mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
We now enable and disable save button when changing inputs for custom time limit settings in change_save_button_state function only which shows or hide the save-discard widget instead of handling them in "change" event handlers. This fixes the bug of save button flashing to its enabled state from disabled state before hiding after clicking on "Discard" as now button is re-enabled only after save-discard widget is hidden and it is disabled if required before being shown. Note that there is still a bug for message edit and delete limit settings where the save button flashes to enabled state when setting is changed to the original value instead of clicking on "Discard". This bug is not present for email notification batching setting in a follow-up PR. This commit also renames update_save_button_state function to enable_or_disable_save_button to avoid confusion with change_save_button_state function.
75 lines
2.6 KiB
JavaScript
75 lines
2.6 KiB
JavaScript
import $ from "jquery";
|
|
|
|
import * as overlays from "./overlays";
|
|
import {page_params} from "./page_params";
|
|
import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
|
|
import * as settings_display from "./settings_display";
|
|
import * as settings_notifications from "./settings_notifications";
|
|
import * as settings_org from "./settings_org";
|
|
|
|
export const realm_default_settings_panel = {};
|
|
|
|
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");
|
|
}
|
|
}
|
|
|
|
export function update_page(property) {
|
|
if (!overlays.settings_open()) {
|
|
return;
|
|
}
|
|
const $container = $(realm_default_settings_panel.container);
|
|
let value = realm_user_settings_defaults[property];
|
|
|
|
// settings_org.set_input_element_value doesn't support radio
|
|
// button widgets like these.
|
|
if (property === "emojiset" || property === "user_list_style") {
|
|
$container.find(`input[value=${CSS.escape(value)}]`).prop("checked", true);
|
|
return;
|
|
}
|
|
|
|
if (property === "email_notifications_batching_period_seconds") {
|
|
settings_notifications.set_notification_batching_ui($container, value);
|
|
return;
|
|
}
|
|
|
|
// 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.
|
|
if (property === "twenty_four_hour_time") {
|
|
value = value.toString();
|
|
}
|
|
|
|
const $input_elem = $container.find(`[name=${CSS.escape(property)}]`);
|
|
settings_org.set_input_element_value($input_elem, value);
|
|
}
|
|
|
|
export function set_up() {
|
|
const $container = $(realm_default_settings_panel.container);
|
|
settings_display.set_up(realm_default_settings_panel);
|
|
settings_notifications.set_up(realm_default_settings_panel);
|
|
|
|
settings_org.register_save_discard_widget_handlers(
|
|
$container,
|
|
"/json/realm/user_settings_defaults",
|
|
true,
|
|
);
|
|
|
|
maybe_disable_widgets();
|
|
}
|
|
|
|
export function initialize() {
|
|
realm_default_settings_panel.container = "#realm-user-default-settings";
|
|
realm_default_settings_panel.settings_object = realm_user_settings_defaults;
|
|
realm_default_settings_panel.notification_sound_elem =
|
|
"#realm-default-notification-sound-audio";
|
|
realm_default_settings_panel.for_realm_settings = true;
|
|
}
|