|
1 | | -import $ from 'jquery'; |
| 1 | +import {POST} from '../../modules/fetch.js'; |
2 | 2 | import {hideElem, showElem, toggleElem} from '../../utils/dom.js'; |
3 | 3 |
|
4 | | -const {csrfToken} = window.config; |
5 | | - |
6 | 4 | export function initCompWebHookEditor() { |
7 | | - if ($('.new.webhook').length === 0) { |
| 5 | + if (!document.querySelectorAll('.new.webhook').length) { |
8 | 6 | return; |
9 | 7 | } |
10 | 8 |
|
11 | | - $('.events.checkbox input').on('change', function () { |
12 | | - if ($(this).is(':checked')) { |
13 | | - showElem($('.events.fields')); |
14 | | - } |
15 | | - }); |
16 | | - $('.non-events.checkbox input').on('change', function () { |
17 | | - if ($(this).is(':checked')) { |
18 | | - hideElem($('.events.fields')); |
19 | | - } |
20 | | - }); |
| 9 | + for (const input of document.querySelectorAll('.events.checkbox input')) { |
| 10 | + input.addEventListener('change', function () { |
| 11 | + if (this.checked) { |
| 12 | + showElem('.events.fields'); |
| 13 | + } |
| 14 | + }); |
| 15 | + } |
| 16 | + |
| 17 | + for (const input of document.querySelectorAll('.non-events.checkbox input')) { |
| 18 | + input.addEventListener('change', function () { |
| 19 | + if (this.checked) { |
| 20 | + hideElem('.events.fields'); |
| 21 | + } |
| 22 | + }); |
| 23 | + } |
21 | 24 |
|
22 | 25 | const updateContentType = function () { |
23 | | - const visible = $('#http_method').val() === 'POST'; |
24 | | - toggleElem($('#content_type').parent().parent(), visible); |
| 26 | + const visible = document.getElementById('http_method').value === 'POST'; |
| 27 | + toggleElem(document.getElementById('content_type').parentNode.parentNode, visible); |
25 | 28 | }; |
26 | 29 | updateContentType(); |
27 | | - $('#http_method').on('change', () => { |
28 | | - updateContentType(); |
29 | | - }); |
| 30 | + |
| 31 | + document.getElementById('http_method').addEventListener('change', updateContentType); |
30 | 32 |
|
31 | 33 | // Test delivery |
32 | | - $('#test-delivery').on('click', function () { |
33 | | - const $this = $(this); |
34 | | - $this.addClass('loading disabled'); |
35 | | - $.post($this.data('link'), { |
36 | | - _csrf: csrfToken |
37 | | - }).done( |
38 | | - setTimeout(() => { |
39 | | - window.location.href = $this.data('redirect'); |
40 | | - }, 5000) |
41 | | - ); |
| 34 | + document.getElementById('test-delivery')?.addEventListener('click', async function () { |
| 35 | + this.classList.add('loading', 'disabled'); |
| 36 | + await POST(this.getAttribute('data-link')); |
| 37 | + setTimeout(() => { |
| 38 | + window.location.href = this.getAttribute('data-redirect'); |
| 39 | + }, 5000); |
42 | 40 | }); |
43 | 41 | } |
0 commit comments