From 25223539d1b3344446d3145f4a3e26e84651deaa Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Fri, 2 Sep 2022 22:33:01 +0530 Subject: [PATCH] settings_org: Move update_save_button_state function to module level. We would use update_save_button_state for realm-level default of notification batching setting also in further commits. --- static/js/settings_org.js | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/static/js/settings_org.js b/static/js/settings_org.js index 275cbe2508..f48f01b198 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -888,6 +888,27 @@ export function init_dropdown_widgets() { default_code_language_widget.setup(); } +function update_save_button_state(e) { + const $subsection_elem = $(e.target).closest(".org-subsection-parent"); + const time_limit_settings = Array.from($subsection_elem.find(".time-limit-setting")); + let disable_save_btn = false; + for (const setting_elem of time_limit_settings) { + const dropdown_elem_val = $(setting_elem).find("select").val(); + const custom_input_elem_val = Number.parseInt( + $(setting_elem).find(".admin-realm-time-limit-input").val(), + 10, + ); + + disable_save_btn = + dropdown_elem_val === "custom_limit" && + (custom_input_elem_val <= 0 || Number.isNaN(custom_input_elem_val)); + if (disable_save_btn) { + break; + } + } + $subsection_elem.find(".subsection-changes-save button").prop("disabled", disable_save_btn); +} + export function register_save_discard_widget_handlers( $container, patch_url, @@ -1163,27 +1184,6 @@ export function build_page() { register_save_discard_widget_handlers($(".admin-realm-form"), "/json/realm", false); - function update_save_button_state(e) { - const $subsection_elem = $(e.target).closest(".org-subsection-parent"); - const time_limit_settings = Array.from($subsection_elem.find(".time-limit-setting")); - let disable_save_btn = false; - for (const setting_elem of time_limit_settings) { - const dropdown_elem_val = $(setting_elem).find("select").val(); - const custom_input_elem_val = Number.parseInt( - $(setting_elem).find(".admin-realm-time-limit-input").val(), - 10, - ); - - disable_save_btn = - dropdown_elem_val === "custom_limit" && - (custom_input_elem_val <= 0 || Number.isNaN(custom_input_elem_val)); - if (disable_save_btn) { - break; - } - } - $subsection_elem.find(".subsection-changes-save button").prop("disabled", disable_save_btn); - } - $(".org-subsection-parent").on("keydown", "input", (e) => { e.stopPropagation(); if (e.key === "Enter") {