2024-02-17 18:47:04 +05:30
|
|
|
import {POST} from '../../modules/fetch.js';
|
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-11-09 14:57:25 +05:30
|
|
|
export function initCompWebHookEditor() {
|
2024-02-17 18:47:04 +05:30
|
|
|
if (!document.querySelectorAll('.new.webhook').length) {
|
2021-10-16 22:58:04 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-17 18:47:04 +05:30
|
|
|
for (const input of document.querySelectorAll('.events.checkbox input')) {
|
|
|
|
input.addEventListener('change', function () {
|
|
|
|
if (this.checked) {
|
|
|
|
showElem('.events.fields');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const input of document.querySelectorAll('.non-events.checkbox input')) {
|
|
|
|
input.addEventListener('change', function () {
|
|
|
|
if (this.checked) {
|
|
|
|
hideElem('.events.fields');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-10-16 22:58:04 +05:30
|
|
|
|
|
|
|
const updateContentType = function () {
|
2024-02-17 18:47:04 +05:30
|
|
|
const visible = document.getElementById('http_method').value === 'POST';
|
|
|
|
toggleElem(document.getElementById('content_type').parentNode.parentNode, visible);
|
2021-10-16 22:58:04 +05:30
|
|
|
};
|
|
|
|
updateContentType();
|
2024-02-17 18:47:04 +05:30
|
|
|
|
|
|
|
document.getElementById('http_method').addEventListener('change', updateContentType);
|
2021-10-16 22:58:04 +05:30
|
|
|
|
|
|
|
// Test delivery
|
2024-02-17 18:47:04 +05:30
|
|
|
document.getElementById('test-delivery')?.addEventListener('click', async function () {
|
|
|
|
this.classList.add('loading', 'disabled');
|
|
|
|
await POST(this.getAttribute('data-link'));
|
|
|
|
setTimeout(() => {
|
|
|
|
window.location.href = this.getAttribute('data-redirect');
|
|
|
|
}, 5000);
|
2021-10-16 22:58:04 +05:30
|
|
|
});
|
|
|
|
}
|