mirror of
https://github.com/zulip/zulip.git
synced 2025-11-17 20:41:46 +00:00
settings: Add functions to discard complete subsection.
This commit adds new functions which will be used to discard changes for all the settings in a subsection when clicking on discard button. This change will help in avoiding code duplication when they will be used to discard changes in a subsection if some other user changed a setting in the same subsection.
This commit is contained in:
@@ -639,6 +639,38 @@ export function discard_realm_default_property_element_changes(elem) {
|
||||
update_dependent_subsettings(property_name);
|
||||
}
|
||||
|
||||
function discard_realm_settings_subsection_changes($subsection) {
|
||||
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
||||
discard_realm_property_element_changes(elem);
|
||||
}
|
||||
const $save_btn_controls = $subsection.find(".save-button-controls");
|
||||
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
||||
}
|
||||
|
||||
export function discard_stream_settings_subsection_changes($subsection, sub) {
|
||||
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
||||
discard_stream_property_element_changes(elem, sub);
|
||||
}
|
||||
const $save_btn_controls = $subsection.find(".save-button-controls");
|
||||
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
||||
}
|
||||
|
||||
export function discard_group_settings_subsection_changes($subsection, group) {
|
||||
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
||||
discard_group_property_element_changes(elem, group);
|
||||
}
|
||||
const $save_btn_controls = $subsection.find(".save-button-controls");
|
||||
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
||||
}
|
||||
|
||||
function discard_realm_default_settings_subsection_changes($subsection) {
|
||||
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
||||
discard_realm_default_property_element_changes(elem);
|
||||
}
|
||||
const $save_btn_controls = $subsection.find(".save-button-controls");
|
||||
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
||||
}
|
||||
|
||||
export function deactivate_organization(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
@@ -872,15 +904,11 @@ export function register_save_discard_widget_handlers(
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const $subsection = $(e.target).closest(".settings-subsection-parent");
|
||||
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
||||
if (for_realm_default_settings) {
|
||||
discard_realm_default_property_element_changes(elem);
|
||||
discard_realm_default_settings_subsection_changes($subsection);
|
||||
} else {
|
||||
discard_realm_property_element_changes(elem);
|
||||
discard_realm_settings_subsection_changes($subsection);
|
||||
}
|
||||
}
|
||||
const $save_btn_controls = $(e.target).closest(".save-button-controls");
|
||||
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
||||
});
|
||||
|
||||
$container.on("click", ".subsection-header .subsection-changes-save button", (e) => {
|
||||
|
||||
@@ -756,12 +756,8 @@ export function initialize() {
|
||||
const sub = sub_store.get(stream_id);
|
||||
|
||||
const $subsection = $(e.target).closest(".settings-subsection-parent");
|
||||
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
||||
settings_org.discard_stream_property_element_changes(elem, sub);
|
||||
}
|
||||
settings_org.discard_stream_settings_subsection_changes($subsection, sub);
|
||||
stream_ui_updates.update_default_stream_and_stream_privacy_state($subsection);
|
||||
const $save_btn_controls = $(e.target).closest(".save-button-controls");
|
||||
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -916,11 +916,7 @@ export function initialize() {
|
||||
const group = user_groups.get_user_group_from_id(group_id);
|
||||
|
||||
const $subsection = $(e.target).closest(".settings-subsection-parent");
|
||||
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
||||
settings_org.discard_group_property_element_changes(elem, group);
|
||||
}
|
||||
const $save_btn_controls = $(e.target).closest(".save-button-controls");
|
||||
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
||||
settings_org.discard_group_settings_subsection_changes($subsection, group);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -444,15 +444,20 @@ function test_discard_changes_button(discard_changes) {
|
||||
);
|
||||
|
||||
const $discard_button_parent = $(".settings-subsection-parent");
|
||||
$discard_button_parent.find = () => [
|
||||
$discard_button_parent.set_find_results(".prop-element", [
|
||||
$allow_edit_history,
|
||||
$msg_edit_limit_setting,
|
||||
$msg_delete_limit_setting,
|
||||
$edit_topic_policy,
|
||||
];
|
||||
]);
|
||||
|
||||
const {$discard_button, props} = createSaveButtons("msg-editing");
|
||||
$discard_button.closest = (selector) => $(selector);
|
||||
const {$discard_button, $save_button_controls, props} = createSaveButtons("msg-editing");
|
||||
$discard_button.closest = (selector) => {
|
||||
assert.equal(selector, ".settings-subsection-parent");
|
||||
return $discard_button_parent;
|
||||
};
|
||||
|
||||
$discard_button_parent.set_find_results(".save-button-controls", $save_button_controls);
|
||||
|
||||
discard_changes(ev);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user