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) { 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 edit_elem = container.find(".email_notification_batching_period_edit_minutes");
const valid_period_values = settings_config.email_notifications_batching_period_values.map( const valid_period_values = settings_config.email_notifications_batching_period_values.map(
(x) => x.value, (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 // We display the custom widget if either the user just selected
// custom_period, or the current value cannot be represented with // custom_period, or the current value cannot be represented with
// the existing set of values. // the existing set of values.
if (force_custom || !valid_period_values.includes(setting_seconds)) { const show_edit_elem = force_custom || !valid_period_values.includes(setting_seconds);
const setting_minutes = setting_seconds / 60; const select_elem_val = show_edit_elem ? "custom_period" : setting_seconds;
select_elem.val("custom_period");
edit_elem.val(setting_minutes); container.find(".setting_email_notifications_batching_period_seconds").val(select_elem_val);
edit_elem.parent().show(); edit_elem.val(setting_seconds / 60);
} else { settings_org.change_element_block_display_property(edit_elem.attr("id"), show_edit_elem);
select_elem.val(setting_seconds);
edit_elem.parent().hide();
}
} }
export function set_enable_digest_emails_visibility(settings_panel) { export function set_enable_digest_emails_visibility(settings_panel) {

View File

@@ -237,7 +237,7 @@ function set_property_dropdown_value(property_name) {
$(`#id_${CSS.escape(property_name)}`).val(get_property_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)}`); const elem = $(`#${CSS.escape(elem_id)}`);
if (show_element) { if (show_element) {
elem.parent().show(); elem.parent().show();

View File

@@ -138,7 +138,7 @@
class="email_notification_batching_period_edit_minutes admin-realm-time-limit-input prop-element" class="email_notification_batching_period_edit_minutes admin-realm-time-limit-input prop-element"
data-setting-widget-type="number" data-setting-widget-type="number"
autocomplete="off" autocomplete="off"
value="{{ email_notifications_batching_period_seconds }}"/> id="{{prefix}}email_notification_batching_period_edit_minutes"/>
</div> </div>
</div> </div>