diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 5cea074a56..9e1591c5aa 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -225,15 +225,35 @@ function test_submit_settings_form(submit_form) { success_callback = req.success; }; - ev.currentTarget = '#org-submit-other-permissions'; - let stubs = createSaveButtons('other-permissions'); + let subsection = 'other-permissions'; + ev.currentTarget = `#org-submit-${subsection}`; + let stubs = createSaveButtons(subsection); let save_button = stubs.save_button; - save_button.attr('id', 'org-submit-other-permissions'); + save_button.attr('id', `org-submit-${subsection}`); + save_button.replace = () => { + return `${subsection}`; + }; $("#id_realm_create_stream_permission").val("by_anyone"); $("#id_realm_add_emoji_by_admins_only").val("by_anyone"); $("#id_realm_message_retention_days").val("15"); - $("#id_realm_bot_creation_policy").val("1"); - $("#id_realm_email_address_visibility").val("1"); + const bot_creation_policy_elem = $("#id_realm_bot_creation_policy"); + bot_creation_policy_elem.val("1"); + bot_creation_policy_elem.attr('id', 'id_realm_bot_creation_policy'); + bot_creation_policy_elem.data = () => { + return "integer"; + }; + const email_address_visibility_elem = $("#id_realm_email_address_visibility"); + email_address_visibility_elem.val("1"); + email_address_visibility_elem.attr('id', 'id_realm_email_address_visibility'); + email_address_visibility_elem.data = () => { + return "integer"; + }; + + let subsection_elem = $(`#org-${subsection}`); + subsection_elem.set_find_results('.setting-widget', [ + bot_creation_policy_elem, + email_address_visibility_elem, + ]); patched = false; submit_form(ev); @@ -250,13 +270,30 @@ function test_submit_settings_form(submit_form) { assert.deepEqual(data, expected_value); - ev.currentTarget = '#org-submit-user-defaults'; - stubs = createSaveButtons('user-defaults'); + subsection = 'user-defaults'; + ev.currentTarget = `#org-submit-${subsection}`; + stubs = createSaveButtons(subsection); save_button = stubs.save_button; - save_button.attr('id', 'org-submit-user-defaults'); + save_button.attr('id', `org-submit-${subsection}`); - $("#id_realm_default_language").val("en"); - $("#id_realm_default_twenty_four_hour_time").prop("checked", true); + const realm_default_language_elem = $("#id_realm_default_language"); + realm_default_language_elem.val("en"); + realm_default_language_elem.attr('id', 'id_realm_default_language'); + realm_default_language_elem.data = () => { + return "text"; + }; + const realm_default_twenty_four_hour_time_elem = $("#id_realm_default_twenty_four_hour_time"); + realm_default_twenty_four_hour_time_elem.prop("checked", true); + realm_default_twenty_four_hour_time_elem.attr('id', 'id_realm_default_twenty_four_hour_time'); + realm_default_twenty_four_hour_time_elem.data = () => { + return "bool"; + }; + + subsection_elem = $(`#org-${subsection}`); + subsection_elem.set_find_results('.setting-widget', [ + realm_default_language_elem, + realm_default_twenty_four_hour_time_elem, + ]); submit_form(ev); assert(patched); diff --git a/static/js/settings_org.js b/static/js/settings_org.js index dbcde61e96..8824e5ab57 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -10,86 +10,6 @@ exports.reset = function () { meta.loaded = false; }; -var org_profile = { - name: { - type: 'text', - }, - description: { - type: 'text', - }, -}; - -var org_settings = { - msg_editing: { - allow_edit_history: { - type: 'bool', - }, - allow_community_topic_editing: { - type: 'bool', - }, - }, - other_settings: { - inline_image_preview: { - type: 'bool', - }, - inline_url_embed_preview: { - type: 'bool', - }, - mandatory_topics: { - type: 'bool', - }, - video_chat_provider: { - type: 'text', - }, - google_hangouts_domain: { - type: 'text', - }, - zoom_user_id: { - type: 'text', - }, - zoom_api_key: { - type: 'text', - }, - zoom_api_secret: { - type: 'text', - }, - message_content_allowed_in_email_notifications: { - type: 'bool', - }, - }, - user_defaults: { - default_language: { - type: 'text', - }, - default_twenty_four_hour_time: { - type: 'bool', - }, - }, - notifications: { - send_welcome_emails: { - type: 'bool', - }, - }, -}; - -var org_permissions = { - user_identity: { - name_changes_disabled: { - type: 'bool', - }, - email_changes_disabled: { - type: 'bool', - }, - }, - other_permissions: { - bot_creation_policy: { - type: 'integer', - }, - email_address_visibility: { - type: 'integer', - }, - }, -}; exports.maybe_disable_widgets = function () { if (page_params.is_admin) { @@ -131,17 +51,6 @@ exports.email_address_visibility_values = { }, }; -function get_subsection_property_types(subsection) { - if (_.has(org_settings, subsection)) { - return org_settings[subsection]; - } else if (_.has(org_permissions, subsection)) { - return org_permissions[subsection]; - } else if (subsection === 'org_profile') { - return org_profile; - } - return; -} - exports.get_realm_time_limits_in_minutes = function (property) { var val = (page_params[property] / 60).toFixed(1); if (parseFloat(val, 10) === parseInt(val, 10)) { @@ -622,19 +531,24 @@ exports.build_page = function () { // Populate authentication methods table exports.populate_auth_methods(page_params.realm_authentication_methods); - function populate_data_for_request(data, changing_property_types) { - _.each(changing_property_types, function (v, k) { - var field = changing_property_types[k]; - if (field.type === 'bool') { - data[k] = JSON.stringify($('#id_realm_' + k).prop('checked')); + function populate_data_for_request(subsection) { + var data = {}; + var subsection_elem = $('#org-' + subsection); + var input_elems = subsection_elem.find('.setting-widget'); + _.each(input_elems, function (input_elem) { + input_elem = $(input_elem); + var input_type = input_elem.data("setting-widget-type"); + var property_name = input_elem.attr('id').replace("id_realm_", ""); + if (input_type === 'bool') { + data[property_name] = JSON.stringify(input_elem.prop('checked')); return; } - if (field.type === 'text') { - data[k] = JSON.stringify($('#id_realm_' + k).val().trim()); + if (input_type === 'text') { + data[property_name] = JSON.stringify(input_elem.val().trim()); return; } - if (field.type === 'integer') { - data[k] = JSON.stringify(parseInt($("#id_realm_" + k).val().trim(), 10)); + if (input_type === 'integer') { + data[property_name] = JSON.stringify(parseInt(input_elem.val().trim(), 10)); } }); return data; @@ -830,7 +744,7 @@ exports.build_page = function () { var subsection_id = save_button.attr('id').replace("org-submit-", ""); var subsection = subsection_id.split('-').join('_'); - var data = populate_data_for_request({}, get_subsection_property_types(subsection)); + var data = populate_data_for_request(subsection_id); var opts = get_complete_data_for_subsection(subsection); data = _.extend(data, opts.data); var success_continuation = opts.success_continuation; diff --git a/static/templates/settings/organization-permissions-admin.handlebars b/static/templates/settings/organization-permissions-admin.handlebars index 1694bd39cb..4577424b1d 100644 --- a/static/templates/settings/organization-permissions-admin.handlebars +++ b/static/templates/settings/organization-permissions-admin.handlebars @@ -78,7 +78,7 @@
- {{#each bot_creation_policy_values}} {{/each}} @@ -95,7 +95,7 @@
- {{#each email_address_visibility_values}} {{/each}} diff --git a/static/templates/settings/organization-profile-admin.handlebars b/static/templates/settings/organization-profile-admin.handlebars index 48c7382a7a..48aae6d410 100644 --- a/static/templates/settings/organization-profile-admin.handlebars +++ b/static/templates/settings/organization-profile-admin.handlebars @@ -15,14 +15,14 @@
-
- +
diff --git a/static/templates/settings/organization-settings-admin.handlebars b/static/templates/settings/organization-settings-admin.handlebars index 85c17d30cb..942b88eb31 100644 --- a/static/templates/settings/organization-settings-admin.handlebars +++ b/static/templates/settings/organization-settings-admin.handlebars @@ -132,7 +132,7 @@
- {{#each language_list}} {{/each}} @@ -156,7 +156,7 @@ - {{#each realm_available_video_chat_providers}} {{/each}} @@ -166,7 +166,8 @@ + class="admin-realm-google-hangouts-domain setting-widget" + data-setting-widget-type="text"/>

@@ -179,21 +180,24 @@ + class="admin-realm-zoom-field setting-widget" + data-setting-widget-type="text"/>

+ class="admin-realm-zoom-field setting-widget" + data-setting-widget-type="text"/>
+ class="admin-realm-zoom-field setting-widget" + data-setting-widget-type="text"/>
diff --git a/static/templates/settings/settings_checkbox.handlebars b/static/templates/settings/settings_checkbox.handlebars index d7da14fb40..de6a30a419 100644 --- a/static/templates/settings/settings_checkbox.handlebars +++ b/static/templates/settings/settings_checkbox.handlebars @@ -1,6 +1,6 @@