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