settings: Refactor set_notification_batching_ui function.

This commit refactors the set_notification_batching_ui to
use settings_org.change_element_block_display_property function
for toggling the visibility of custom input.

We add id to the email_notification_batching_period_edit_minutes
element such that we can use change_element_block_display_property
function because it requires id of element as an argument.

This commit also removes the value attribute of the custom
input since its value was set undefined in the template
and then was set in set_notification_batching_ui, so there
is no use of keeping the value attribute in templates.

This is a prep commit for fixing the behavior of this element
in realm-level default settings.
This commit is contained in:
Sahil Batra
2021-12-02 19:06:09 +05:30
committed by Tim Abbott
parent 7c9f587563
commit 08038ef140
3 changed files with 8 additions and 12 deletions

View File

@@ -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) {