2021-06-30 19:48:43 +02:00
|
|
|
import {parseISO} from "date-fns";
|
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-07-18 15:33:16 +02:00
|
|
|
import {$t, $t_html} 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";
|
2021-07-28 16:00:58 +02:00
|
|
|
import {user_settings} from "./user_settings";
|
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
|
|
|
|
2022-03-16 22:19:29 +01:00
|
|
|
$(() => {
|
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;
|
|
|
|
}
|
2022-07-23 00:15:37 +02:00
|
|
|
if ($(e.target).closest(".micromodal").length > 0) {
|
2017-09-16 12:44:42 +02:00
|
|
|
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
|
|
|
presence_enabled: $t({
|
2022-09-24 12:40:36 +02:00
|
|
|
defaultMessage: "Display my availability to other users",
|
2021-04-13 06:51:54 +02:00
|
|
|
}),
|
2022-09-24 12:40:36 +02:00
|
|
|
presence_enabled_parens_text: $t({defaultMessage: "invisible mode off"}),
|
2021-10-03 08:36:36 +02:00
|
|
|
send_stream_typing_notifications: $t({
|
|
|
|
defaultMessage: "Let subscribers see when I'm typing messages in streams",
|
|
|
|
}),
|
|
|
|
send_private_typing_notifications: $t({
|
|
|
|
defaultMessage: "Let recipients see when I'm typing private messages",
|
|
|
|
}),
|
2021-10-03 08:53:35 +02:00
|
|
|
send_read_receipts: $t({
|
2022-08-08 14:09:06 +02:00
|
|
|
defaultMessage: "Let others see when I've read messages",
|
2021-10-03 08:53:35 +02:00
|
|
|
}),
|
2018-04-17 21:52:25 +02:00
|
|
|
|
2021-09-17 01:07:32 +02:00
|
|
|
...settings_config.notification_settings_labels,
|
2021-08-31 12:45:21 +02:00
|
|
|
...settings_config.display_settings_labels,
|
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:
|
2021-07-28 16:00:58 +02:00
|
|
|
user_settings.enable_sounds || user_settings.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,
|
2022-08-12 22:41:06 +02:00
|
|
|
user_list_style_values: settings_config.user_list_style_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,
|
2021-08-27 15:46:23 +02:00
|
|
|
general_settings: settings_config.all_notifications(user_settings).general_settings,
|
|
|
|
notification_settings: settings_config.all_notifications(user_settings).settings,
|
2021-08-14 11:31:31 +02:00
|
|
|
email_notifications_batching_period_values:
|
|
|
|
settings_config.email_notifications_batching_period_values,
|
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:
|
2021-08-27 15:46:23 +02:00
|
|
|
settings_config.all_notifications(user_settings).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(),
|
2022-12-09 17:34:00 +01:00
|
|
|
user_can_change_email: settings_data.user_can_change_email(),
|
2021-04-29 15:49:01 +02:00
|
|
|
user_role_text: people.get_user_type(page_params.user_id),
|
2021-08-18 11:47:07 +02:00
|
|
|
default_language_name: settings_display.user_default_language_name,
|
2022-03-30 11:39:21 +02:00
|
|
|
realm_push_notifications_enabled: page_params.realm_push_notifications_enabled,
|
2021-08-25 13:03:05 +02:00
|
|
|
settings_object: user_settings,
|
2022-08-05 12:13:21 +02:00
|
|
|
send_read_receipts_tooltip: $t({
|
|
|
|
defaultMessage: "Read receipts are currently disabled in this organization.",
|
|
|
|
}),
|
2022-12-20 16:52:25 +01:00
|
|
|
user_is_only_organization_owner: people.is_current_user_only_owner(),
|
2017-01-20 23:49:20 +01:00
|
|
|
});
|
|
|
|
|
2018-03-22 22:10:08 +01:00
|
|
|
$(".settings-box").html(rendered_settings_tab);
|
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);
|
|
|
|
}
|