opengist/public/admin.ts
2023-05-06 18:53:59 +02:00

24 lines
865 B
TypeScript

document.addEventListener('DOMContentLoaded', () => {
registerDomSetting(document.getElementById('disable-signup') as HTMLInputElement);
registerDomSetting(document.getElementById('require-login') as HTMLInputElement);
registerDomSetting(document.getElementById('disable-login-form') as HTMLInputElement);
});
const setSetting = (key: string, value: string) => {
const data = new URLSearchParams();
data.append('key', key);
data.append('value', value);
data.append('_csrf', ((document.getElementsByName('_csrf')[0] as HTMLInputElement).value));
fetch('/admin-panel/set-setting', {
method: 'PUT',
credentials: 'same-origin',
body: data,
});
};
const registerDomSetting = (el: HTMLInputElement) => {
el.addEventListener('change', () => {
setSetting(el.id, el.checked ? '1' : '0');
});
};