You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WebHookEditor.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {POST} from '../../modules/fetch.js';
  2. import {hideElem, showElem, toggleElem} from '../../utils/dom.js';
  3. export function initCompWebHookEditor() {
  4. if (!document.querySelectorAll('.new.webhook').length) {
  5. return;
  6. }
  7. for (const input of document.querySelectorAll('.events.checkbox input')) {
  8. input.addEventListener('change', function () {
  9. if (this.checked) {
  10. showElem('.events.fields');
  11. }
  12. });
  13. }
  14. for (const input of document.querySelectorAll('.non-events.checkbox input')) {
  15. input.addEventListener('change', function () {
  16. if (this.checked) {
  17. hideElem('.events.fields');
  18. }
  19. });
  20. }
  21. // some webhooks (like Gitea) allow to set the request method (GET/POST), and it would toggle the "Content Type" field
  22. const httpMethodInput = document.getElementById('http_method');
  23. if (httpMethodInput) {
  24. const updateContentType = function () {
  25. const visible = httpMethodInput.value === 'POST';
  26. toggleElem(document.getElementById('content_type').closest('.field'), visible);
  27. };
  28. updateContentType();
  29. httpMethodInput.addEventListener('change', updateContentType);
  30. }
  31. // Test delivery
  32. document.getElementById('test-delivery')?.addEventListener('click', async function () {
  33. this.classList.add('is-loading', 'disabled');
  34. await POST(this.getAttribute('data-link'));
  35. setTimeout(() => {
  36. window.location.href = this.getAttribute('data-redirect');
  37. }, 5000);
  38. });
  39. }