mirror of https://github.com/zulip/zulip.git
stream_edit: Extract toggler to new stream_edit_toggler module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
3cac29a8e1
commit
1d43a4cccb
|
@ -221,6 +221,7 @@ EXEMPT_FILES = make_set(
|
|||
"web/src/stream_create_subscribers.js",
|
||||
"web/src/stream_edit.js",
|
||||
"web/src/stream_edit_subscribers.js",
|
||||
"web/src/stream_edit_toggler.js",
|
||||
"web/src/stream_list.js",
|
||||
"web/src/stream_muting.js",
|
||||
"web/src/stream_popover.js",
|
||||
|
|
|
@ -11,7 +11,6 @@ import render_stream_settings from "../templates/stream_settings/stream_settings
|
|||
import * as blueslip from "./blueslip";
|
||||
import * as browser_history from "./browser_history";
|
||||
import * as channel from "./channel";
|
||||
import * as components from "./components";
|
||||
import * as confirm_dialog from "./confirm_dialog";
|
||||
import {show_copied_confirmation} from "./copied_tooltip";
|
||||
import * as dialog_widget from "./dialog_widget";
|
||||
|
@ -28,6 +27,7 @@ import * as settings_org from "./settings_org";
|
|||
import * as stream_color from "./stream_color";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as stream_edit_subscribers from "./stream_edit_subscribers";
|
||||
import * as stream_edit_toggler from "./stream_edit_toggler";
|
||||
import * as stream_settings_api from "./stream_settings_api";
|
||||
import * as stream_settings_containers from "./stream_settings_containers";
|
||||
import * as stream_settings_data from "./stream_settings_data";
|
||||
|
@ -39,9 +39,6 @@ import * as user_groups from "./user_groups";
|
|||
import {user_settings} from "./user_settings";
|
||||
import * as util from "./util";
|
||||
|
||||
export let toggler;
|
||||
export let select_tab = "personal_settings";
|
||||
|
||||
function setup_subscriptions_stream_hash(sub) {
|
||||
const hash = hash_util.stream_edit_url(sub);
|
||||
browser_history.update(hash);
|
||||
|
@ -261,7 +258,7 @@ export function show_settings_for(node) {
|
|||
});
|
||||
scroll_util.get_content_element($("#stream_settings")).html(html);
|
||||
|
||||
$("#stream_settings .tab-container").prepend(toggler.get());
|
||||
$("#stream_settings .tab-container").prepend(stream_edit_toggler.toggler.get());
|
||||
stream_ui_updates.update_toggler_for_sub(sub);
|
||||
|
||||
const $edit_container = stream_settings_containers.get_edit_container(sub);
|
||||
|
@ -278,20 +275,7 @@ export function show_settings_for(node) {
|
|||
}
|
||||
|
||||
export function setup_stream_settings(node) {
|
||||
toggler = components.toggle({
|
||||
child_wants_focus: true,
|
||||
values: [
|
||||
{label: $t({defaultMessage: "General"}), key: "general_settings"},
|
||||
{label: $t({defaultMessage: "Personal"}), key: "personal_settings"},
|
||||
{label: $t({defaultMessage: "Subscribers"}), key: "subscriber_settings"},
|
||||
],
|
||||
callback(_name, key) {
|
||||
$(".stream_section").hide();
|
||||
$(`.${CSS.escape(key)}`).show();
|
||||
select_tab = key;
|
||||
},
|
||||
});
|
||||
|
||||
stream_edit_toggler.setup_toggler();
|
||||
show_settings_for(node);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import $ from "jquery";
|
||||
|
||||
import * as components from "./components";
|
||||
import {$t} from "./i18n";
|
||||
|
||||
export let toggler;
|
||||
export let select_tab = "personal_settings";
|
||||
|
||||
export function setup_toggler() {
|
||||
toggler = components.toggle({
|
||||
child_wants_focus: true,
|
||||
values: [
|
||||
{label: $t({defaultMessage: "General"}), key: "general_settings"},
|
||||
{label: $t({defaultMessage: "Personal"}), key: "personal_settings"},
|
||||
{label: $t({defaultMessage: "Subscribers"}), key: "subscriber_settings"},
|
||||
],
|
||||
callback(_name, key) {
|
||||
$(".stream_section").hide();
|
||||
$(`.${CSS.escape(key)}`).show();
|
||||
select_tab = key;
|
||||
},
|
||||
});
|
||||
}
|
|
@ -11,7 +11,7 @@ import {page_params} from "./page_params";
|
|||
import * as settings_data from "./settings_data";
|
||||
import * as settings_org from "./settings_org";
|
||||
import * as stream_data from "./stream_data";
|
||||
import * as stream_edit from "./stream_edit";
|
||||
import * as stream_edit_toggler from "./stream_edit_toggler";
|
||||
import * as stream_settings_containers from "./stream_settings_containers";
|
||||
import * as stream_settings_ui from "./stream_settings_ui";
|
||||
|
||||
|
@ -37,18 +37,18 @@ export function update_toggler_for_sub(sub) {
|
|||
return;
|
||||
}
|
||||
if (sub.subscribed) {
|
||||
stream_edit.toggler.enable_tab("personal_settings");
|
||||
stream_edit.toggler.goto(stream_edit.select_tab);
|
||||
stream_edit_toggler.toggler.enable_tab("personal_settings");
|
||||
stream_edit_toggler.toggler.goto(stream_edit_toggler.select_tab);
|
||||
} else {
|
||||
if (stream_edit.select_tab === "personal_settings") {
|
||||
if (stream_edit_toggler.select_tab === "personal_settings") {
|
||||
// Go to the general settings tab, if the user is not
|
||||
// subscribed. Also preserve the previous selected tab,
|
||||
// to render next time a stream row is selected.
|
||||
stream_edit.toggler.goto("general_settings");
|
||||
stream_edit_toggler.toggler.goto("general_settings");
|
||||
} else {
|
||||
stream_edit.toggler.goto(stream_edit.select_tab);
|
||||
stream_edit_toggler.toggler.goto(stream_edit_toggler.select_tab);
|
||||
}
|
||||
stream_edit.toggler.disable_tab("personal_settings");
|
||||
stream_edit_toggler.toggler.disable_tab("personal_settings");
|
||||
}
|
||||
enable_or_disable_subscribers_tab(sub);
|
||||
}
|
||||
|
@ -59,14 +59,14 @@ export function enable_or_disable_subscribers_tab(sub) {
|
|||
}
|
||||
|
||||
if (!stream_data.can_view_subscribers(sub)) {
|
||||
stream_edit.toggler.disable_tab("subscriber_settings");
|
||||
if (stream_edit.select_tab === "subscriber_settings") {
|
||||
stream_edit.toggler.goto("general_settings");
|
||||
stream_edit_toggler.toggler.disable_tab("subscriber_settings");
|
||||
if (stream_edit_toggler.select_tab === "subscriber_settings") {
|
||||
stream_edit_toggler.toggler.goto("general_settings");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
stream_edit.toggler.enable_tab("subscriber_settings");
|
||||
stream_edit_toggler.toggler.enable_tab("subscriber_settings");
|
||||
}
|
||||
|
||||
export function update_settings_button_for_sub(sub) {
|
||||
|
|
Loading…
Reference in New Issue