2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-06-14 12:38:43 +02:00
|
|
|
import render_gear_menu from "../templates/gear_menu.hbs";
|
|
|
|
|
2021-02-28 01:07:47 +01:00
|
|
|
import * as hashchange from "./hashchange";
|
2021-04-13 06:51:54 +02:00
|
|
|
import {$t} from "./i18n";
|
2021-02-28 01:02:12 +01:00
|
|
|
import * as message_viewport from "./message_viewport";
|
2021-02-28 01:05:26 +01:00
|
|
|
import * as navigate from "./navigate";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-07-08 17:37:18 +02:00
|
|
|
import * as settings_data from "./settings_data";
|
2021-02-28 00:42:00 +01:00
|
|
|
|
2018-08-29 19:50:12 +02:00
|
|
|
/*
|
|
|
|
For various historical reasons there isn't one
|
|
|
|
single chunk of code that really makes our gear
|
|
|
|
menu function. In this comment I try to help
|
|
|
|
you know where to look for relevant code.
|
|
|
|
|
|
|
|
The module that you're reading now doesn't
|
2020-12-20 13:03:32 +01:00
|
|
|
actually do much of the work.
|
2018-08-29 19:50:12 +02:00
|
|
|
|
|
|
|
Our gear menu has these choices:
|
|
|
|
|
|
|
|
=================
|
|
|
|
hash: Manage streams
|
|
|
|
hash: Settings
|
|
|
|
hash: Organization settings
|
2021-05-12 16:56:51 +02:00
|
|
|
link: Usage statistics
|
2018-08-29 19:50:12 +02:00
|
|
|
---
|
|
|
|
link: Help center
|
|
|
|
info: Keyboard shortcuts
|
|
|
|
info: Message formatting
|
|
|
|
info: Search operators
|
2021-02-09 11:16:52 +01:00
|
|
|
hash: About Zulip
|
2018-08-29 19:50:12 +02:00
|
|
|
---
|
|
|
|
link: Desktop & mobile apps
|
|
|
|
link: Integrations
|
|
|
|
link: API documentation
|
2021-05-12 16:56:51 +02:00
|
|
|
link: Sponsor Zulip
|
|
|
|
link: Plans and pricing
|
2018-08-29 19:50:12 +02:00
|
|
|
---
|
|
|
|
hash: Invite users
|
|
|
|
---
|
|
|
|
misc: Logout
|
|
|
|
=================
|
|
|
|
|
|
|
|
Depending on settings, there may also be choices
|
|
|
|
like "Feedback" or "Debug".
|
|
|
|
|
|
|
|
The menu items get built in a server-side template called
|
|
|
|
templates/zerver/app/navbar.html. Each item is
|
|
|
|
an HTML anchor tag with a "role" of "menuitem".
|
|
|
|
|
|
|
|
The menu itself has the selector
|
|
|
|
"settings-dropdown".
|
|
|
|
|
|
|
|
The items with the prefix of "hash:" are in-page
|
|
|
|
links:
|
|
|
|
|
|
|
|
#streams
|
|
|
|
#settings
|
|
|
|
#organization
|
2021-02-09 11:16:52 +01:00
|
|
|
#about-zulip
|
2018-08-29 19:50:12 +02:00
|
|
|
#invite
|
|
|
|
|
|
|
|
When you click on the links there is a function
|
|
|
|
called hashchanged() in static/js/hashchange.js
|
2021-05-20 01:50:32 +02:00
|
|
|
that gets invoked. (We register this as a listener
|
|
|
|
for the hashchange event.) This function then
|
2018-08-29 19:50:12 +02:00
|
|
|
launches the appropriate modal for each menu item.
|
|
|
|
Look for things like subs.launch(...) or
|
|
|
|
invite.launch() in that code.
|
|
|
|
|
|
|
|
Some items above are prefixed with "link:". Those
|
|
|
|
items, when clicked, just use the normal browser
|
|
|
|
mechanism to link to external pages, and they
|
|
|
|
have a target of "_blank".
|
|
|
|
|
|
|
|
The "info:" items use our info overlay system
|
|
|
|
in static/js/info_overlay.js. They are dispatched
|
|
|
|
using a click handler in static/js/click_handlers.js.
|
|
|
|
The click handler uses "[data-overlay-trigger]" as
|
2021-03-22 16:09:12 +01:00
|
|
|
the selector and then calls browser_history.go_to_location.
|
2018-08-29 19:50:12 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-03-13 21:55:47 +01:00
|
|
|
// We want to remember how far we were scrolled on each 'tab'.
|
|
|
|
// To do so, we need to save away the old position of the
|
|
|
|
// scrollbar when we switch to a new tab (and restore it
|
|
|
|
// when we switch back.)
|
2020-02-12 06:24:38 +01:00
|
|
|
const scroll_positions = new Map();
|
2014-03-13 21:55:47 +01:00
|
|
|
|
2021-02-28 01:02:12 +01:00
|
|
|
export function update_org_settings_menu_item() {
|
2020-07-15 01:29:15 +02:00
|
|
|
const item = $(".admin-menu-item").expectOne();
|
2018-12-06 18:41:56 +01:00
|
|
|
if (page_params.is_admin) {
|
2021-04-13 06:51:54 +02:00
|
|
|
item.find("span").text($t({defaultMessage: "Manage organization"}));
|
2018-12-06 18:41:56 +01:00
|
|
|
} else {
|
2021-04-13 06:51:54 +02:00
|
|
|
item.find("span").text($t({defaultMessage: "Organization settings"}));
|
2018-12-06 18:41:56 +01:00
|
|
|
}
|
2021-02-28 01:02:12 +01:00
|
|
|
}
|
2018-12-06 18:41:56 +01:00
|
|
|
|
2021-02-28 01:02:12 +01:00
|
|
|
export function initialize() {
|
2021-07-08 17:37:18 +02:00
|
|
|
const rendered_gear_menu = render_gear_menu({
|
|
|
|
...page_params,
|
|
|
|
can_invite_others_to_realm: settings_data.user_can_invite_others_to_realm(),
|
|
|
|
});
|
2021-06-14 12:38:43 +02:00
|
|
|
$("#navbar-buttons").html(rendered_gear_menu);
|
2021-02-28 01:02:12 +01:00
|
|
|
update_org_settings_menu_item();
|
2014-03-13 21:55:47 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$('#gear-menu a[data-toggle="tab"]').on("show", (e) => {
|
2014-03-13 21:55:47 +01:00
|
|
|
// Save the position of our old tab away, before we switch
|
2020-07-15 01:29:15 +02:00
|
|
|
const old_tab = $(e.relatedTarget).attr("href");
|
2020-02-12 06:24:38 +01:00
|
|
|
scroll_positions.set(old_tab, message_viewport.scrollTop());
|
2014-03-13 21:55:47 +01:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
$('#gear-menu a[data-toggle="tab"]').on("shown", (e) => {
|
|
|
|
const target_tab = $(e.target).attr("href");
|
2014-03-13 21:55:47 +01:00
|
|
|
// Hide all our error messages when switching tabs
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".alert").removeClass("show");
|
2014-03-13 21:55:47 +01:00
|
|
|
|
|
|
|
// Set the URL bar title to show the sub-page you're currently on.
|
2019-11-02 00:06:25 +01:00
|
|
|
let browser_url = target_tab;
|
2020-07-04 16:25:41 +02:00
|
|
|
if (browser_url === "#message_feed_container") {
|
2014-03-13 21:55:47 +01:00
|
|
|
browser_url = "";
|
|
|
|
}
|
|
|
|
hashchange.changehash(browser_url);
|
|
|
|
|
|
|
|
// After we show the new tab, restore its old scroll position
|
|
|
|
// (we apparently have to do this after setting the hash,
|
|
|
|
// because otherwise that action may scroll us somewhere.)
|
2020-07-04 16:25:41 +02:00
|
|
|
if (target_tab === "#message_feed_container") {
|
2020-02-12 06:24:38 +01:00
|
|
|
if (scroll_positions.has(target_tab)) {
|
|
|
|
message_viewport.scrollTop(scroll_positions.get(target_tab));
|
2014-03-13 21:55:47 +01:00
|
|
|
} else {
|
2017-05-17 05:36:58 +02:00
|
|
|
navigate.scroll_to_selected();
|
2014-03-13 21:55:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// The admin and settings pages are generated client-side through
|
|
|
|
// templates.
|
2021-02-28 01:02:12 +01:00
|
|
|
}
|
2014-03-13 21:55:47 +01:00
|
|
|
|
2021-02-28 01:02:12 +01:00
|
|
|
export function open() {
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#settings-dropdown").trigger("click");
|
2017-05-22 04:29:24 +02:00
|
|
|
// there are invisible li tabs, which should not be clicked.
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#gear-menu").find("li:not(.invisible) a").eq(0).trigger("focus");
|
2021-02-28 01:02:12 +01:00
|
|
|
}
|
2017-03-18 20:30:20 +01:00
|
|
|
|
2021-02-28 01:02:12 +01:00
|
|
|
export function is_open() {
|
2017-05-22 04:28:52 +02:00
|
|
|
return $(".dropdown").hasClass("open");
|
2021-02-28 01:02:12 +01:00
|
|
|
}
|
2017-05-22 04:28:52 +02:00
|
|
|
|
2021-02-28 01:02:12 +01:00
|
|
|
export function close() {
|
|
|
|
if (is_open()) {
|
2017-05-22 04:28:52 +02:00
|
|
|
$(".dropdown").removeClass("open");
|
|
|
|
}
|
2021-02-28 01:02:12 +01:00
|
|
|
}
|