code.gitea.io/gitea@v1.22.3/web_src/js/features/comp/WebHookEditor.js (about) 1 import {POST} from '../../modules/fetch.js'; 2 import {hideElem, showElem, toggleElem} from '../../utils/dom.js'; 3 4 export function initCompWebHookEditor() { 5 if (!document.querySelectorAll('.new.webhook').length) { 6 return; 7 } 8 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 } 24 25 // some webhooks (like Gitea) allow to set the request method (GET/POST), and it would toggle the "Content Type" field 26 const httpMethodInput = document.getElementById('http_method'); 27 if (httpMethodInput) { 28 const updateContentType = function () { 29 const visible = httpMethodInput.value === 'POST'; 30 toggleElem(document.getElementById('content_type').closest('.field'), visible); 31 }; 32 updateContentType(); 33 httpMethodInput.addEventListener('change', updateContentType); 34 } 35 36 // Test delivery 37 document.getElementById('test-delivery')?.addEventListener('click', async function () { 38 this.classList.add('is-loading', 'disabled'); 39 await POST(this.getAttribute('data-link')); 40 setTimeout(() => { 41 window.location.href = this.getAttribute('data-redirect'); 42 }, 5000); 43 }); 44 }