2022-01-29 00:00:11 +03:00
|
|
|
import $ from 'jquery';
|
2023-02-19 07:06:14 +03:00
|
|
|
import {hideElem, showElem, toggleElem} from '../../utils/dom.js';
|
2022-12-23 19:03:11 +03:00
|
|
|
|
2021-10-21 10:37:43 +03:00
|
|
|
const {csrfToken} = window.config;
|
2021-10-16 20:28:04 +03:00
|
|
|
|
2021-11-09 12:27:25 +03:00
|
|
|
export function initCompWebHookEditor() {
|
2021-10-16 20:28:04 +03:00
|
|
|
if ($('.new.webhook').length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.events.checkbox input').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
2023-02-19 07:06:14 +03:00
|
|
|
showElem($('.events.fields'));
|
2021-10-16 20:28:04 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$('.non-events.checkbox input').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
2023-02-19 07:06:14 +03:00
|
|
|
hideElem($('.events.fields'));
|
2021-10-16 20:28:04 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const updateContentType = function () {
|
|
|
|
const visible = $('#http_method').val() === 'POST';
|
2023-02-19 07:06:14 +03:00
|
|
|
toggleElem($('#content_type').parent().parent(), visible);
|
2021-10-16 20:28:04 +03:00
|
|
|
};
|
|
|
|
updateContentType();
|
|
|
|
$('#http_method').on('change', () => {
|
|
|
|
updateContentType();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test delivery
|
|
|
|
$('#test-delivery').on('click', function () {
|
|
|
|
const $this = $(this);
|
|
|
|
$this.addClass('loading disabled');
|
|
|
|
$.post($this.data('link'), {
|
2021-10-21 10:37:43 +03:00
|
|
|
_csrf: csrfToken
|
2021-10-16 20:28:04 +03:00
|
|
|
}).done(
|
|
|
|
setTimeout(() => {
|
|
|
|
window.location.href = $this.data('redirect');
|
|
|
|
}, 5000)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|