settings: Use subection-parent div to get subsction.

We used id of save-button to get subsection parameter
which is passed to get_complete_data_for_subsection.

This commit now changes it to instead get subsection
from settings-subsection-parent div. We also change
the id of settings-subsection-parent div of organization
joining settings in this commit to be a more reasonable
name as per this change.
This commit is contained in:
Sahil Batra 2022-12-07 16:46:37 +05:30 committed by Tim Abbott
parent e78ae9463d
commit 4b46f08b5f
3 changed files with 19 additions and 11 deletions

View File

@ -57,7 +57,7 @@ test("unloaded", () => {
function createSaveButtons(subsection) {
const $stub_save_button_header = $(`#org-${CSS.escape(subsection)}`);
const $save_button_controls = $(".save-button-controls");
const $stub_save_button = $(`#org-submit-${CSS.escape(subsection)}`);
const $stub_save_button = $(".save-discard-widget-button.save-button");
const $stub_discard_button = $(`#org-discard-${CSS.escape(subsection)}`);
const $stub_save_button_text = $(".save-discard-widget-button-text");
$stub_save_button_header.set_find_results(
@ -127,10 +127,11 @@ function test_submit_settings_form(override, submit_form) {
});
let subsection = "other-permissions";
ev.currentTarget = `#org-submit-${CSS.escape(subsection)}`;
ev.currentTarget = ".save-discard-widget-button.save-button";
let stubs = createSaveButtons(subsection);
let $save_button = stubs.$save_button;
$save_button.attr("id", `org-submit-${subsection}`);
let $save_button_header = stubs.$save_button_header;
$save_button_header.attr("id", `org-${subsection}`);
$("#id_realm_waiting_period_threshold").val(10);
@ -195,10 +196,11 @@ function test_submit_settings_form(override, submit_form) {
assert.deepEqual(data, expected_value);
subsection = "user-defaults";
ev.currentTarget = `#org-submit-${CSS.escape(subsection)}`;
ev.currentTarget = ".save-discard-widget-button.save-button";
stubs = createSaveButtons(subsection);
$save_button = stubs.$save_button;
$save_button.attr("id", `org-submit-${subsection}`);
$save_button_header = stubs.$save_button_header;
$save_button_header.attr("id", `org-${subsection}`);
const $realm_default_language_elem = $("#id_realm_default_language");
$realm_default_language_elem.val("en");
@ -224,9 +226,15 @@ function test_submit_settings_form(override, submit_form) {
}
function test_change_save_button_state() {
const {$save_button_controls, $save_button_text, $save_button, $discard_button, props} =
createSaveButtons("msg-editing");
$save_button.attr("id", "org-submit-msg-editing");
const {
$save_button_controls,
$save_button_text,
$save_button,
$save_button_header,
$discard_button,
props,
} = createSaveButtons("msg-editing");
$save_button_header.attr("id", "org-msg-editing");
{
settings_org.change_save_button_state($save_button_controls, "unsaved");

View File

@ -994,7 +994,7 @@ export function register_save_discard_widget_handlers(
data.default_code_block_language = code_block_language_value;
break;
}
case "org_join": {
case "join_settings": {
const org_join_restrictions = $("#id_realm_org_join_restrictions").val();
switch (org_join_restrictions) {
case "only_selected_domain":
@ -1082,7 +1082,7 @@ export function register_save_discard_widget_handlers(
// The organization settings system has some coupled
// fields that must be submitted together, which is
// managed by the get_complete_data_for_subsection function.
const [, subsection_id] = /^org-submit-(.*)$/.exec($save_button.attr("id"));
const [, subsection_id] = /^org-(.*)$/.exec($subsection_elem.attr("id"));
const subsection = subsection_id.replace(/-/g, "_");
extra_data = get_complete_data_for_subsection(subsection);
}

View File

@ -1,7 +1,7 @@
<div id="organization-permissions" data-name="organization-permissions" class="settings-section">
<form class="form-horizontal admin-realm-form org-permissions-form">
<div id="org-join" class="settings-subsection-parent">
<div id="org-join-settings" class="settings-subsection-parent">
<div class="subsection-header">
<h3>{{t "Joining the organization" }}</h3>
<i class="fa fa-info-circle settings-info-icon realm_message_retention_tooltip tippy-zulip-tooltip" aria-hidden="true" data-tippy-content="{{t 'Only owners can change these settings.' }}"></i>