diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 8c11b44a6a..6102c868c5 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -49,6 +49,7 @@ set_global('settings_org', { reset_realm_default_language: noop, update_message_retention_days: noop, update_realm_description: noop, + sync_realm_settings: noop, }); set_global('message_edit', { diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index 62933d95a0..9f21a8f023 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -67,6 +67,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) { invite_by_admins_only: noop, invite_required: noop, mandatory_topics: noop, + message_content_edit_limit_seconds: noop, message_retention_days: settings_org.update_message_retention_days, name: notifications.redraw_title, name_changes_disabled: settings_account.update_name_change_display, @@ -79,6 +80,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) { if (event.op === 'update' && _.has(realm_settings, event.property)) { page_params['realm_' + event.property] = event.value; realm_settings[event.property](); + settings_org.sync_realm_settings(event.property); if (event.property === 'create_stream_by_admins_only') { if (!page_params.is_admin) { page_params.can_create_streams = (!page_params. @@ -101,6 +103,9 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) { if (key === 'allow_message_editing') { message_edit.update_message_topic_editing_pencil(); } + if (_.has(realm_settings, key)) { + settings_org.sync_realm_settings(key); + } }); if (event.data.authentication_methods !== undefined) { settings_org.populate_auth_methods(event.data.authentication_methods); diff --git a/static/js/settings_org.js b/static/js/settings_org.js index a262845abb..2c4b29495f 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -679,6 +679,25 @@ 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-profile-form").off('submit').on('submit', function (e) { e.preventDefault(); e.stopPropagation();