mirror of https://github.com/zulip/zulip.git
settings: Refactor code for realm message retention setting.
This commit refactors the code for realm message retention setting which will help us in reusing some code when adding save-discard widget for stream settings in further commits. Following changes have been done in this commit - - Renamed the "retain_for_period" option to "custom_period" and "retain_forever" option to "unlimited" to match with the stream settings options such that we can reuse the code. - Updated set_message_retention_setting_dropdown such that it can be used for stream message retention setting as well.
This commit is contained in:
parent
de259b3c4a
commit
8241e2d353
|
@ -555,9 +555,18 @@ test("set_up", ({override, override_rewire}) => {
|
|||
);
|
||||
$custom_delete_limit_input.attr("id", "id_realm_message_content_delete_limit_minutes");
|
||||
|
||||
$("#id_realm_message_retention_custom_input").set_parent(
|
||||
$.create("<stub retention period parent>"),
|
||||
const $stub_realm_message_retention_parent = $.create(
|
||||
"<stub message retention setting parent>",
|
||||
);
|
||||
const $realm_message_retention_custom_input = $("#id_realm_message_retention_custom_input");
|
||||
$("#id_realm_message_retention_days").set_parent($stub_realm_message_retention_parent);
|
||||
$realm_message_retention_custom_input.set_parent($stub_realm_message_retention_parent);
|
||||
$stub_realm_message_retention_parent.set_find_results(
|
||||
".message-retention-setting-custom-input",
|
||||
$realm_message_retention_custom_input,
|
||||
);
|
||||
$realm_message_retention_custom_input.attr("id", "id_realm_message_retention_custom_input");
|
||||
|
||||
$("#message_content_in_email_notifications_label").set_parent(
|
||||
$.create("<stub in-content setting checkbox>"),
|
||||
);
|
||||
|
|
|
@ -346,7 +346,7 @@ function set_msg_delete_limit_dropdown() {
|
|||
|
||||
function get_message_retention_setting_value($input_elem, for_api_data = true) {
|
||||
const select_elem_val = $input_elem.val();
|
||||
if (select_elem_val === "retain_forever") {
|
||||
if (select_elem_val === "unlimited") {
|
||||
if (!for_api_data) {
|
||||
return settings_config.retain_message_forever;
|
||||
}
|
||||
|
@ -362,27 +362,32 @@ function get_message_retention_setting_value($input_elem, for_api_data = true) {
|
|||
|
||||
function get_dropdown_value_for_message_retention_setting(setting_value) {
|
||||
if (setting_value === settings_config.retain_message_forever) {
|
||||
return "retain_forever";
|
||||
return "unlimited";
|
||||
}
|
||||
|
||||
return "retain_for_period";
|
||||
return "custom_period";
|
||||
}
|
||||
|
||||
function set_message_retention_setting_dropdown() {
|
||||
const value = get_property_value("realm_message_retention_days");
|
||||
const dropdown_val = get_dropdown_value_for_message_retention_setting(value);
|
||||
$("#id_realm_message_retention_days").val(dropdown_val);
|
||||
const property_name = "realm_message_retention_days";
|
||||
const setting_value = get_property_value(property_name, false);
|
||||
const dropdown_val = get_dropdown_value_for_message_retention_setting(setting_value);
|
||||
|
||||
const $dropdown_elem = $(`#id_${CSS.escape(property_name)}`);
|
||||
$dropdown_elem.val(dropdown_val);
|
||||
|
||||
const $custom_input_elem = $dropdown_elem
|
||||
.parent()
|
||||
.find(".message-retention-setting-custom-input")
|
||||
.val("");
|
||||
if (dropdown_val === "custom_period") {
|
||||
$custom_input_elem.val(setting_value);
|
||||
}
|
||||
|
||||
change_element_block_display_property(
|
||||
"id_realm_message_retention_custom_input",
|
||||
dropdown_val === "retain_for_period",
|
||||
$custom_input_elem.attr("id"),
|
||||
dropdown_val === "custom_period",
|
||||
);
|
||||
|
||||
let custom_input_val = "";
|
||||
if (dropdown_val === "retain_for_period") {
|
||||
custom_input_val = value;
|
||||
}
|
||||
$("#id_realm_message_retention_custom_input").val(custom_input_val);
|
||||
}
|
||||
|
||||
function set_org_join_restrictions_dropdown() {
|
||||
|
@ -1146,7 +1151,7 @@ export function build_page() {
|
|||
const message_retention_setting_dropdown_value = e.target.value;
|
||||
change_element_block_display_property(
|
||||
"id_realm_message_retention_custom_input",
|
||||
message_retention_setting_dropdown_value === "retain_for_period",
|
||||
message_retention_setting_dropdown_value === "custom_period",
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -75,8 +75,8 @@
|
|||
id="id_realm_message_retention_days" class="prop-element"
|
||||
data-setting-widget-type="message-retention-setting"
|
||||
{{#unless zulip_plan_is_not_limited}}disabled{{/unless}}>
|
||||
<option value="retain_forever">{{t 'Retain forever' }}</option>
|
||||
<option value="retain_for_period">{{t 'Retain for N days after posting' }}</option>
|
||||
<option value="unlimited">{{t 'Retain forever' }}</option>
|
||||
<option value="custom_period">{{t 'Retain for N days after posting' }}</option>
|
||||
</select>
|
||||
|
||||
<div class="dependent-inline-block">
|
||||
|
|
Loading…
Reference in New Issue