Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

settings: Refactor set_notification_batching_ui function.

Sahil Batra08038ef140c0
diff --git a/static/js/settings_notifications.js b/static/js/settings_notifications.js
index 3015aaae437..007c9e66c86 100644
--- a/static/js/settings_notifications.js
+++ b/static/js/settings_notifications.js
@@ -66,7 +66,6 @@ function update_desktop_icon_count_display(settings_panel) {
}
function set_notification_batching_ui(container, setting_seconds, force_custom) {
- const select_elem = container.find(".setting_email_notifications_batching_period_seconds");
const edit_elem = container.find(".email_notification_batching_period_edit_minutes");
const valid_period_values = settings_config.email_notifications_batching_period_values.map(
(x) => x.value,
@@ -75,15 +74,12 @@ function set_notification_batching_ui(container, setting_seconds, force_custom)
// We display the custom widget if either the user just selected
// custom_period, or the current value cannot be represented with
// the existing set of values.
- if (force_custom || !valid_period_values.includes(setting_seconds)) {
- const setting_minutes = setting_seconds / 60;
- select_elem.val("custom_period");
- edit_elem.val(setting_minutes);
- edit_elem.parent().show();
- } else {
- select_elem.val(setting_seconds);
- edit_elem.parent().hide();
- }
+ const show_edit_elem = force_custom || !valid_period_values.includes(setting_seconds);
+ const select_elem_val = show_edit_elem ? "custom_period" : setting_seconds;
+
+ container.find(".setting_email_notifications_batching_period_seconds").val(select_elem_val);
+ edit_elem.val(setting_seconds / 60);
+ settings_org.change_element_block_display_property(edit_elem.attr("id"), show_edit_elem);
}
export function set_enable_digest_emails_visibility(settings_panel) {
diff --git a/static/js/settings_org.js b/static/js/settings_org.js
index b05b8e65cdd..d070a96e716 100644
--- a/static/js/settings_org.js
+++ b/static/js/settings_org.js
@@ -237,7 +237,7 @@ function set_property_dropdown_value(property_name) {
$(`#id_${CSS.escape(property_name)}`).val(get_property_value(property_name));
}
-function change_element_block_display_property(elem_id, show_element) {
+export function change_element_block_display_property(elem_id, show_element) {
const elem = $(`#${CSS.escape(elem_id)}`);
if (show_element) {
elem.parent().show();
diff --git a/static/templates/settings/notification_settings.hbs b/static/templates/settings/notification_settings.hbs
index 79c427cf24d..94f859d3bd8 100644
--- a/static/templates/settings/notification_settings.hbs
+++ b/static/templates/settings/notification_settings.hbs
@@ -138,7 +138,7 @@
class="email_notification_batching_period_edit_minutes admin-realm-time-limit-input prop-element"
data-setting-widget-type="number"
autocomplete="off"
- value="{{ email_notifications_batching_period_seconds }}"/>
+ id="{{prefix}}email_notification_batching_period_edit_minutes"/>
</div>
</div>