mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	This changes the method of rendering list of alert words in DOM,
earlier it was rendered using 'for' loop over the array of alert_words
which is now changed to render using ListWidget, which gets a array
of objects from get_word_list() in alert_words.js.
The use of ListWidget helps to define a parent_container and $container
in table-body of alert-words-table using which we can now apply sorting over
alert words with the help of handle_sort() function in list_widget.js
Changed the method of adding alert_word_settings_item row in table body
through {{#with}} loop because of rendering through ListWidget, which was done
earlier using for loop over each alert-word in while rendering the list.
this commit also mocks template of render_alert_word_item
while mocking ListWidget.create() function in render_alert_words_ui().
and checks that ListWidget.create() is not called when variable `loaded`
is set as false.
Fixes #21142.
		
	
		
			
				
	
	
		
			121 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			121 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import * as alert_words_ui from "./alert_words_ui";
 | 
						|
import * as attachments_ui from "./attachments_ui";
 | 
						|
import * as blueslip from "./blueslip";
 | 
						|
import * as settings_account from "./settings_account";
 | 
						|
import * as settings_bots from "./settings_bots";
 | 
						|
import * as settings_display from "./settings_display";
 | 
						|
import * as settings_emoji from "./settings_emoji";
 | 
						|
import * as settings_exports from "./settings_exports";
 | 
						|
import * as settings_invites from "./settings_invites";
 | 
						|
import * as settings_linkifiers from "./settings_linkifiers";
 | 
						|
import * as settings_muted_topics from "./settings_muted_topics";
 | 
						|
import * as settings_muted_users from "./settings_muted_users";
 | 
						|
import * as settings_notifications from "./settings_notifications";
 | 
						|
import * as settings_org from "./settings_org";
 | 
						|
import * as settings_playgrounds from "./settings_playgrounds";
 | 
						|
import * as settings_profile_fields from "./settings_profile_fields";
 | 
						|
import * as settings_realm_user_settings_defaults from "./settings_realm_user_settings_defaults";
 | 
						|
import * as settings_streams from "./settings_streams";
 | 
						|
import * as settings_user_groups from "./settings_user_groups";
 | 
						|
import * as settings_users from "./settings_users";
 | 
						|
 | 
						|
const load_func_dict = new Map(); // group -> function
 | 
						|
const loaded_groups = new Set();
 | 
						|
 | 
						|
export function get_group(section) {
 | 
						|
    // Sometimes several sections all share the same code.
 | 
						|
 | 
						|
    switch (section) {
 | 
						|
        case "organization-profile":
 | 
						|
        case "organization-settings":
 | 
						|
        case "organization-permissions":
 | 
						|
        case "auth-methods":
 | 
						|
            return "org_misc";
 | 
						|
 | 
						|
        case "bot-list-admin":
 | 
						|
            return "org_bots";
 | 
						|
 | 
						|
        case "user-list-admin":
 | 
						|
        case "deactivated-users-admin":
 | 
						|
            return "org_users";
 | 
						|
 | 
						|
        case "profile":
 | 
						|
        case "account-and-privacy":
 | 
						|
            return "your-account";
 | 
						|
 | 
						|
        default:
 | 
						|
            return section;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
export function initialize() {
 | 
						|
    // personal
 | 
						|
    load_func_dict.set("your-account", settings_account.set_up);
 | 
						|
    load_func_dict.set("display-settings", () => {
 | 
						|
        settings_display.set_up(settings_display.user_settings_panel);
 | 
						|
    });
 | 
						|
    load_func_dict.set("notifications", () => {
 | 
						|
        settings_notifications.set_up(settings_notifications.user_settings_panel);
 | 
						|
    });
 | 
						|
    load_func_dict.set("your-bots", settings_bots.set_up);
 | 
						|
    load_func_dict.set("alert-words", alert_words_ui.set_up_alert_words);
 | 
						|
    load_func_dict.set("uploaded-files", attachments_ui.set_up_attachments);
 | 
						|
    load_func_dict.set("muted-topics", settings_muted_topics.set_up);
 | 
						|
    load_func_dict.set("muted-users", settings_muted_users.set_up);
 | 
						|
 | 
						|
    // org
 | 
						|
    load_func_dict.set("org_misc", settings_org.set_up);
 | 
						|
    load_func_dict.set("org_bots", settings_users.set_up_bots);
 | 
						|
    load_func_dict.set("org_users", settings_users.set_up_humans);
 | 
						|
    load_func_dict.set("emoji-settings", settings_emoji.set_up);
 | 
						|
    load_func_dict.set("default-streams-list", settings_streams.set_up);
 | 
						|
    load_func_dict.set("linkifier-settings", settings_linkifiers.set_up);
 | 
						|
    load_func_dict.set("playground-settings", settings_playgrounds.set_up);
 | 
						|
    load_func_dict.set("invites-list-admin", settings_invites.set_up);
 | 
						|
    load_func_dict.set("user-groups-admin", settings_user_groups.set_up);
 | 
						|
    load_func_dict.set("profile-field-settings", settings_profile_fields.set_up);
 | 
						|
    load_func_dict.set("data-exports-admin", settings_exports.set_up);
 | 
						|
    load_func_dict.set(
 | 
						|
        "organization-level-user-defaults",
 | 
						|
        settings_realm_user_settings_defaults.set_up,
 | 
						|
    );
 | 
						|
}
 | 
						|
 | 
						|
export function load_settings_section(section) {
 | 
						|
    const group = get_group(section);
 | 
						|
 | 
						|
    if (!load_func_dict.has(group)) {
 | 
						|
        blueslip.error("Unknown section " + section);
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    if (loaded_groups.has(group)) {
 | 
						|
        // We only load groups once (unless somebody calls
 | 
						|
        // reset_sections).
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    const load_func = load_func_dict.get(group);
 | 
						|
 | 
						|
    // Do the real work here!
 | 
						|
    load_func();
 | 
						|
    loaded_groups.add(group);
 | 
						|
}
 | 
						|
 | 
						|
export function reset_sections() {
 | 
						|
    loaded_groups.clear();
 | 
						|
    settings_emoji.reset();
 | 
						|
    settings_exports.reset();
 | 
						|
    settings_linkifiers.reset();
 | 
						|
    settings_playgrounds.reset();
 | 
						|
    settings_invites.reset();
 | 
						|
    settings_org.reset();
 | 
						|
    settings_profile_fields.reset();
 | 
						|
    settings_streams.reset();
 | 
						|
    settings_user_groups.reset();
 | 
						|
    settings_muted_topics.reset();
 | 
						|
    settings_muted_users.reset();
 | 
						|
    alert_words_ui.reset();
 | 
						|
    // settings_users doesn't need a reset()
 | 
						|
}
 |