Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import {POST} from '../../modules/fetch.ts';
|
|
import {hideElem, showElem, toggleElem} from '../../utils/dom.ts';
|
|
|
|
export function initCompWebHookEditor() {
|
|
if (!document.querySelectorAll('.new.webhook').length) {
|
|
return;
|
|
}
|
|
|
|
for (const input of document.querySelectorAll<HTMLInputElement>('.events.checkbox input')) {
|
|
input.addEventListener('change', function () {
|
|
if (this.checked) {
|
|
showElem('.events.fields');
|
|
}
|
|
});
|
|
}
|
|
|
|
for (const input of document.querySelectorAll<HTMLInputElement>('.non-events.checkbox input')) {
|
|
input.addEventListener('change', function () {
|
|
if (this.checked) {
|
|
hideElem('.events.fields');
|
|
}
|
|
});
|
|
}
|
|
|
|
// some webhooks (like Gitea) allow to set the request method (GET/POST), and it would toggle the "Content Type" field
|
|
const httpMethodInput = document.querySelector<HTMLInputElement>('#http_method');
|
|
if (httpMethodInput) {
|
|
const updateContentType = function () {
|
|
const visible = httpMethodInput.value === 'POST';
|
|
toggleElem(document.querySelector('#content_type')!.closest('.field')!, visible);
|
|
};
|
|
updateContentType();
|
|
httpMethodInput.addEventListener('change', updateContentType);
|
|
}
|
|
|
|
// Test delivery
|
|
document.querySelector<HTMLButtonElement>('#test-delivery')?.addEventListener('click', async function () {
|
|
this.classList.add('is-loading', 'disabled');
|
|
await POST(this.getAttribute('data-link')!);
|
|
setTimeout(() => window.location.reload(), 5000);
|
|
});
|
|
}
|