2018-06-03 17:29:11 +02:00
|
|
|
var settings_panel_menu = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
exports.make_menu = function (opts) {
|
|
|
|
var main_elem = opts.main_elem;
|
2018-06-03 17:59:33 +02:00
|
|
|
var hash_prefix = opts.hash_prefix;
|
|
|
|
var load_section = opts.load_section;
|
2018-06-03 19:12:11 +02:00
|
|
|
var curr_li = main_elem.children('li').eq(0);
|
2018-06-03 17:29:11 +02:00
|
|
|
|
|
|
|
var self = {};
|
|
|
|
|
|
|
|
self.show = function () {
|
|
|
|
main_elem.show();
|
2018-12-02 21:00:53 +01:00
|
|
|
var section = self.current_tab();
|
|
|
|
self.activate_section(section);
|
2018-06-03 12:42:43 +02:00
|
|
|
curr_li.focus();
|
2018-06-03 17:29:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
self.hide = function () {
|
|
|
|
main_elem.hide();
|
|
|
|
};
|
|
|
|
|
2018-06-03 19:12:11 +02:00
|
|
|
self.current_tab = function () {
|
|
|
|
return curr_li.data('section');
|
|
|
|
};
|
|
|
|
|
2018-12-02 21:00:53 +01:00
|
|
|
self.li_for_section = function (section) {
|
|
|
|
var li = $("#settings_overlay_container li[data-section='" + section + "']");
|
|
|
|
return li;
|
|
|
|
};
|
|
|
|
|
2018-06-03 12:42:43 +02:00
|
|
|
self.set_key_handlers = function (toggler) {
|
|
|
|
keydown_util.handle({
|
|
|
|
elem: main_elem,
|
|
|
|
handlers: {
|
|
|
|
left_arrow: toggler.maybe_go_left,
|
|
|
|
right_arrow: toggler.maybe_go_right,
|
2018-06-04 12:52:42 +02:00
|
|
|
enter_key: self.enter_panel,
|
2018-06-03 12:42:43 +02:00
|
|
|
up_arrow: self.prev,
|
|
|
|
down_arrow: self.next,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
self.prev = function () {
|
|
|
|
curr_li.prev().focus().click();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
self.next = function () {
|
|
|
|
curr_li.next().focus().click();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2018-06-04 12:52:42 +02:00
|
|
|
self.enter_panel = function () {
|
|
|
|
var panel = self.get_panel();
|
|
|
|
var sel = 'input:visible:first,button:visible:first,select:visible:first';
|
|
|
|
var panel_elem = panel.find(sel).first();
|
|
|
|
|
|
|
|
panel_elem.focus();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2018-12-02 21:00:53 +01:00
|
|
|
self.activate_section = function (section) {
|
|
|
|
curr_li = self.li_for_section(section);
|
2018-06-03 19:12:11 +02:00
|
|
|
|
2018-06-03 17:59:33 +02:00
|
|
|
main_elem.children("li").removeClass("active no-border");
|
2018-12-02 21:00:53 +01:00
|
|
|
curr_li.addClass("active");
|
|
|
|
curr_li.prev().addClass("no-border");
|
2018-12-02 17:34:48 +01:00
|
|
|
|
|
|
|
var settings_section_hash = hash_prefix + section;
|
|
|
|
hashchange.update_browser_history(settings_section_hash);
|
2018-06-03 17:59:33 +02:00
|
|
|
|
|
|
|
$(".settings-section, .settings-wrapper").removeClass("show");
|
|
|
|
|
|
|
|
ui.update_scrollbar($("#settings_content"));
|
|
|
|
|
|
|
|
load_section(section);
|
|
|
|
|
2018-06-04 12:52:42 +02:00
|
|
|
self.get_panel().addClass('show');
|
2018-12-02 21:10:32 +01:00
|
|
|
|
|
|
|
var $settings_overlay_container = $("#settings_overlay_container");
|
|
|
|
$settings_overlay_container.find(".right").addClass("show");
|
|
|
|
$settings_overlay_container.find(".settings-header.mobile").addClass("slide-left");
|
|
|
|
|
|
|
|
settings.set_settings_header(section);
|
2018-06-04 12:52:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
self.get_panel = function () {
|
|
|
|
var section = curr_li.data('section');
|
2018-06-03 17:59:33 +02:00
|
|
|
var sel = "[data-name='" + section + "']";
|
2018-06-04 12:52:42 +02:00
|
|
|
var panel = $(".settings-section" + sel + ", .settings-wrapper" + sel);
|
|
|
|
return panel;
|
2018-06-03 17:59:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
main_elem.on("click", "li[data-section]", function (e) {
|
2018-12-02 21:00:53 +01:00
|
|
|
var section = $(this).attr('data-section');
|
|
|
|
|
|
|
|
self.activate_section(section);
|
2018-06-03 17:59:33 +02:00
|
|
|
|
2018-12-02 21:10:32 +01:00
|
|
|
// You generally want to add logic to activate_section,
|
|
|
|
// not to this click handler.
|
2018-06-26 13:26:06 +02:00
|
|
|
|
2018-06-03 17:59:33 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2018-06-03 17:29:11 +02:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.initialize = function () {
|
|
|
|
exports.normal_settings = exports.make_menu({
|
|
|
|
main_elem: $('.normal-settings-list'),
|
2018-06-03 17:59:33 +02:00
|
|
|
hash_prefix: "settings/",
|
|
|
|
load_section: function (section) {
|
|
|
|
settings_sections.load_settings_section(section);
|
|
|
|
},
|
2018-06-03 17:29:11 +02:00
|
|
|
});
|
|
|
|
exports.org_settings = exports.make_menu({
|
|
|
|
main_elem: $('.org-settings-list'),
|
2018-06-03 17:59:33 +02:00
|
|
|
hash_prefix: "organization/",
|
|
|
|
load_section: function (section) {
|
|
|
|
admin_sections.load_admin_section(section);
|
|
|
|
},
|
2018-06-03 17:29:11 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2018-06-03 12:42:43 +02:00
|
|
|
exports.set_key_handlers = function (toggler) {
|
|
|
|
exports.normal_settings.set_key_handlers(toggler);
|
|
|
|
exports.org_settings.set_key_handlers(toggler);
|
|
|
|
};
|
|
|
|
|
2018-06-03 17:29:11 +02:00
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = settings_panel_menu;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
|
|
|
|
window.settings_panel_menu = settings_panel_menu;
|