org settings: Make sync_realm_settings to be available at load time.

This moves `sync_realm_settings` function out of `_setup` so that
we can call `settings_org.sync_realm_settings` without opening
settings page at least once.

This also fixes a minor bug in which if we have two tabs opened and
in one we haven't opened settings page at least once and in
another we change an org setting, then we get an exception in
the former tab because of the event as `sync_realm_settings`
isn't defined yet.
This commit is contained in:
Shubham Dhama
2018-03-29 16:45:50 +05:30
committed by Tim Abbott
parent 29f57d54a0
commit 7eea186306

View File

@@ -351,6 +351,25 @@ function discard_property_element_changes(elem) {
exports.handle_dependent_subsettings(property_name);
}
exports.sync_realm_settings = function (property) {
if (!overlays.settings_open()) {
return;
}
if (property === 'message_content_edit_limit_seconds') {
property = 'message_content_edit_limit_minutes';
} else if (property === 'create_stream_by_admins_only' || property === 'waiting_period_threshold') {
// We use this path for `waiting_period_threshold` property because we
// don't get both 'create_stream_by_admins_only' and 'waiting_period_threshold'
// in the same event to determine the value of dropdown.
property = 'create_stream_permission';
}
var element = $('#id_realm_'+property);
if (element.length) {
discard_property_element_changes(element);
}
};
function _set_up() {
meta.loaded = true;
@@ -600,25 +619,6 @@ function _set_up() {
}
});
exports.sync_realm_settings = function (property) {
if (!overlays.settings_open()) {
return;
}
if (property === 'message_content_edit_limit_seconds') {
property = 'message_content_edit_limit_minutes';
} else if (property === 'create_stream_by_admins_only' || property === 'waiting_period_threshold') {
// We use this path for `waiting_period_threshold` property because we
// don't get both 'create_stream_by_admins_only' and 'waiting_period_threshold'
// in the same event to determine the value of dropdown.
property = 'create_stream_permission';
}
var element = $('#id_realm_'+property);
if (element.length) {
discard_property_element_changes(element);
}
};
$(".organization form.org-authentications-form").off('submit').on('submit', function (e) {
var authentication_methods_status = $("#admin-realm-authentication-methods-status").expectOne();