From 8abff20ce8e9a0b98ff7531eedc2fa15387b6a5d Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 21 Feb 2020 20:45:34 +0000 Subject: [PATCH] settings: Move time limit properties. We have to extract a local `config` due to line length restrictions. (Or do something else ugly.) --- static/js/admin.js | 4 +-- static/js/settings_config.js | 35 +++++++++++++++++++++++++++ static/js/settings_org.js | 47 ++++++------------------------------ 3 files changed, 45 insertions(+), 41 deletions(-) diff --git a/static/js/admin.js b/static/js/admin.js index 0825f1a281..da6365cd28 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -80,8 +80,8 @@ exports.build_page = function () { }; options.admin_settings_label = admin_settings_label; - options.msg_edit_limit_dropdown_values = settings_org.msg_edit_limit_dropdown_values; - options.msg_delete_limit_dropdown_values = settings_org.msg_delete_limit_dropdown_values; + options.msg_edit_limit_dropdown_values = settings_config.msg_edit_limit_dropdown_values; + options.msg_delete_limit_dropdown_values = settings_config.msg_delete_limit_dropdown_values; options.bot_creation_policy_values = settings_bots.bot_creation_policy_values; options.email_address_visibility_values = settings_config.email_address_visibility_values; _.extend(options, settings_org.get_organization_settings_options()); diff --git a/static/js/settings_config.js b/static/js/settings_config.js index 4a10997e4e..c387d0d4e1 100644 --- a/static/js/settings_config.js +++ b/static/js/settings_config.js @@ -116,3 +116,38 @@ exports.private_message_policy_values = { description: i18n.t("Private messages disabled"), }, }; + +const time_limit_dropdown_values = { + any_time: { + text: i18n.t("Any time"), + seconds: 0, + }, + never: { + text: i18n.t("Never"), + }, + upto_two_min: { + text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("2 minutes")}), + seconds: 2 * 60, + }, + upto_ten_min: { + text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("10 minutes")}), + seconds: 10 * 60, + }, + upto_one_hour: { + text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 hour")}), + seconds: 60 * 60, + }, + 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: { + text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 week")}), + seconds: 7 * 24 * 60 * 60, + }, + 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; diff --git a/static/js/settings_org.js b/static/js/settings_org.js index d8ba8a4c8b..73d63c95a6 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -124,7 +124,7 @@ function get_property_value(property_name) { if (!page_params.realm_allow_message_editing) { return "never"; } - value = _.findKey(exports.msg_edit_limit_dropdown_values, function (elem) { + 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) { @@ -137,7 +137,7 @@ function get_property_value(property_name) { if (!page_params.realm_allow_message_deleting) { return "never"; } - value = _.findKey(exports.msg_delete_limit_dropdown_values, function (elem) { + 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) { @@ -238,41 +238,6 @@ function set_video_chat_provider_dropdown() { } } -const time_limit_dropdown_values = { - any_time: { - text: i18n.t("Any time"), - seconds: 0, - }, - never: { - text: i18n.t("Never"), - }, - upto_two_min: { - text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("2 minutes")}), - seconds: 2 * 60, - }, - upto_ten_min: { - text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("10 minutes")}), - seconds: 10 * 60, - }, - upto_one_hour: { - text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 hour")}), - seconds: 60 * 60, - }, - 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: { - text: i18n.t("Up to __time_limit__ after posting", {time_limit: i18n.t("1 week")}), - seconds: 7 * 24 * 60 * 60, - }, - 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; - function set_msg_edit_limit_dropdown() { const value = get_property_value("realm_msg_edit_limit_setting"); $("#id_realm_msg_edit_limit_setting").val(value); @@ -717,6 +682,10 @@ 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(); if (edit_limit_setting_value === 'never') { @@ -728,7 +697,7 @@ exports.build_page = function () { } else { data.allow_message_editing = true; data.message_content_edit_limit_seconds = - exports.msg_edit_limit_dropdown_values[edit_limit_setting_value].seconds; + config.msg_edit_limit_dropdown_values[edit_limit_setting_value].seconds; } const delete_limit_setting_value = $("#id_realm_msg_delete_limit_setting").val(); if (delete_limit_setting_value === 'never') { @@ -740,7 +709,7 @@ exports.build_page = function () { } else { data.allow_message_deleting = true; data.message_content_delete_limit_seconds = - exports.msg_delete_limit_dropdown_values[delete_limit_setting_value].seconds; + config.msg_delete_limit_dropdown_values[delete_limit_setting_value].seconds; } } else if (subsection === 'notifications') { data.notifications_stream_id = JSON.stringify(