2021-06-30 19:48:43 +02:00
|
|
|
import {parseISO} from "date-fns";
|
2021-04-13 06:02:45 +02:00
|
|
|
import Handlebars from "handlebars/runtime";
|
2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 01:23:16 +01:00
|
|
|
import timezones from "../generated/timezones.json";
|
2021-06-11 12:22:04 +02:00
|
|
|
import render_settings_overlay from "../templates/settings_overlay.hbs";
|
2021-02-28 01:23:16 +01:00
|
|
|
import render_settings_tab from "../templates/settings_tab.hbs";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-28 01:23:35 +01:00
|
|
|
import * as admin from "./admin";
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-04-05 09:53:15 +02:00
|
|
|
import * as common from "./common";
|
2021-06-15 22:37:07 +02:00
|
|
|
import {$t, $t_html, get_language_list_columns} from "./i18n";
|
2021-02-28 01:23:16 +01:00
|
|
|
import * as overlays from "./overlays";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:23:16 +01:00
|
|
|
import * as people from "./people";
|
|
|
|
import * as settings_bots from "./settings_bots";
|
|
|
|
import * as settings_config from "./settings_config";
|
2021-03-21 16:46:13 +01:00
|
|
|
import * as settings_data from "./settings_data";
|
2021-06-15 17:23:38 +02:00
|
|
|
import * as settings_display from "./settings_display";
|
2021-02-28 01:23:16 +01:00
|
|
|
import * as settings_panel_menu from "./settings_panel_menu";
|
|
|
|
import * as settings_sections from "./settings_sections";
|
|
|
|
import * as settings_toggle from "./settings_toggle";
|
2019-07-09 21:24:00 +02:00
|
|
|
|
2021-02-28 01:23:16 +01:00
|
|
|
export let settings_label;
|
2020-07-24 06:02:07 +02:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("body").ready(() => {
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#settings_overlay_container").on("click", (e) => {
|
2017-08-29 19:06:31 +02:00
|
|
|
if (!overlays.is_modal_open()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-16 12:44:42 +02:00
|
|
|
if ($(e.target).closest(".modal").length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-29 19:06:31 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2018-05-23 22:29:00 +02:00
|
|
|
// Whenever opening a modal(over settings overlay) in an event handler
|
|
|
|
// attached to a click event, make sure to stop the propagation of the
|
|
|
|
// event to the parent container otherwise the modal will not open. This
|
|
|
|
// is so because this event handler will get fired on any click in settings
|
|
|
|
// overlay and subsequently close any open modal.
|
2017-08-29 19:06:31 +02:00
|
|
|
overlays.close_active_modal();
|
|
|
|
});
|
2017-03-01 01:31:33 +01:00
|
|
|
});
|
|
|
|
|
2018-03-24 13:44:16 +01:00
|
|
|
function setup_settings_label() {
|
2021-02-28 01:23:16 +01:00
|
|
|
settings_label = {
|
2018-03-24 13:44:16 +01:00
|
|
|
// settings_notification
|
2021-04-13 06:51:54 +02:00
|
|
|
enable_online_push_notifications: $t({
|
|
|
|
defaultMessage: "Send mobile notifications even if I'm online (useful for testing)",
|
|
|
|
}),
|
|
|
|
pm_content_in_desktop_notifications: $t({
|
|
|
|
defaultMessage: "Include content of private messages in desktop notifications",
|
|
|
|
}),
|
|
|
|
desktop_icon_count_display: $t({
|
|
|
|
defaultMessage: "Unread count summary (appears in desktop sidebar and browser tab)",
|
|
|
|
}),
|
|
|
|
enable_digest_emails: $t({defaultMessage: "Send digest emails when I'm away"}),
|
|
|
|
enable_login_emails: $t({
|
|
|
|
defaultMessage: "Send email notifications for new logins to my account",
|
|
|
|
}),
|
2021-04-28 00:25:27 +02:00
|
|
|
enable_marketing_emails: $t({
|
|
|
|
defaultMessage: "Send me occasional marketing emails about Zulip (a few times a year)",
|
|
|
|
}),
|
2021-04-13 06:51:54 +02:00
|
|
|
message_content_in_email_notifications: $t({
|
2021-04-20 23:27:25 +02:00
|
|
|
defaultMessage: "Include message content in message notification emails",
|
2021-04-13 06:51:54 +02:00
|
|
|
}),
|
|
|
|
realm_name_in_notifications: $t({
|
2021-04-20 23:27:25 +02:00
|
|
|
defaultMessage: "Include organization name in subject of message notification emails",
|
2021-04-13 06:51:54 +02:00
|
|
|
}),
|
|
|
|
presence_enabled: $t({
|
|
|
|
defaultMessage: "Display my availability to other users when online",
|
|
|
|
}),
|
2018-04-17 21:52:25 +02:00
|
|
|
|
|
|
|
// display settings
|
2021-04-13 06:51:54 +02:00
|
|
|
dense_mode: $t({defaultMessage: "Dense mode"}),
|
|
|
|
fluid_layout_width: $t({defaultMessage: "Use full width on wide screens"}),
|
|
|
|
high_contrast_mode: $t({defaultMessage: "High contrast mode"}),
|
|
|
|
left_side_userlist: $t({
|
|
|
|
defaultMessage: "Show user list on left sidebar in narrow windows",
|
|
|
|
}),
|
|
|
|
starred_message_counts: $t({defaultMessage: "Show counts for starred messages"}),
|
|
|
|
twenty_four_hour_time: $t({defaultMessage: "Time format"}),
|
2021-04-13 06:02:45 +02:00
|
|
|
translate_emoticons: new Handlebars.SafeString(
|
|
|
|
$t_html({
|
|
|
|
defaultMessage: "Convert emoticons before sending (<code>:)</code> becomes 😃)",
|
|
|
|
}),
|
2020-07-15 00:34:28 +02:00
|
|
|
),
|
2018-03-24 13:44:16 +01:00
|
|
|
};
|
|
|
|
}
|
2017-03-01 01:31:33 +01:00
|
|
|
|
2021-06-30 19:48:43 +02:00
|
|
|
function get_parsed_date_of_joining() {
|
|
|
|
const user_date_joined = people.get_by_user_id(page_params.user_id, false).date_joined;
|
|
|
|
const dateFormat = new Intl.DateTimeFormat("default", {dateStyle: "long"});
|
|
|
|
return dateFormat.format(parseISO(user_date_joined));
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:23:16 +01:00
|
|
|
export function build_page() {
|
2018-03-24 13:44:16 +01:00
|
|
|
setup_settings_label();
|
2018-01-29 16:10:54 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const rendered_settings_tab = render_settings_tab({
|
2017-01-20 23:49:20 +01:00
|
|
|
full_name: people.my_full_name(),
|
2021-06-30 19:48:43 +02:00
|
|
|
date_joined_text: get_parsed_date_of_joining(),
|
2020-07-20 22:18:43 +02:00
|
|
|
page_params,
|
2020-07-15 00:34:28 +02:00
|
|
|
enable_sound_select:
|
|
|
|
page_params.enable_sounds || page_params.enable_stream_audible_notifications,
|
2020-07-15 01:29:15 +02:00
|
|
|
zuliprc: "zuliprc",
|
|
|
|
botserverrc: "botserverrc",
|
2020-09-29 22:20:46 +02:00
|
|
|
timezones: timezones.timezones,
|
2018-06-13 16:59:15 +02:00
|
|
|
can_create_new_bots: settings_bots.can_create_new_bots(),
|
2021-02-28 01:23:16 +01:00
|
|
|
settings_label,
|
2020-02-21 14:26:11 +01:00
|
|
|
demote_inactive_streams_values: settings_config.demote_inactive_streams_values,
|
2020-05-16 13:13:59 +02:00
|
|
|
color_scheme_values: settings_config.color_scheme_values,
|
2021-03-10 13:56:10 +01:00
|
|
|
default_view_values: settings_config.default_view_values,
|
2020-02-21 14:26:11 +01:00
|
|
|
twenty_four_hour_time_values: settings_config.twenty_four_hour_time_values,
|
2020-03-28 18:03:43 +01:00
|
|
|
general_settings: settings_config.all_notifications().general_settings,
|
|
|
|
notification_settings: settings_config.all_notifications().settings,
|
2021-03-22 13:14:33 +01:00
|
|
|
desktop_icon_count_display_values: settings_config.desktop_icon_count_display_values,
|
2021-05-09 22:29:53 +02:00
|
|
|
show_push_notifications_tooltip:
|
|
|
|
settings_config.all_notifications().show_push_notifications_tooltip,
|
2020-02-21 14:26:11 +01:00
|
|
|
display_settings: settings_config.get_all_display_settings(),
|
2021-03-21 16:46:13 +01:00
|
|
|
user_can_change_name: settings_data.user_can_change_name(),
|
|
|
|
user_can_change_avatar: settings_data.user_can_change_avatar(),
|
2021-04-29 15:49:01 +02:00
|
|
|
user_role_text: people.get_user_type(page_params.user_id),
|
2021-06-15 17:23:38 +02:00
|
|
|
default_language_name: settings_display.default_language_name,
|
2021-06-15 22:37:07 +02:00
|
|
|
language_list_dbl_col: get_language_list_columns(page_params.default_language),
|
2017-01-20 23:49:20 +01:00
|
|
|
});
|
|
|
|
|
2018-03-22 22:10:08 +01:00
|
|
|
$(".settings-box").html(rendered_settings_tab);
|
2021-04-05 09:53:15 +02:00
|
|
|
common.setup_password_visibility_toggle(
|
|
|
|
"#old_password",
|
|
|
|
"#old_password + .password_visibility_toggle",
|
2021-04-20 16:49:39 +02:00
|
|
|
{tippy_tooltips: true},
|
2021-04-05 09:53:15 +02:00
|
|
|
);
|
|
|
|
common.setup_password_visibility_toggle(
|
|
|
|
"#new_password",
|
|
|
|
"#new_password + .password_visibility_toggle",
|
2021-04-20 16:49:39 +02:00
|
|
|
{tippy_tooltips: true},
|
2021-04-05 09:53:15 +02:00
|
|
|
);
|
2021-02-28 01:23:16 +01:00
|
|
|
}
|
2018-12-06 01:59:07 +01:00
|
|
|
|
2021-02-28 01:23:16 +01:00
|
|
|
export function launch(section) {
|
|
|
|
build_page();
|
2018-12-06 20:18:56 +01:00
|
|
|
admin.build_page();
|
2018-12-08 19:28:26 +01:00
|
|
|
settings_sections.reset_sections();
|
2018-12-06 01:59:07 +01:00
|
|
|
|
2017-05-27 15:40:54 +02:00
|
|
|
overlays.open_settings();
|
2020-06-25 00:51:20 +02:00
|
|
|
settings_panel_menu.normal_settings.activate_section_or_default(section);
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_toggle.highlight_toggle("settings");
|
2021-02-28 01:23:16 +01:00
|
|
|
}
|
2016-12-03 01:12:52 +01:00
|
|
|
|
2021-02-28 01:23:16 +01:00
|
|
|
export function set_settings_header(key) {
|
2021-07-01 11:38:38 +02:00
|
|
|
const selected_tab_key = $("#settings_page .tab-switcher .selected").data("tab-key");
|
|
|
|
let header_prefix = $t_html({defaultMessage: "Personal settings"});
|
|
|
|
if (selected_tab_key === "organization") {
|
|
|
|
header_prefix = $t_html({defaultMessage: "Organization settings"});
|
|
|
|
}
|
|
|
|
$(".settings-header h1 .header-prefix").text(header_prefix);
|
|
|
|
|
2021-02-03 23:23:32 +01:00
|
|
|
const header_text = $(
|
|
|
|
`#settings_page .sidebar-list [data-section='${CSS.escape(key)}'] .text`,
|
|
|
|
).text();
|
2019-08-22 13:08:24 +02:00
|
|
|
if (header_text) {
|
|
|
|
$(".settings-header h1 .section").text(" / " + header_text);
|
2017-05-09 22:09:13 +02:00
|
|
|
} else {
|
2020-07-15 00:34:28 +02:00
|
|
|
blueslip.warn(
|
|
|
|
"Error: the key '" +
|
|
|
|
key +
|
|
|
|
"' does not exist in the settings" +
|
|
|
|
" sidebar list. Please add it.",
|
|
|
|
);
|
2017-05-09 22:09:13 +02:00
|
|
|
}
|
2021-02-28 01:23:16 +01:00
|
|
|
}
|
2021-06-11 12:22:04 +02:00
|
|
|
|
|
|
|
export function initialize() {
|
|
|
|
const rendered_settings_overlay = render_settings_overlay({
|
|
|
|
is_owner: page_params.is_owner,
|
|
|
|
is_admin: page_params.is_admin,
|
|
|
|
is_guest: page_params.is_guest,
|
|
|
|
show_uploaded_files_section: page_params.max_file_upload_size_mib > 0,
|
|
|
|
show_emoji_settings_lock:
|
|
|
|
!page_params.is_admin && page_params.realm_add_emoji_by_admins_only,
|
|
|
|
});
|
|
|
|
$("#settings_overlay_container").append(rendered_settings_overlay);
|
|
|
|
}
|