mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
settings_org: Convert time_limit_dropdown_values from object to Map.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
53933c7562
commit
1cd1b5d198
@@ -117,37 +117,37 @@ exports.private_message_policy_values = {
|
||||
},
|
||||
};
|
||||
|
||||
const time_limit_dropdown_values = {
|
||||
any_time: {
|
||||
const time_limit_dropdown_values = new Map([
|
||||
["any_time", {
|
||||
text: i18n.t("Any time"),
|
||||
seconds: 0,
|
||||
},
|
||||
never: {
|
||||
}],
|
||||
["never", {
|
||||
text: i18n.t("Never"),
|
||||
},
|
||||
upto_two_min: {
|
||||
}],
|
||||
["upto_two_min", {
|
||||
text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("2 minutes")}),
|
||||
seconds: 2 * 60,
|
||||
},
|
||||
upto_ten_min: {
|
||||
}],
|
||||
["upto_ten_min", {
|
||||
text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("10 minutes")}),
|
||||
seconds: 10 * 60,
|
||||
},
|
||||
upto_one_hour: {
|
||||
}],
|
||||
["upto_one_hour", {
|
||||
text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 hour")}),
|
||||
seconds: 60 * 60,
|
||||
},
|
||||
upto_one_day: {
|
||||
}],
|
||||
["upto_one_day", {
|
||||
text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 day")}),
|
||||
seconds: 24 * 60 * 60,
|
||||
},
|
||||
upto_one_week: {
|
||||
}],
|
||||
["upto_one_week", {
|
||||
text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 week")}),
|
||||
seconds: 7 * 24 * 60 * 60,
|
||||
},
|
||||
custom_limit: {
|
||||
}],
|
||||
["custom_limit", {
|
||||
text: i18n.t("Up to N minutes after posting"),
|
||||
},
|
||||
};
|
||||
}],
|
||||
]);
|
||||
exports.msg_edit_limit_dropdown_values = time_limit_dropdown_values;
|
||||
exports.msg_delete_limit_dropdown_values = time_limit_dropdown_values;
|
||||
|
||||
@@ -93,8 +93,6 @@ exports.get_realm_time_limits_in_minutes = function (property) {
|
||||
};
|
||||
|
||||
function get_property_value(property_name) {
|
||||
let value;
|
||||
|
||||
if (property_name === 'realm_message_content_edit_limit_minutes') {
|
||||
return exports.get_realm_time_limits_in_minutes('realm_message_content_edit_limit_seconds');
|
||||
}
|
||||
@@ -124,26 +122,24 @@ function get_property_value(property_name) {
|
||||
if (!page_params.realm_allow_message_editing) {
|
||||
return "never";
|
||||
}
|
||||
value = _.findKey(settings_config.msg_edit_limit_dropdown_values, function (elem) {
|
||||
return elem.seconds === page_params.realm_message_content_edit_limit_seconds;
|
||||
});
|
||||
if (value === undefined) {
|
||||
return "custom_limit";
|
||||
for (const [value, elem] of settings_config.msg_edit_limit_dropdown_values) {
|
||||
if (elem.seconds === page_params.realm_message_content_edit_limit_seconds) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
return "custom_limit";
|
||||
}
|
||||
|
||||
if (property_name === 'realm_msg_delete_limit_setting') {
|
||||
if (!page_params.realm_allow_message_deleting) {
|
||||
return "never";
|
||||
}
|
||||
value = _.findKey(settings_config.msg_delete_limit_dropdown_values, function (elem) {
|
||||
return elem.seconds === page_params.realm_message_content_delete_limit_seconds;
|
||||
});
|
||||
if (value === undefined) {
|
||||
return "custom_limit";
|
||||
for (const [value, elem] of settings_config.msg_delete_limit_dropdown_values) {
|
||||
if (elem.seconds === page_params.realm_message_content_delete_limit_seconds) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
return "custom_limit";
|
||||
}
|
||||
|
||||
if (property_name === 'realm_org_join_restrictions') {
|
||||
@@ -682,9 +678,6 @@ exports.build_page = function () {
|
||||
|
||||
function get_complete_data_for_subsection(subsection) {
|
||||
let data = {};
|
||||
// Hacky extra name created to avoid linter.
|
||||
// TODO: Fix this properly by just de-nesting this function outside build_page.
|
||||
const config = settings_config;
|
||||
|
||||
if (subsection === 'msg_editing') {
|
||||
const edit_limit_setting_value = $("#id_realm_msg_edit_limit_setting").val();
|
||||
@@ -697,7 +690,9 @@ exports.build_page = function () {
|
||||
} else {
|
||||
data.allow_message_editing = true;
|
||||
data.message_content_edit_limit_seconds =
|
||||
config.msg_edit_limit_dropdown_values[edit_limit_setting_value].seconds;
|
||||
settings_config.msg_edit_limit_dropdown_values.get(
|
||||
edit_limit_setting_value
|
||||
).seconds;
|
||||
}
|
||||
const delete_limit_setting_value = $("#id_realm_msg_delete_limit_setting").val();
|
||||
if (delete_limit_setting_value === 'never') {
|
||||
@@ -709,7 +704,9 @@ exports.build_page = function () {
|
||||
} else {
|
||||
data.allow_message_deleting = true;
|
||||
data.message_content_delete_limit_seconds =
|
||||
config.msg_delete_limit_dropdown_values[delete_limit_setting_value].seconds;
|
||||
settings_config.msg_delete_limit_dropdown_values.get(
|
||||
delete_limit_setting_value
|
||||
).seconds;
|
||||
}
|
||||
} else if (subsection === 'notifications') {
|
||||
data.notifications_stream_id = JSON.stringify(
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<label for="realm_msg_edit_limit_setting" class="dropdown-title">{{t "Allow message editing" }}</label>
|
||||
<select name="realm_msg_edit_limit_setting" id="id_realm_msg_edit_limit_setting" class="prop-element">
|
||||
{{#each msg_edit_limit_dropdown_values}}
|
||||
<option value="{{@key}}">{{this.text}}</option>
|
||||
<option value="{{0}}">{{1.text}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
<div class="dependent-inline-block">
|
||||
@@ -50,7 +50,7 @@
|
||||
</label>
|
||||
<select name="realm_msg_delete_limit_setting" id="id_realm_msg_delete_limit_setting" class="prop-element">
|
||||
{{#each msg_delete_limit_dropdown_values}}
|
||||
<option value="{{@key}}">{{this.text}}</option>
|
||||
<option value="{{0}}">{{1.text}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
<div class="dependent-inline-block">
|
||||
|
||||
Reference in New Issue
Block a user