2023-04-16 22:17:06 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2023-05-11 13:16:05 +00:00
|
|
|
let elems = Array.from(document.getElementsByClassName("toggle-button"));
|
|
|
|
for (let elem of elems) {
|
|
|
|
elem.addEventListener('click', () => {
|
|
|
|
registerDomSetting(elem as HTMLElement)
|
|
|
|
})
|
2024-04-02 19:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let copyInviteButtons = Array.from(document.getElementsByClassName("copy-invitation-link"));
|
|
|
|
for (let button of copyInviteButtons) {
|
|
|
|
button.addEventListener('click', () => {
|
|
|
|
navigator.clipboard.writeText((button as HTMLElement).dataset.link).catch((err) => {
|
|
|
|
console.error('Could not copy text: ', err);
|
|
|
|
});
|
|
|
|
})
|
2023-05-11 13:16:05 +00:00
|
|
|
}
|
2023-04-16 22:17:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const setSetting = (key: string, value: string) => {
|
2024-01-04 03:44:56 +00:00
|
|
|
// @ts-ignore
|
2024-01-02 04:11:49 +00:00
|
|
|
const baseUrl = window.opengist_base_url || '';
|
2023-04-16 22:17:06 +00:00
|
|
|
const data = new URLSearchParams();
|
|
|
|
data.append('key', key);
|
|
|
|
data.append('value', value);
|
2023-09-22 15:31:19 +00:00
|
|
|
if (document.getElementsByName('_csrf').length !== 0) {
|
|
|
|
data.append('_csrf', ((document.getElementsByName('_csrf')[0] as HTMLInputElement).value));
|
|
|
|
}
|
2024-01-02 04:11:49 +00:00
|
|
|
return fetch(`${baseUrl}/admin-panel/set-config`, {
|
2023-04-16 22:17:06 +00:00
|
|
|
method: 'PUT',
|
|
|
|
credentials: 'same-origin',
|
|
|
|
body: data,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-05-11 13:16:05 +00:00
|
|
|
const registerDomSetting = (el: HTMLElement) => {
|
|
|
|
// @ts-ignore
|
|
|
|
el.dataset["bool"] = !(el.dataset["bool"] === 'true');
|
|
|
|
setSetting(el.id, el.dataset["bool"] === 'true' ? '1' : '0')
|
|
|
|
.then(() => {
|
|
|
|
el.classList.toggle("bg-primary-600");
|
2023-05-27 11:58:08 +00:00
|
|
|
el.classList.toggle("dark:bg-gray-400");
|
|
|
|
el.classList.toggle("bg-gray-300");
|
2023-05-11 13:16:05 +00:00
|
|
|
(el.childNodes.item(1) as HTMLElement).classList.toggle("translate-x-5");
|
|
|
|
});
|
2023-04-16 22:17:06 +00:00
|
|
|
};
|
|
|
|
|