summaryrefslogtreecommitdiffstats
path: root/web_src/js/features/admin/config.js
diff options
context:
space:
mode:
Diffstat (limited to 'web_src/js/features/admin/config.js')
-rw-r--r--web_src/js/features/admin/config.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/web_src/js/features/admin/config.js b/web_src/js/features/admin/config.js
new file mode 100644
index 0000000000..f5d8fae8fa
--- /dev/null
+++ b/web_src/js/features/admin/config.js
@@ -0,0 +1,37 @@
+import $ from 'jquery';
+import {showTemporaryTooltip} from '../../modules/tippy.js';
+
+const {appSubUrl, csrfToken, pageData} = window.config;
+
+export function initAdminConfigs() {
+ const isAdminConfigPage = pageData?.adminConfigPage;
+ if (!isAdminConfigPage) return;
+
+ $("input[type='checkbox']").on('change', (e) => {
+ const $this = $(e.currentTarget);
+ $.ajax({
+ url: `${appSubUrl}/admin/config`,
+ type: 'POST',
+ data: {
+ _csrf: csrfToken,
+ key: $this.attr('name'),
+ value: $this.is(':checked'),
+ version: $this.attr('version'),
+ }
+ }).done((resp) => {
+ if (resp) {
+ if (resp.redirect) {
+ window.location.href = resp.redirect;
+ } else if (resp.version) {
+ $this.attr('version', resp.version);
+ } else if (resp.err) {
+ showTemporaryTooltip(e.currentTarget, resp.err);
+ $this.prop('checked', !$this.is(':checked'));
+ }
+ }
+ });
+
+ e.preventDefault();
+ return false;
+ });
+}