diff options
Diffstat (limited to 'web_src/js')
-rw-r--r-- | web_src/js/features/admin/common.js (renamed from web_src/js/features/admin-common.js) | 0 | ||||
-rw-r--r-- | web_src/js/features/admin/config.js | 37 | ||||
-rw-r--r-- | web_src/js/features/admin/emails.js (renamed from web_src/js/features/admin-emails.js) | 0 | ||||
-rw-r--r-- | web_src/js/features/admin/users.js (renamed from web_src/js/features/admin-users.js) | 0 | ||||
-rw-r--r-- | web_src/js/index.js | 8 |
5 files changed, 42 insertions, 3 deletions
diff --git a/web_src/js/features/admin-common.js b/web_src/js/features/admin/common.js index 2438fcf62b..2438fcf62b 100644 --- a/web_src/js/features/admin-common.js +++ b/web_src/js/features/admin/common.js 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; + }); +} diff --git a/web_src/js/features/admin-emails.js b/web_src/js/features/admin/emails.js index 46fafa7eff..46fafa7eff 100644 --- a/web_src/js/features/admin-emails.js +++ b/web_src/js/features/admin/emails.js diff --git a/web_src/js/features/admin-users.js b/web_src/js/features/admin/users.js index 2221fc4929..2221fc4929 100644 --- a/web_src/js/features/admin-users.js +++ b/web_src/js/features/admin/users.js diff --git a/web_src/js/index.js b/web_src/js/index.js index b13ad0e13a..a829deaf11 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -16,7 +16,8 @@ import initRepoMigration from './features/repo-migration.js'; import initRepoProject from './features/repo-projects.js'; import initServiceWorker from './features/serviceworker.js'; import initTableSort from './features/tablesort.js'; -import {initAdminUserListSearchForm} from './features/admin-users.js'; +import {initAdminUserListSearchForm} from './features/admin/users.js'; +import {initAdminConfigs} from './features/admin/config.js'; import {initMarkupAnchors} from './markup/anchors.js'; import {initNotificationCount, initNotificationsTable} from './features/notification.js'; import {initRepoIssueContentHistory} from './features/repo-issue-content.js'; @@ -60,8 +61,8 @@ import { initGlobalTooltips, } from './features/common-global.js'; import {initRepoTopicBar} from './features/repo-home.js'; -import {initAdminEmails} from './features/admin-emails.js'; -import {initAdminCommon} from './features/admin-common.js'; +import {initAdminEmails} from './features/admin/emails.js'; +import {initAdminCommon} from './features/admin/common.js'; import {initRepoTemplateSearch} from './features/repo-template.js'; import {initRepoCodeView} from './features/repo-code.js'; import {initSshKeyFormParser} from './features/sshkey-helper.js'; @@ -139,6 +140,7 @@ $(document).ready(() => { initAdminCommon(); initAdminEmails(); initAdminUserListSearchForm(); + initAdminConfigs(); initDashboardRepoList(); |