2022-01-29 02:30:11 +05:30
|
|
|
import $ from 'jquery';
|
2023-02-19 09:36:14 +05:30
|
|
|
import {hideElem, showElem, toggleElem} from '../../utils/dom.js';
|
2022-12-23 21:33:11 +05:30
|
|
|
|
2021-10-21 13:07:43 +05:30
|
|
|
const {csrfToken} = window.config;
|
2021-10-16 22:58:04 +05:30
|
|
|
|
2021-11-09 14:57:25 +05:30
|
|
|
export function initCompWebHookEditor() {
|
2021-10-16 22:58:04 +05:30
|
|
|
if ($('.new.webhook').length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.events.checkbox input').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
2023-02-19 09:36:14 +05:30
|
|
|
showElem($('.events.fields'));
|
2021-10-16 22:58:04 +05:30
|
|
|
}
|
|
|
|
});
|
|
|
|
$('.non-events.checkbox input').on('change', function () {
|
|
|
|
if ($(this).is(':checked')) {
|
2023-02-19 09:36:14 +05:30
|
|
|
hideElem($('.events.fields'));
|
2021-10-16 22:58:04 +05:30
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const updateContentType = function () {
|
|
|
|
const visible = $('#http_method').val() === 'POST';
|
2023-02-19 09:36:14 +05:30
|
|
|
toggleElem($('#content_type').parent().parent(), visible);
|
2021-10-16 22:58:04 +05:30
|
|
|
};
|
|
|
|
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 13:07:43 +05:30
|
|
|
_csrf: csrfToken
|
2021-10-16 22:58:04 +05:30
|
|
|
}).done(
|
|
|
|
setTimeout(() => {
|
|
|
|
window.location.href = $this.data('redirect');
|
|
|
|
}, 5000)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|