2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-03-22 16:09:12 +01:00
|
|
|
import * as browser_history from "./browser_history";
|
2021-02-28 01:01:14 +01:00
|
|
|
import * as keydown_util from "./keydown_util";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as popovers from "./popovers";
|
2021-02-28 01:23:16 +01:00
|
|
|
import * as settings from "./settings";
|
2021-02-28 01:19:36 +01:00
|
|
|
import * as settings_sections from "./settings_sections";
|
2021-02-28 21:33:10 +01:00
|
|
|
import * as ui from "./ui";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-28 01:01:14 +01:00
|
|
|
export let normal_settings;
|
|
|
|
export let org_settings;
|
2021-02-28 00:36:50 +01:00
|
|
|
|
2021-02-28 01:01:14 +01:00
|
|
|
export function mobile_deactivate_section() {
|
2020-06-25 00:51:20 +02:00
|
|
|
const $settings_overlay_container = $("#settings_overlay_container");
|
|
|
|
$settings_overlay_container.find(".right").removeClass("show");
|
|
|
|
$settings_overlay_container.find(".settings-header.mobile").removeClass("slide-left");
|
2021-02-28 01:01:14 +01:00
|
|
|
}
|
2020-06-25 00:51:20 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
function two_column_mode() {
|
|
|
|
return $("#settings_overlay_container").css("--single-column") === undefined;
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:01:14 +01:00
|
|
|
export class SettingsPanelMenu {
|
2020-07-23 02:34:41 +02:00
|
|
|
constructor(opts) {
|
|
|
|
this.main_elem = opts.main_elem;
|
|
|
|
this.hash_prefix = opts.hash_prefix;
|
|
|
|
this.curr_li = this.main_elem.children("li").eq(0);
|
|
|
|
|
|
|
|
this.main_elem.on("click", "li[data-section]", (e) => {
|
|
|
|
const section = $(e.currentTarget).attr("data-section");
|
|
|
|
|
|
|
|
this.activate_section_or_default(section);
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
// You generally want to add logic to activate_section,
|
|
|
|
// not to this click handler.
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2020-06-25 00:51:20 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
show() {
|
|
|
|
this.main_elem.show();
|
|
|
|
const section = this.current_tab();
|
2020-06-25 00:51:20 +02:00
|
|
|
if (two_column_mode()) {
|
2020-08-11 01:47:44 +02:00
|
|
|
// In one column mode want to show the settings list, not the first settings section.
|
2020-07-23 02:34:41 +02:00
|
|
|
this.activate_section_or_default(section);
|
2020-06-24 07:46:43 +02:00
|
|
|
}
|
2020-07-23 02:34:41 +02:00
|
|
|
this.curr_li.trigger("focus");
|
|
|
|
}
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
hide() {
|
|
|
|
this.main_elem.hide();
|
|
|
|
}
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
current_tab() {
|
|
|
|
return this.curr_li.data("section");
|
|
|
|
}
|
2018-06-03 19:12:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
li_for_section(section) {
|
2021-02-03 23:23:32 +01:00
|
|
|
const li = $(`#settings_overlay_container li[data-section='${CSS.escape(section)}']`);
|
2018-12-02 21:00:53 +01:00
|
|
|
return li;
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-12-02 21:00:53 +01:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
set_key_handlers(toggler) {
|
2018-06-03 12:42:43 +02:00
|
|
|
keydown_util.handle({
|
2020-07-23 02:34:41 +02:00
|
|
|
elem: this.main_elem,
|
2018-06-03 12:42:43 +02:00
|
|
|
handlers: {
|
|
|
|
left_arrow: toggler.maybe_go_left,
|
|
|
|
right_arrow: toggler.maybe_go_right,
|
2020-07-23 02:34:41 +02:00
|
|
|
enter_key: () => this.enter_panel(),
|
|
|
|
up_arrow: () => this.prev(),
|
|
|
|
down_arrow: () => this.next(),
|
2018-06-03 12:42:43 +02:00
|
|
|
},
|
|
|
|
});
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-06-03 12:42:43 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
prev() {
|
|
|
|
this.curr_li.prevAll(":visible:first").trigger("focus").trigger("click");
|
2018-06-03 12:42:43 +02:00
|
|
|
return true;
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-06-03 12:42:43 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
next() {
|
|
|
|
this.curr_li.nextAll(":visible:first").trigger("focus").trigger("click");
|
2018-06-03 12:42:43 +02:00
|
|
|
return true;
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-06-03 12:42:43 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
enter_panel() {
|
|
|
|
const panel = this.get_panel();
|
2021-01-23 02:36:54 +01:00
|
|
|
const panel_elem = panel.find("input:visible,button:visible,select:visible").first();
|
2018-06-04 12:52:42 +02:00
|
|
|
|
2020-07-20 21:24:26 +02:00
|
|
|
panel_elem.trigger("focus");
|
2018-06-04 12:52:42 +02:00
|
|
|
return true;
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-06-04 12:52:42 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
activate_section_or_default(section) {
|
2020-07-03 22:20:57 +02:00
|
|
|
popovers.hide_all();
|
2020-06-25 00:51:20 +02:00
|
|
|
if (!section) {
|
|
|
|
// No section is given so we display the default.
|
|
|
|
|
|
|
|
if (two_column_mode()) {
|
|
|
|
// In two column mode we resume to the last active section.
|
2020-07-23 02:34:41 +02:00
|
|
|
section = this.current_tab();
|
2020-06-25 00:51:20 +02:00
|
|
|
} else {
|
|
|
|
// In single column mode we close the active section
|
|
|
|
// so that you always start at the settings list.
|
2021-02-28 01:01:14 +01:00
|
|
|
mobile_deactivate_section();
|
2020-06-25 00:51:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
this.curr_li = this.li_for_section(section);
|
2018-06-03 19:12:11 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
this.main_elem.children("li").removeClass("active");
|
|
|
|
this.curr_li.addClass("active");
|
2018-12-02 17:34:48 +01:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
const settings_section_hash = "#" + this.hash_prefix + section;
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.update(settings_section_hash);
|
2018-06-03 17:59:33 +02:00
|
|
|
|
2020-07-03 18:49:26 +02:00
|
|
|
$(".settings-section").removeClass("show");
|
2018-06-03 17:59:33 +02:00
|
|
|
|
2018-12-08 19:28:26 +01:00
|
|
|
settings_sections.load_settings_section(section);
|
2018-06-03 17:59:33 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
this.get_panel().addClass("show");
|
2018-12-02 21:10:32 +01:00
|
|
|
|
2019-03-01 01:40:05 +01:00
|
|
|
ui.reset_scrollbar($("#settings_content"));
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const $settings_overlay_container = $("#settings_overlay_container");
|
2018-12-02 21:10:32 +01:00
|
|
|
$settings_overlay_container.find(".right").addClass("show");
|
|
|
|
$settings_overlay_container.find(".settings-header.mobile").addClass("slide-left");
|
|
|
|
|
|
|
|
settings.set_settings_header(section);
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
2018-06-04 12:52:42 +02:00
|
|
|
|
2020-07-23 02:34:41 +02:00
|
|
|
get_panel() {
|
|
|
|
const section = this.curr_li.data("section");
|
2021-02-03 23:23:32 +01:00
|
|
|
const sel = `[data-name='${CSS.escape(section)}']`;
|
2020-07-03 18:49:26 +02:00
|
|
|
const panel = $(".settings-section" + sel);
|
2018-06-04 12:52:42 +02:00
|
|
|
return panel;
|
2020-07-23 02:34:41 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2021-02-28 01:01:14 +01:00
|
|
|
export function initialize() {
|
|
|
|
normal_settings = new SettingsPanelMenu({
|
2020-07-15 01:29:15 +02:00
|
|
|
main_elem: $(".normal-settings-list"),
|
2018-06-03 17:59:33 +02:00
|
|
|
hash_prefix: "settings/",
|
2018-06-03 17:29:11 +02:00
|
|
|
});
|
2021-02-28 01:01:14 +01:00
|
|
|
org_settings = new SettingsPanelMenu({
|
2020-07-15 01:29:15 +02:00
|
|
|
main_elem: $(".org-settings-list"),
|
2018-06-03 17:59:33 +02:00
|
|
|
hash_prefix: "organization/",
|
2018-06-03 17:29:11 +02:00
|
|
|
});
|
2021-02-28 01:01:14 +01:00
|
|
|
}
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2021-02-28 01:01:14 +01:00
|
|
|
export function show_normal_settings() {
|
|
|
|
org_settings.hide();
|
|
|
|
normal_settings.show();
|
|
|
|
}
|
2018-06-03 17:29:11 +02:00
|
|
|
|
2021-02-28 01:01:14 +01:00
|
|
|
export function show_org_settings() {
|
|
|
|
normal_settings.hide();
|
|
|
|
org_settings.show();
|
|
|
|
}
|
2018-06-03 12:42:43 +02:00
|
|
|
|
2021-02-28 01:01:14 +01:00
|
|
|
export function set_key_handlers(toggler) {
|
|
|
|
normal_settings.set_key_handlers(toggler);
|
|
|
|
org_settings.set_key_handlers(toggler);
|
|
|
|
}
|