2021-08-17 14:43:29 +02:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-10-02 13:34:52 +02:00
|
|
|
import * as overlays from "./overlays";
|
2021-09-16 19:18:39 +02:00
|
|
|
import {page_params} from "./page_params";
|
2021-08-17 14:43:29 +02:00
|
|
|
import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
|
|
|
|
import * as settings_display from "./settings_display";
|
2021-08-26 21:03:27 +02:00
|
|
|
import * as settings_notifications from "./settings_notifications";
|
2021-09-28 09:09:52 +02:00
|
|
|
import * as settings_org from "./settings_org";
|
2021-08-17 14:43:29 +02:00
|
|
|
|
2021-09-20 13:38:38 +02:00
|
|
|
export const realm_default_settings_panel = {};
|
|
|
|
|
2021-09-16 19:18:39 +02:00
|
|
|
export function maybe_disable_widgets() {
|
|
|
|
if (!page_params.is_admin) {
|
|
|
|
$(".organization-box [data-name='organization-level-user-defaults']")
|
|
|
|
.find("input, select")
|
|
|
|
.prop("disabled", true);
|
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-level-user-defaults']")
|
|
|
|
.find(".play_notification_sound")
|
|
|
|
.addClass("control-label-disabled");
|
|
|
|
}
|
|
|
|
}
|
2021-10-02 13:34:52 +02:00
|
|
|
|
|
|
|
export function update_page(property) {
|
|
|
|
if (!overlays.settings_open()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
const $container = $(realm_default_settings_panel.container);
|
2021-11-09 14:17:09 +01:00
|
|
|
let value = realm_user_settings_defaults[property];
|
2021-10-02 13:34:52 +02:00
|
|
|
|
2021-11-09 19:05:08 +01:00
|
|
|
// settings_org.set_input_element_value doesn't support radio
|
|
|
|
// button widgets like this one.
|
2021-10-02 13:34:52 +02:00
|
|
|
if (property === "emojiset") {
|
2022-01-25 11:36:19 +01:00
|
|
|
$container.find(`input[value=${CSS.escape(value)}]`).prop("checked", true);
|
2021-10-02 13:34:52 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-11-09 19:05:08 +01:00
|
|
|
|
2021-12-02 15:56:34 +01:00
|
|
|
if (property === "email_notifications_batching_period_seconds") {
|
2022-01-25 11:36:19 +01:00
|
|
|
settings_notifications.set_notification_batching_ui($container, value);
|
2021-12-02 15:56:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-09 19:05:08 +01:00
|
|
|
// The twenty_four_hour_time setting is represented as a boolean
|
|
|
|
// in the API, but a dropdown with "true"/"false" as strings in
|
|
|
|
// the UI, so we need to convert its format here.
|
2021-11-09 14:17:09 +01:00
|
|
|
if (property === "twenty_four_hour_time") {
|
|
|
|
value = value.toString();
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $input_elem = $container.find(`[name=${CSS.escape(property)}]`);
|
|
|
|
settings_org.set_input_element_value($input_elem, value);
|
2021-10-02 13:34:52 +02:00
|
|
|
}
|
|
|
|
|
2021-08-17 14:43:29 +02:00
|
|
|
export function set_up() {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $container = $(realm_default_settings_panel.container);
|
2021-09-20 13:38:38 +02:00
|
|
|
settings_display.set_up(realm_default_settings_panel);
|
2021-09-20 15:56:32 +02:00
|
|
|
settings_notifications.set_up(realm_default_settings_panel);
|
2021-08-30 09:51:38 +02:00
|
|
|
|
2021-09-28 09:09:52 +02:00
|
|
|
settings_org.register_save_discard_widget_handlers(
|
2022-01-25 11:36:19 +01:00
|
|
|
$container,
|
2021-09-28 09:09:52 +02:00
|
|
|
"/json/realm/user_settings_defaults",
|
|
|
|
true,
|
|
|
|
);
|
2021-09-17 12:51:31 +02:00
|
|
|
|
2021-09-16 19:18:39 +02:00
|
|
|
maybe_disable_widgets();
|
2021-08-17 14:43:29 +02:00
|
|
|
}
|
2021-09-20 13:38:38 +02:00
|
|
|
|
|
|
|
export function initialize() {
|
|
|
|
realm_default_settings_panel.container = "#realm-user-default-settings";
|
|
|
|
realm_default_settings_panel.settings_object = realm_user_settings_defaults;
|
2021-09-20 15:56:32 +02:00
|
|
|
realm_default_settings_panel.notification_sound_elem =
|
|
|
|
"#realm-default-notification-sound-audio";
|
2021-09-20 13:38:38 +02:00
|
|
|
realm_default_settings_panel.for_realm_settings = true;
|
|
|
|
}
|