mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
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:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user