code.gitea.io/gitea@v1.21.7/web_src/js/features/admin/config.js (about) 1 import {showTemporaryTooltip} from '../../modules/tippy.js'; 2 import {POST} from '../../modules/fetch.js'; 3 4 const {appSubUrl} = window.config; 5 6 export function initAdminConfigs() { 7 const elAdminConfig = document.querySelector('.page-content.admin.config'); 8 if (!elAdminConfig) return; 9 10 for (const el of elAdminConfig.querySelectorAll('input[type="checkbox"][data-config-dyn-key]')) { 11 el.addEventListener('change', async () => { 12 try { 13 const resp = await POST(`${appSubUrl}/admin/config`, { 14 data: new URLSearchParams({key: el.getAttribute('data-config-dyn-key'), value: el.checked}), 15 }); 16 const json = await resp.json(); 17 if (json.errorMessage) throw new Error(json.errorMessage); 18 } catch (ex) { 19 showTemporaryTooltip(el, ex.toString()); 20 el.checked = !el.checked; 21 } 22 }); 23 } 24 }