2021-08-17 14:43:29 +02:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2023-10-07 00:09:47 +02:00
|
|
|
import * as audible_notifications from "./audible_notifications";
|
2024-07-18 15:42:17 +02:00
|
|
|
import {
|
|
|
|
NON_COMPACT_MODE_FONT_SIZE_PX,
|
|
|
|
NON_COMPACT_MODE_LINE_HEIGHT_PERCENT,
|
|
|
|
} from "./information_density";
|
2021-10-02 13:34:52 +02:00
|
|
|
import * as overlays from "./overlays";
|
2024-07-18 15:42:17 +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";
|
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";
|
2024-01-09 20:36:02 +01:00
|
|
|
import * as settings_preferences from "./settings_preferences";
|
2024-02-13 02:08:16 +01:00
|
|
|
import {current_user} from "./state_data";
|
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() {
|
2024-02-13 02:08:16 +01:00
|
|
|
if (!current_user.is_admin) {
|
2021-09-16 19:18:39 +02:00
|
|
|
$(".organization-box [data-name='organization-level-user-defaults']")
|
|
|
|
.find("input, select")
|
|
|
|
.prop("disabled", true);
|
|
|
|
|
2024-06-26 10:06:58 +02:00
|
|
|
$(".organization-box [data-name='organization-level-user-defaults']")
|
|
|
|
.find("input[type='checkbox']:disabled")
|
|
|
|
.closest(".input-group")
|
|
|
|
.addClass("control-label-disabled");
|
|
|
|
|
2021-09-16 19:18:39 +02:00
|
|
|
$(".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;
|
|
|
|
}
|
2021-11-09 19:05:08 +01:00
|
|
|
|
2024-06-25 09:13:10 +02:00
|
|
|
const $element = $(`#realm_${CSS.escape(property)}`);
|
|
|
|
if ($element.length) {
|
2024-06-18 11:50:51 +02:00
|
|
|
const $subsection = $element.closest(".settings-subsection-parent");
|
|
|
|
if ($subsection.find(".save-button-controls").hasClass("hide")) {
|
|
|
|
settings_org.discard_realm_default_property_element_changes($element[0]);
|
|
|
|
} else {
|
|
|
|
settings_org.discard_realm_default_settings_subsection_changes($subsection);
|
|
|
|
}
|
2021-11-09 14:17:09 +01:00
|
|
|
}
|
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);
|
2023-10-11 00:44:18 +02:00
|
|
|
const $notification_sound_elem = $("audio#realm-default-notification-sound-audio");
|
2023-09-07 07:53:50 +02:00
|
|
|
const $notification_sound_dropdown = $container.find(".setting_notification_sound");
|
|
|
|
|
2024-01-09 20:36:02 +01:00
|
|
|
settings_preferences.set_up(realm_default_settings_panel);
|
2023-09-07 07:53:50 +02:00
|
|
|
|
2023-10-07 00:09:47 +02:00
|
|
|
audible_notifications.update_notification_sound_source(
|
2023-09-07 07:53:50 +02:00
|
|
|
$notification_sound_elem,
|
|
|
|
realm_default_settings_panel.settings_object,
|
|
|
|
);
|
|
|
|
|
|
|
|
$notification_sound_dropdown.on("change", () => {
|
|
|
|
const sound = $notification_sound_dropdown.val().toLowerCase();
|
2023-10-07 00:09:47 +02:00
|
|
|
audible_notifications.update_notification_sound_source($notification_sound_elem, {
|
2023-09-07 07:53:50 +02:00
|
|
|
notification_sound: sound,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-07-18 15:42:17 +02:00
|
|
|
if (!page_params.development_environment) {
|
|
|
|
$("#realm_dense_mode").on("change", (e) => {
|
|
|
|
const val = $(e.target).prop("checked");
|
|
|
|
if (val) {
|
|
|
|
$container.find(".information-density-settings").hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
!realm_user_settings_defaults.dense_mode &&
|
|
|
|
(realm_user_settings_defaults.web_font_size_px !== NON_COMPACT_MODE_FONT_SIZE_PX ||
|
|
|
|
realm_user_settings_defaults.web_line_height_percent !==
|
|
|
|
NON_COMPACT_MODE_LINE_HEIGHT_PERCENT)
|
|
|
|
) {
|
|
|
|
$container.find(".information-density-settings").show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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-10-27 09:48:10 +02:00
|
|
|
$("#realm_email_address_visibility").val(realm_user_settings_defaults.email_address_visibility);
|
|
|
|
|
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 =
|
2024-10-02 07:59:50 +02:00
|
|
|
"audio#realm-default-notification-sound-audio";
|
2021-09-20 13:38:38 +02:00
|
|
|
realm_default_settings_panel.for_realm_settings = true;
|
|
|
|
}
|