diff --git a/.eslintrc.json b/.eslintrc.json index 77f92b4a86..d70a755a9f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -38,6 +38,7 @@ "settings_muting": false, "settings_lab": false, "settings_bots": false, + "settings_sections": false, "settings": false, "resize": false, "loading": false, diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js index 737b84dcf6..0c3093beb9 100644 --- a/static/js/click_handlers.js +++ b/static/js/click_handlers.js @@ -581,6 +581,7 @@ $(function () { } $(".settings-section, .settings-wrapper").removeClass("show"); + settings_sections.load_settings_section(section); $(".settings-section" + sel + ", .settings-wrapper" + sel).addClass("show"); }); diff --git a/static/js/settings.js b/static/js/settings.js index d0f38717c9..e36bc8e4aa 100644 --- a/static/js/settings.js +++ b/static/js/settings.js @@ -66,14 +66,9 @@ function _setup_page() { $(".settings-box").html(settings_tab); - alert_words_ui.set_up_alert_words(); - attachments_ui.set_up_attachments(); - settings_account.set_up(); - settings_display.set_up(); - settings_notifications.set_up(); - settings_bots.set_up(); - settings_muting.set_up(); - settings_lab.set_up(); + // Since we just swapped in a whole new settings widget, we need to + // tell settings_sections nothing is loaded. + settings_sections.reset_sections(); if (tab) { exports.launch_page(tab); diff --git a/static/js/settings_sections.js b/static/js/settings_sections.js new file mode 100644 index 0000000000..c71c7a615a --- /dev/null +++ b/static/js/settings_sections.js @@ -0,0 +1,47 @@ +var settings_sections = (function () { + +var exports = {}; + +var load_func_dict = new Dict(); // section -> function +var is_loaded = new Dict(); // section -> bool + +exports.initialize = function () { + load_func_dict.set('your-account', settings_account.set_up); + load_func_dict.set('display-settings', settings_display.set_up); + load_func_dict.set('notifications', settings_notifications.set_up); + 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_muting.set_up); + load_func_dict.set('zulip-labs', settings_lab.set_up); +}; + +exports.load_settings_section = function (section) { + if (!load_func_dict.has(section)) { + // admin sections don't have loaders yet, and that's ok + return; + } + + if (is_loaded.get(section)) { + // We only load sections once (unless somebody calls + // reset_sections). + return; + } + + var load_func = load_func_dict.get(section); + + // Do the real work here! + load_func(); + is_loaded.set(section, true); +}; + +exports.reset_sections = function () { + is_loaded.clear(); +}; + +return exports; +}()); + +if (typeof module !== 'undefined') { + module.exports = settings_sections; +} diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 090a7621d8..3042e2b812 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -257,6 +257,7 @@ $(function () { activity.initialize(); emoji.initialize(); hotspots.initialize(); + settings_sections.initialize(); }); diff --git a/zproject/settings.py b/zproject/settings.py index e9345b5472..ea96a31207 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -911,6 +911,7 @@ JS_SPECS = { 'js/settings_bots.js', 'js/settings_muting.js', 'js/settings_lab.js', + 'js/settings_sections.js', 'js/settings.js', 'js/admin.js', 'js/tab_bar.js',