mirror of https://github.com/zulip/zulip.git
settings: Eliminate admin_sections module.
We move all of its logic into settings_sections. Note that this is slightly more than a refactor. We are slightly more aggressive about resetting sections. For example, if you go into Settings, then exit the overlay, then go into Manage Organization, we will now reset sections for both groups.
This commit is contained in:
parent
0543e8fbc1
commit
7a44d99b96
|
@ -26,7 +26,6 @@
|
|||
"_": false,
|
||||
"activity": false,
|
||||
"admin": false,
|
||||
"admin_sections": false,
|
||||
"alert_words": false,
|
||||
"alert_words_ui": false,
|
||||
"attachments_ui": false,
|
||||
|
|
|
@ -69,16 +69,13 @@ exports.build_page = function () {
|
|||
$("#id_realm_email_address_visibility").val(page_params.realm_email_address_visibility);
|
||||
|
||||
$("#id_realm_default_language").val(page_params.realm_default_language);
|
||||
|
||||
// Since we just swapped in a whole new page, we need to
|
||||
// tell admin_sections nothing is loaded.
|
||||
admin_sections.reset_sections();
|
||||
};
|
||||
|
||||
|
||||
exports.launch = function (section) {
|
||||
settings.build_page();
|
||||
exports.build_page();
|
||||
settings_sections.reset_sections();
|
||||
|
||||
overlays.open_settings();
|
||||
settings_panel_menu.org_settings.activate_section(section);
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
var admin_sections = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
var is_loaded = new Dict(); // section -> bool
|
||||
|
||||
exports.load_admin_section = function (name) {
|
||||
var section;
|
||||
|
||||
switch (name) {
|
||||
case 'organization-profile':
|
||||
case 'organization-settings':
|
||||
case 'organization-permissions':
|
||||
case 'auth-methods':
|
||||
section = 'org';
|
||||
break;
|
||||
case 'emoji-settings':
|
||||
section = 'emoji';
|
||||
break;
|
||||
case 'bot-list-admin':
|
||||
case 'user-list-admin':
|
||||
case 'deactivated-users-admin':
|
||||
section = 'users';
|
||||
break;
|
||||
case 'default-streams-list':
|
||||
section = 'streams';
|
||||
break;
|
||||
case 'filter-settings':
|
||||
section = 'filters';
|
||||
break;
|
||||
case 'invites-list-admin':
|
||||
section = 'invites';
|
||||
break;
|
||||
case 'user-groups-admin':
|
||||
section = 'user-groups';
|
||||
break;
|
||||
case 'profile-field-settings':
|
||||
section = 'profile-fields';
|
||||
break;
|
||||
default:
|
||||
blueslip.error('Unknown admin id ' + name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_loaded.get(section)) {
|
||||
// We only load sections once (unless somebody calls
|
||||
// reset_sections).
|
||||
return;
|
||||
}
|
||||
|
||||
switch (section) {
|
||||
case 'org':
|
||||
settings_org.set_up();
|
||||
break;
|
||||
case 'emoji':
|
||||
settings_emoji.set_up();
|
||||
break;
|
||||
case 'users':
|
||||
settings_users.set_up();
|
||||
break;
|
||||
case 'streams':
|
||||
settings_streams.set_up();
|
||||
break;
|
||||
case 'filters':
|
||||
settings_filters.set_up();
|
||||
break;
|
||||
case 'invites':
|
||||
settings_invites.set_up();
|
||||
break;
|
||||
case 'user-groups':
|
||||
settings_user_groups.set_up();
|
||||
break;
|
||||
case 'profile-fields':
|
||||
settings_profile_fields.set_up();
|
||||
break;
|
||||
default:
|
||||
blueslip.error('programming error for section ' + section);
|
||||
return;
|
||||
}
|
||||
|
||||
is_loaded.set(section, true);
|
||||
};
|
||||
|
||||
exports.reset_sections = function () {
|
||||
is_loaded.clear();
|
||||
settings_org.reset();
|
||||
settings_emoji.reset();
|
||||
settings_users.reset();
|
||||
settings_streams.reset();
|
||||
settings_filters.reset();
|
||||
settings_invites.reset();
|
||||
settings_user_groups.reset();
|
||||
settings_profile_fields.reset();
|
||||
};
|
||||
|
||||
return exports;
|
||||
}());
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = admin_sections;
|
||||
}
|
||||
window.admin_sections = admin_sections;
|
|
@ -183,7 +183,6 @@ import "js/settings_invites.js";
|
|||
import "js/settings_user_groups.js";
|
||||
import "js/settings_profile_fields.js";
|
||||
import "js/settings.js";
|
||||
import "js/admin_sections.js";
|
||||
import "js/admin.js";
|
||||
import "js/tab_bar.js";
|
||||
import "js/emoji.js";
|
||||
|
|
|
@ -135,15 +135,12 @@ exports.build_page = function () {
|
|||
});
|
||||
|
||||
$(".settings-box").html(rendered_settings_tab);
|
||||
|
||||
// Since we just swapped in a whole new settings widget, we need to
|
||||
// tell settings_sections nothing is loaded.
|
||||
settings_sections.reset_sections();
|
||||
};
|
||||
|
||||
exports.launch = function (section) {
|
||||
exports.build_page();
|
||||
admin.build_page();
|
||||
settings_sections.reset_sections();
|
||||
|
||||
overlays.open_settings();
|
||||
settings_panel_menu.normal_settings.activate_section(section);
|
||||
|
|
|
@ -5,7 +5,6 @@ var exports = {};
|
|||
exports.make_menu = function (opts) {
|
||||
var main_elem = opts.main_elem;
|
||||
var hash_prefix = opts.hash_prefix;
|
||||
var load_section = opts.load_section;
|
||||
var curr_li = main_elem.children('li').eq(0);
|
||||
|
||||
var self = {};
|
||||
|
@ -76,7 +75,7 @@ exports.make_menu = function (opts) {
|
|||
|
||||
ui.update_scrollbar($("#settings_content"));
|
||||
|
||||
load_section(section);
|
||||
settings_sections.load_settings_section(section);
|
||||
|
||||
self.get_panel().addClass('show');
|
||||
|
||||
|
@ -112,16 +111,10 @@ exports.initialize = function () {
|
|||
exports.normal_settings = exports.make_menu({
|
||||
main_elem: $('.normal-settings-list'),
|
||||
hash_prefix: "settings/",
|
||||
load_section: function (section) {
|
||||
settings_sections.load_settings_section(section);
|
||||
},
|
||||
});
|
||||
exports.org_settings = exports.make_menu({
|
||||
main_elem: $('.org-settings-list'),
|
||||
hash_prefix: "organization/",
|
||||
load_section: function (section) {
|
||||
admin_sections.load_admin_section(section);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -2,10 +2,31 @@ var settings_sections = (function () {
|
|||
|
||||
var exports = {};
|
||||
|
||||
var load_func_dict = new Dict(); // section -> function
|
||||
var is_loaded = new Dict(); // section -> bool
|
||||
var load_func_dict = new Dict(); // group -> function
|
||||
var is_loaded = new Dict(); // group -> bool
|
||||
|
||||
exports.get_group = function (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':
|
||||
case 'user-list-admin':
|
||||
case 'deactivated-users-admin':
|
||||
return 'org_users';
|
||||
|
||||
default:
|
||||
return section;
|
||||
}
|
||||
};
|
||||
|
||||
exports.initialize = function () {
|
||||
// personal
|
||||
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);
|
||||
|
@ -13,29 +34,49 @@ exports.initialize = function () {
|
|||
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);
|
||||
|
||||
// org
|
||||
load_func_dict.set('org_misc', settings_org.set_up);
|
||||
load_func_dict.set('org_users', settings_users.set_up);
|
||||
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('filter-settings', settings_filters.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);
|
||||
};
|
||||
|
||||
exports.load_settings_section = function (section) {
|
||||
if (!load_func_dict.has(section)) {
|
||||
var group = exports.get_group(section);
|
||||
|
||||
if (!load_func_dict.has(group)) {
|
||||
blueslip.error('Unknown section ' + section);
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_loaded.get(section)) {
|
||||
// We only load sections once (unless somebody calls
|
||||
if (is_loaded.get(group)) {
|
||||
// We only load groups once (unless somebody calls
|
||||
// reset_sections).
|
||||
return;
|
||||
}
|
||||
|
||||
var load_func = load_func_dict.get(section);
|
||||
var load_func = load_func_dict.get(group);
|
||||
|
||||
// Do the real work here!
|
||||
load_func();
|
||||
is_loaded.set(section, true);
|
||||
is_loaded.set(group, true);
|
||||
};
|
||||
|
||||
exports.reset_sections = function () {
|
||||
is_loaded.clear();
|
||||
settings_emoji.reset();
|
||||
settings_filters.reset();
|
||||
settings_invites.reset();
|
||||
settings_org.reset();
|
||||
settings_profile_fields.reset();
|
||||
settings_streams.reset();
|
||||
settings_user_groups.reset();
|
||||
settings_users.reset();
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
|
Loading…
Reference in New Issue