summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/admin/application_settings/account_and_limits.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/pages/admin/application_settings/account_and_limits.js')
-rw-r--r--app/assets/javascripts/pages/admin/application_settings/account_and_limits.js57
1 files changed, 56 insertions, 1 deletions
diff --git a/app/assets/javascripts/pages/admin/application_settings/account_and_limits.js b/app/assets/javascripts/pages/admin/application_settings/account_and_limits.js
index 455c637a6b3..8b8147425bc 100644
--- a/app/assets/javascripts/pages/admin/application_settings/account_and_limits.js
+++ b/app/assets/javascripts/pages/admin/application_settings/account_and_limits.js
@@ -20,10 +20,65 @@ function setUserInternalRegexPlaceholder(checkbox) {
}
}
-export default function initUserInternalRegexPlaceholder() {
+function initUserInternalRegexPlaceholder() {
const checkbox = document.getElementById('application_setting_user_default_external');
setUserInternalRegexPlaceholder(checkbox);
checkbox.addEventListener('change', () => {
setUserInternalRegexPlaceholder(checkbox);
});
}
+
+/**
+ * Sets up logic inside "Dormant users" subsection:
+ * - checkbox enables/disables additional input
+ * - shows/hides an inline error on input validation
+ */
+function initDeactivateDormantUsersPeriodInputSection() {
+ const DISPLAY_NONE_CLASS = 'gl-display-none';
+
+ /** @type {HTMLInputElement} */
+ const checkbox = document.getElementById('application_setting_deactivate_dormant_users');
+ /** @type {HTMLInputElement} */
+ const input = document.getElementById('application_setting_deactivate_dormant_users_period');
+ /** @type {HTMLDivElement} */
+ const errorLabel = document.getElementById(
+ 'application_setting_deactivate_dormant_users_period_error',
+ );
+
+ if (!checkbox || !input || !errorLabel) return;
+
+ const hideInputErrorLabel = () => {
+ if (input.checkValidity()) {
+ errorLabel.classList.add(DISPLAY_NONE_CLASS);
+ }
+ };
+
+ const handleInputInvalidState = (event) => {
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ errorLabel.classList.remove(DISPLAY_NONE_CLASS);
+ return false;
+ };
+
+ const updateInputDisabledState = () => {
+ input.disabled = !checkbox.checked;
+ if (input.disabled) {
+ hideInputErrorLabel();
+ }
+ };
+
+ // Show error when input is invalid
+ input.addEventListener('invalid', handleInputInvalidState);
+ // Hide error when input changes
+ input.addEventListener('input', hideInputErrorLabel);
+ input.addEventListener('change', hideInputErrorLabel);
+
+ // Handle checkbox change and set initial state
+ checkbox.addEventListener('change', updateInputDisabledState);
+ updateInputDisabledState();
+}
+
+export default function initAccountAndLimitsSection() {
+ initUserInternalRegexPlaceholder();
+ initDeactivateDormantUsersPeriodInputSection();
+}