diff --git a/.eslintrc.json b/.eslintrc.json index 1adc90698f..f0ba759b28 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -49,6 +49,7 @@ "user_groups": false, "navigate": false, "toMarkdown": false, + "settings_panel_menu": false, "settings_toggle": false, "settings_account": false, "settings_display": false, diff --git a/static/js/settings_panel_menu.js b/static/js/settings_panel_menu.js new file mode 100644 index 0000000000..e95787973a --- /dev/null +++ b/static/js/settings_panel_menu.js @@ -0,0 +1,50 @@ +var settings_panel_menu = (function () { + +var exports = {}; + +exports.make_menu = function (opts) { + var main_elem = opts.main_elem; + + var self = {}; + + self.goto_top = function () { + main_elem.children('li').eq(0).click(); + }; + + self.show = function () { + main_elem.show(); + }; + + self.hide = function () { + main_elem.hide(); + }; + + return self; +}; + +exports.initialize = function () { + exports.normal_settings = exports.make_menu({ + main_elem: $('.normal-settings-list'), + }); + exports.org_settings = exports.make_menu({ + main_elem: $('.org-settings-list'), + }); +}; + +exports.show_normal_settings = function () { + exports.org_settings.hide(); + exports.normal_settings.show(); +}; + +exports.show_org_settings = function () { + exports.normal_settings.hide(); + exports.org_settings.show(); +}; + +return exports; + +}()); + +if (typeof module !== 'undefined') { + module.exports = settings_panel_menu; +} diff --git a/static/js/settings_toggle.js b/static/js/settings_toggle.js index 2792f63041..9df21f1313 100644 --- a/static/js/settings_toggle.js +++ b/static/js/settings_toggle.js @@ -17,20 +17,15 @@ exports.initialize = function () { { label: i18n.t("Organization"), key: "organization" }, ], callback: function (name, key, payload) { - var normal_list = $('.normal-settings-list'); - var org_list = $('.org-settings-list'); - if (key === "organization") { - normal_list.hide(); - org_list.show(); + settings_panel_menu.show_org_settings(); if (!payload.dont_switch_tab) { - $("li[data-section='organization-profile']").click(); + settings_panel_menu.org_settings.goto_top(); } } else { - org_list.hide(); - normal_list.show(); + settings_panel_menu.show_normal_settings(); if (!payload.dont_switch_tab) { - $("li[data-section='your-account']").click(); + settings_panel_menu.normal_settings.goto_top(); } } }, diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 0d3e673e63..6a078df052 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -307,6 +307,7 @@ $(function () { tutorial.initialize(); notifications.initialize(); gear_menu.initialize(); + settings_panel_menu.initialize(); settings_sections.initialize(); settings_toggle.initialize(); hashchange.initialize(); diff --git a/zproject/settings.py b/zproject/settings.py index a51f71c534..faf72c0003 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -993,6 +993,7 @@ JS_SPECS = { 'js/ui_util.js', 'js/pointer.js', 'js/click_handlers.js', + 'js/settings_panel_menu.js', 'js/settings_toggle.js', 'js/scroll_bar.js', 'js/gear_menu.js',