Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
settings: Extract a function to set msg edit and delete limit setting.
Sahil Batra009e06d8689f
diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.jsindex b8f1cfc6493..3f28ba50365 100644--- a/frontend_tests/node_tests/settings_org.js+++ b/frontend_tests/node_tests/settings_org.js@@ -531,11 +531,39 @@ test("set_up", ({override, override_rewire}) => {update: noop,}));$("#id_realm_message_content_edit_limit_minutes").set_parent(- $.create("<stub edit limit parent>"),+ $.create("<stub edit limit custom input parent>"),);$("#id_realm_message_content_delete_limit_minutes").set_parent(- $.create("<stub delete limit parent>"),+ $.create("<stub delete limit custom input parent>"),);+ const $stub_message_content_edit_limit_parent = $.create(+ "<stub message_content_edit_limit parent",+ );+ $("#id_realm_message_content_edit_limit_seconds").set_parent(+ $stub_message_content_edit_limit_parent,+ );++ const $stub_message_content_delete_limit_parent = $.create(+ "<stub message_content_delete_limit parent",+ );+ $("#id_realm_message_content_delete_limit_seconds").set_parent(+ $stub_message_content_delete_limit_parent,+ );++ const $custom_edit_limit_input = $("#id_realm_message_content_edit_limit_minutes");+ $stub_message_content_edit_limit_parent.set_find_results(+ ".admin-realm-time-limit-input",+ $custom_edit_limit_input,+ );+ $custom_edit_limit_input.attr("id", "id_realm_message_content_edit_limit_minutes");++ const $custom_delete_limit_input = $("#id_realm_message_content_delete_limit_minutes");+ $stub_message_content_delete_limit_parent.set_find_results(+ ".admin-realm-time-limit-input",+ $custom_delete_limit_input,+ );+ $custom_delete_limit_input.attr("id", "id_realm_message_content_delete_limit_minutes");+$("#id_realm_message_retention_days").set_parent($.create("<stub retention period parent>"));$("#message_content_in_email_notifications_label").set_parent($.create("<stub in-content setting checkbox>"),diff --git a/static/js/settings_org.js b/static/js/settings_org.jsindex e9cf3e77ce0..13b13f5a67a 100644--- a/static/js/settings_org.js+++ b/static/js/settings_org.js@@ -314,20 +314,25 @@ function get_time_limit_dropdown_setting_value(property_name) {return "custom_period";}-function set_msg_edit_limit_dropdown() {- const dropdown_elem_val = get_time_limit_dropdown_setting_value(- "realm_message_content_edit_limit_seconds",- );- $("#id_realm_message_content_edit_limit_seconds").val(dropdown_elem_val);- $("#id_realm_message_content_edit_limit_minutes").val(- get_realm_time_limits_in_minutes("realm_message_content_edit_limit_seconds"),- );+function set_time_limit_setting(property_name) {+ const dropdown_elem_val = get_time_limit_dropdown_setting_value(property_name);+ $(`#id_${CSS.escape(property_name)}`).val(dropdown_elem_val);++ const $custom_input = $(`#id_${CSS.escape(property_name)}`)+ .parent()+ .find(".admin-realm-time-limit-input");+ $custom_input.val(get_realm_time_limits_in_minutes(property_name));+change_element_block_display_property(- "id_realm_message_content_edit_limit_minutes",+ $custom_input.attr("id"),dropdown_elem_val === "custom_period",);}+function set_msg_edit_limit_dropdown() {+ set_time_limit_setting("realm_message_content_edit_limit_seconds");+}+function message_delete_limit_setting_enabled(setting_value) {// This function is used to check whether the time-limit setting// should be enabled. The setting is disabled when delete_own_message_policy@@ -359,17 +364,7 @@ function set_delete_own_message_policy_dropdown(setting_value) {}function set_msg_delete_limit_dropdown() {- const dropdown_elem_val = get_time_limit_dropdown_setting_value(- "realm_message_content_delete_limit_seconds",- );- $("#id_realm_message_content_delete_limit_seconds").val(dropdown_elem_val);- $("#id_realm_message_content_delete_limit_minutes").val(- get_realm_time_limits_in_minutes("realm_message_content_delete_limit_seconds"),- );- change_element_block_display_property(- "id_realm_message_content_delete_limit_minutes",- dropdown_elem_val === "custom_period",- );+ set_time_limit_setting("realm_message_content_delete_limit_seconds");}function set_message_retention_setting_dropdown() {@@ -576,10 +571,8 @@ function discard_property_element_changes(elem, for_realm_default_settings) {}break;case "realm_message_content_edit_limit_seconds":- set_msg_edit_limit_dropdown();- break;case "realm_message_content_delete_limit_seconds":- set_msg_delete_limit_dropdown();+ set_time_limit_setting(property_name);break;default:if (property_value !== undefined) {