mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	settings: Update save discard buttons when live-updating.
This commit adds code to hide save discard buttons and discard the changes if another user changed a setting in the same subsection.
This commit is contained in:
		@@ -663,7 +663,7 @@ export function discard_group_settings_subsection_changes($subsection, group) {
 | 
				
			|||||||
    settings_components.change_save_button_state($save_btn_controls, "discarded");
 | 
					    settings_components.change_save_button_state($save_btn_controls, "discarded");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function discard_realm_default_settings_subsection_changes($subsection) {
 | 
					export function discard_realm_default_settings_subsection_changes($subsection) {
 | 
				
			||||||
    for (const elem of settings_components.get_subsection_property_elements($subsection)) {
 | 
					    for (const elem of settings_components.get_subsection_property_elements($subsection)) {
 | 
				
			||||||
        discard_realm_default_property_element_changes(elem);
 | 
					        discard_realm_default_property_element_changes(elem);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -710,7 +710,12 @@ export function sync_realm_settings(property) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    const $element = $(`#id_realm_${CSS.escape(property)}`);
 | 
					    const $element = $(`#id_realm_${CSS.escape(property)}`);
 | 
				
			||||||
    if ($element.length) {
 | 
					    if ($element.length) {
 | 
				
			||||||
 | 
					        const $subsection = $element.closest(".settings-subsection-parent");
 | 
				
			||||||
 | 
					        if ($subsection.find(".save-button-controls").hasClass("hide")) {
 | 
				
			||||||
            discard_realm_property_element_changes($element);
 | 
					            discard_realm_property_element_changes($element);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            discard_realm_settings_subsection_changes($subsection);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,7 +34,12 @@ export function update_page(property) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const $element = $(`#realm_${CSS.escape(property)}`);
 | 
					    const $element = $(`#realm_${CSS.escape(property)}`);
 | 
				
			||||||
    if ($element.length) {
 | 
					    if ($element.length) {
 | 
				
			||||||
 | 
					        const $subsection = $element.closest(".settings-subsection-parent");
 | 
				
			||||||
 | 
					        if ($subsection.find(".save-button-controls").hasClass("hide")) {
 | 
				
			||||||
            settings_org.discard_realm_default_property_element_changes($element[0]);
 | 
					            settings_org.discard_realm_default_property_element_changes($element[0]);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            settings_org.discard_realm_default_settings_subsection_changes($subsection);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -288,10 +288,17 @@ function test_extract_property_name() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function test_sync_realm_settings() {
 | 
					function test_sync_realm_settings() {
 | 
				
			||||||
 | 
					    const $subsection_stub = $.create("org-subsection-stub");
 | 
				
			||||||
 | 
					    $subsection_stub.set_find_results(
 | 
				
			||||||
 | 
					        ".save-button-controls",
 | 
				
			||||||
 | 
					        $.create("save-button-controls-stub").addClass("hide"),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        /* Test invalid settings property sync */
 | 
					        /* Test invalid settings property sync */
 | 
				
			||||||
        const $property_elem = $("#id_realm_invalid_settings_property");
 | 
					        const $property_elem = $("#id_realm_invalid_settings_property");
 | 
				
			||||||
        $property_elem.attr("id", "id_realm_invalid_settings_property");
 | 
					        $property_elem.attr("id", "id_realm_invalid_settings_property");
 | 
				
			||||||
 | 
					        $property_elem.closest = () => $subsection_stub;
 | 
				
			||||||
        $property_elem.length = 1;
 | 
					        $property_elem.length = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        blueslip.expect("error", "Element refers to unknown property");
 | 
					        blueslip.expect("error", "Element refers to unknown property");
 | 
				
			||||||
@@ -302,6 +309,7 @@ function test_sync_realm_settings() {
 | 
				
			|||||||
        const $property_elem = $(`#id_realm_${CSS.escape(property_name)}`);
 | 
					        const $property_elem = $(`#id_realm_${CSS.escape(property_name)}`);
 | 
				
			||||||
        $property_elem.length = 1;
 | 
					        $property_elem.length = 1;
 | 
				
			||||||
        $property_elem.attr("id", `id_realm_${CSS.escape(property_name)}`);
 | 
					        $property_elem.attr("id", `id_realm_${CSS.escape(property_name)}`);
 | 
				
			||||||
 | 
					        $property_elem.closest = () => $subsection_stub;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Each policy is initialized to 'by_members' and then all the values are tested
 | 
					        /* Each policy is initialized to 'by_members' and then all the values are tested
 | 
				
			||||||
        in the following order - by_admins_only, by_moderators_only, by_full_members,
 | 
					        in the following order - by_admins_only, by_moderators_only, by_full_members,
 | 
				
			||||||
@@ -328,6 +336,7 @@ function test_sync_realm_settings() {
 | 
				
			|||||||
        $property_dropdown_elem.length = 1;
 | 
					        $property_dropdown_elem.length = 1;
 | 
				
			||||||
        $property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
 | 
					        $property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
 | 
				
			||||||
        $property_dropdown_elem.attr("id", "id_realm_message_content_edit_limit_seconds");
 | 
					        $property_dropdown_elem.attr("id", "id_realm_message_content_edit_limit_seconds");
 | 
				
			||||||
 | 
					        $property_dropdown_elem.closest = () => $subsection_stub;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        realm.realm_message_content_edit_limit_seconds = 120;
 | 
					        realm.realm_message_content_edit_limit_seconds = 120;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -351,6 +360,7 @@ function test_sync_realm_settings() {
 | 
				
			|||||||
        const $property_elem = $("#id_realm_org_join_restrictions");
 | 
					        const $property_elem = $("#id_realm_org_join_restrictions");
 | 
				
			||||||
        $property_elem.length = 1;
 | 
					        $property_elem.length = 1;
 | 
				
			||||||
        $property_elem.attr("id", "id_realm_org_join_restrictions");
 | 
					        $property_elem.attr("id", "id_realm_org_join_restrictions");
 | 
				
			||||||
 | 
					        $property_elem.closest = () => $subsection_stub;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        realm.realm_emails_restricted_to_domains = true;
 | 
					        realm.realm_emails_restricted_to_domains = true;
 | 
				
			||||||
        realm.realm_disallow_disposable_email_addresses = false;
 | 
					        realm.realm_disallow_disposable_email_addresses = false;
 | 
				
			||||||
@@ -367,6 +377,27 @@ function test_sync_realm_settings() {
 | 
				
			|||||||
        settings_org.sync_realm_settings("emails_restricted_to_domains");
 | 
					        settings_org.sync_realm_settings("emails_restricted_to_domains");
 | 
				
			||||||
        assert.equal($("#id_realm_org_join_restrictions").val(), "no_restriction");
 | 
					        assert.equal($("#id_realm_org_join_restrictions").val(), "no_restriction");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // Test hiding save-discard buttons on live-updating.
 | 
				
			||||||
 | 
					        const $property_elem = $("#id_realm_invite_to_realm_policy");
 | 
				
			||||||
 | 
					        $property_elem.length = 1;
 | 
				
			||||||
 | 
					        $property_elem.attr("id", "id_realm_invite_to_realm_policy");
 | 
				
			||||||
 | 
					        $property_elem.closest = () => $subsection_stub;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const save_button_stubs = createSaveButtons("subsection-stub");
 | 
				
			||||||
 | 
					        $subsection_stub.set_find_results(
 | 
				
			||||||
 | 
					            ".save-button-controls",
 | 
				
			||||||
 | 
					            save_button_stubs.$save_button_controls,
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        $property_elem.val(settings_config.common_policy_values.by_admins_only.code);
 | 
				
			||||||
 | 
					        realm.realm_invite_to_realm_policy = settings_config.common_policy_values.by_members.code;
 | 
				
			||||||
 | 
					        save_button_stubs.$save_button_controls.removeClass("hide");
 | 
				
			||||||
 | 
					        $subsection_stub.set_find_results(".prop-element", [$property_elem]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        settings_org.sync_realm_settings("invite_to_realm_policy");
 | 
				
			||||||
 | 
					        assert.equal(save_button_stubs.props.hidden, true);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function test_parse_time_limit() {
 | 
					function test_parse_time_limit() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user