35 lines
1.1 KiB
PHTML
35 lines
1.1 KiB
PHTML
<?php $url = $block->getCustomUrl(); ?>
|
|
|
|
<script type="text/javascript">
|
|
require(["jquery"],function($) {
|
|
$('#whi_test_connection').click(function() {
|
|
if (!confirm('Save the configuration before testing.')) {
|
|
return;
|
|
}
|
|
|
|
$.ajax({
|
|
url: "<?php echo $url; ?>",
|
|
type: 'GET',
|
|
complete: function (response) {
|
|
switch (response.status) {
|
|
case 204:
|
|
alert('Connection successful.');
|
|
break;
|
|
|
|
case 401:
|
|
case 403:
|
|
alert('Invalid API key.');
|
|
break;
|
|
|
|
default:
|
|
alert('Failed to connect to the provided URL.');
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<?php echo $block->getButtonHtml(); ?>
|
|
<p><sub><em>Note: Currently only works in Chromium-based browsers (Firefox blocks script execution).</em></sub></p>
|