From c4b923886cfc852bd621732d12d014a689ad999e Mon Sep 17 00:00:00 2001 From: "Alex Lau(AvengerMoJo)" Date: Mon, 22 Apr 2024 13:40:37 +0800 Subject: [PATCH] moving the js to a seperated file in web_src/js/features/ Signed-off-by: Alex Lau(AvengerMoJo) --- .../shared/actions/require_action_list.tmpl | 2 ++ web_src/js/features/require-actions-select.js | 19 +++++++++++++++++++ web_src/js/index.js | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 web_src/js/features/require-actions-select.js diff --git a/templates/shared/actions/require_action_list.tmpl b/templates/shared/actions/require_action_list.tmpl index 99642eb62d..e04e551dfc 100644 --- a/templates/shared/actions/require_action_list.tmpl +++ b/templates/shared/actions/require_action_list.tmpl @@ -124,6 +124,7 @@ {{template "base/modal_actions_confirm" (dict "ModalButtonTypes" "confirm")}} + diff --git a/web_src/js/features/require-actions-select.js b/web_src/js/features/require-actions-select.js new file mode 100644 index 0000000000..e18e8d42c4 --- /dev/null +++ b/web_src/js/features/require-actions-select.js @@ -0,0 +1,19 @@ +export function initRequireActionsSelect() { + const raselect = document.getElementById('add-require-actions-modal'); + if (!raselect) return; + const checkboxes = document.querySelectorAll('.ui.radio.checkbox'); + checkboxes.forEach(function(checkbox) { + checkbox.addEventListener('change', function() { + var hiddenInput = this.nextElementSibling; + var isChecked = this.querySelector('input[type="radio"]').checked; + hiddenInput.disabled = !isChecked; + // Disable other hidden inputs + checkboxes.forEach(function(otherCheckbox) { + var otherHiddenInput = otherCheckbox.nextElementSibling; + if (otherCheckbox !== checkbox) { + otherHiddenInput.disabled = isChecked; + } + }); + }); + }); +} diff --git a/web_src/js/index.js b/web_src/js/index.js index fc2f6b9b0b..05bfb46258 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -54,6 +54,7 @@ import {initRepoCodeView} from './features/repo-code.js'; import {initSshKeyFormParser} from './features/sshkey-helper.js'; import {initUserSettings} from './features/user-settings.js'; import {initRepoArchiveLinks} from './features/repo-common.js'; +import {initRequireActionsSelect} from './features/require-actions-select.js'; import {initRepoMigrationStatusChecker} from './features/repo-migrate.js'; import { initRepoSettingGitHook, @@ -143,6 +144,7 @@ onDomReady(() => { initRepoActivityTopAuthorsChart(); initRepoArchiveLinks(); + initRequireActionsSelect(); initRepoBranchButton(); initRepoCodeView(); initRepoCommentForm();