2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2023-06-20 12:18:41 +02:00
|
|
|
import render_inline_decorated_stream_name from "../templates/inline_decorated_stream_name.hbs";
|
2021-02-28 01:02:37 +01:00
|
|
|
import render_move_topic_to_stream from "../templates/move_topic_to_stream.hbs";
|
|
|
|
import render_stream_sidebar_actions from "../templates/stream_sidebar_actions.hbs";
|
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-03-22 16:09:12 +01:00
|
|
|
import * as browser_history from "./browser_history";
|
2021-01-19 15:27:49 +01:00
|
|
|
import * as compose_actions from "./compose_actions";
|
2022-02-26 12:28:09 +01:00
|
|
|
import * as composebox_typeahead from "./composebox_typeahead";
|
2023-07-28 11:10:59 +02:00
|
|
|
import {media_breakpoints_num} from "./css_variables";
|
2021-07-18 11:18:03 +02:00
|
|
|
import * as dialog_widget from "./dialog_widget";
|
2023-06-20 12:18:41 +02:00
|
|
|
import * as dropdown_widget from "./dropdown_widget";
|
2021-02-28 01:07:13 +01:00
|
|
|
import * as hash_util from "./hash_util";
|
2021-05-07 18:41:12 +02:00
|
|
|
import {$t, $t_html} from "./i18n";
|
2021-02-28 01:02:37 +01:00
|
|
|
import * as message_edit from "./message_edit";
|
2023-08-01 15:53:24 +02:00
|
|
|
import * as popover_menus from "./popover_menus";
|
|
|
|
import {left_sidebar_tippy_options} from "./popover_menus";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as popovers from "./popovers";
|
2021-05-13 18:17:57 +02:00
|
|
|
import * as settings_data from "./settings_data";
|
2021-03-22 18:29:15 +01:00
|
|
|
import * as stream_bar from "./stream_bar";
|
2021-02-28 01:02:37 +01:00
|
|
|
import * as stream_color from "./stream_color";
|
2023-06-20 12:18:41 +02:00
|
|
|
import * as stream_data from "./stream_data";
|
2021-07-09 15:51:31 +02:00
|
|
|
import * as stream_settings_ui from "./stream_settings_ui";
|
2021-04-15 17:02:54 +02:00
|
|
|
import * as sub_store from "./sub_store";
|
2021-11-24 16:03:21 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
2023-04-18 17:39:16 +02:00
|
|
|
import * as ui_util from "./ui_util";
|
2021-02-28 21:30:08 +01:00
|
|
|
import * as unread_ops from "./unread_ops";
|
2023-07-28 11:24:42 +02:00
|
|
|
// In this module, we manage stream popovers
|
|
|
|
// that pop up from the left sidebar.
|
2023-08-01 15:53:24 +02:00
|
|
|
let stream_popover_instance = null;
|
2023-06-20 12:18:41 +02:00
|
|
|
let stream_widget_value;
|
2022-01-25 11:36:19 +01:00
|
|
|
let $stream_header_colorblock;
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-10-21 14:23:22 +02:00
|
|
|
// Keep the menu icon over which the popover is based off visible.
|
|
|
|
function show_left_sidebar_menu_icon(element) {
|
2023-09-18 16:57:45 +02:00
|
|
|
$(element).closest(".sidebar-menu-icon").addClass("left_sidebar_menu_icon_visible");
|
2022-10-21 14:23:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the class from element when popover is closed
|
|
|
|
function hide_left_sidebar_menu_icon() {
|
|
|
|
$(".left_sidebar_menu_icon_visible").removeClass("left_sidebar_menu_icon_visible");
|
|
|
|
}
|
|
|
|
|
2020-07-08 22:17:16 +02:00
|
|
|
function get_popover_menu_items(sidebar_elem) {
|
|
|
|
if (!sidebar_elem) {
|
|
|
|
blueslip.error("Trying to get menu items when action popover is closed.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-07-08 22:17:16 +02:00
|
|
|
}
|
|
|
|
|
2023-08-01 15:53:24 +02:00
|
|
|
const $popover = $(sidebar_elem.popper);
|
|
|
|
if (!$popover) {
|
2020-07-08 22:17:16 +02:00
|
|
|
blueslip.error("Cannot find popover data for stream sidebar menu.");
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2020-07-08 22:17:16 +02:00
|
|
|
}
|
2023-08-01 15:53:24 +02:00
|
|
|
|
|
|
|
return $("li:not(.divider):visible > a", $popover);
|
2020-07-08 22:17:16 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function stream_sidebar_menu_handle_keyboard(key) {
|
2023-08-01 15:53:24 +02:00
|
|
|
const items = get_popover_menu_items(stream_popover_instance);
|
2023-09-25 06:45:37 +02:00
|
|
|
popover_menus.popover_items_handle_keyboard(key, items);
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2020-07-09 03:18:27 +02:00
|
|
|
|
2023-03-30 16:12:27 +02:00
|
|
|
export function elem_to_stream_id($elem) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const stream_id = Number.parseInt($elem.attr("data-stream-id"), 10);
|
2020-01-12 13:39:37 +01:00
|
|
|
|
|
|
|
if (stream_id === undefined) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.error("could not find stream id");
|
2020-01-12 13:39:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return stream_id;
|
|
|
|
}
|
|
|
|
|
2023-08-29 18:17:00 +02:00
|
|
|
export function is_open() {
|
2023-08-01 15:53:24 +02:00
|
|
|
return Boolean(stream_popover_instance);
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function hide_stream_popover() {
|
2023-08-29 18:17:00 +02:00
|
|
|
if (is_open()) {
|
2022-10-21 14:23:22 +02:00
|
|
|
hide_left_sidebar_menu_icon();
|
2023-08-01 15:53:24 +02:00
|
|
|
stream_popover_instance.destroy();
|
|
|
|
stream_popover_instance = null;
|
2017-03-05 17:28:40 +01:00
|
|
|
}
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
|
|
|
function stream_popover_sub(e) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elem = $(e.currentTarget).parents("ul");
|
|
|
|
const stream_id = elem_to_stream_id($elem);
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(stream_id);
|
2017-03-05 17:28:40 +01:00
|
|
|
if (!sub) {
|
2023-04-24 15:57:45 +02:00
|
|
|
blueslip.error("Unknown stream", {stream_id});
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2017-03-05 17:28:40 +01:00
|
|
|
}
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2019-02-22 17:07:49 +01:00
|
|
|
function build_stream_popover(opts) {
|
2023-08-01 15:53:24 +02:00
|
|
|
const {elt, stream_id} = opts;
|
2019-02-22 17:07:49 +01:00
|
|
|
|
2023-08-01 15:53:24 +02:00
|
|
|
// This will allow the user to close the popover by clicking
|
|
|
|
// on the reference element if the popover is already open.
|
|
|
|
if (stream_popover_instance?.reference === elt) {
|
2017-03-05 17:28:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-10 01:09:21 +01:00
|
|
|
popovers.hide_all_except_sidebars();
|
2019-11-02 00:06:25 +01:00
|
|
|
const content = render_stream_sidebar_actions({
|
2021-04-15 17:02:54 +02:00
|
|
|
stream: sub_store.get(stream_id),
|
2019-07-09 21:24:00 +02:00
|
|
|
});
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2023-08-01 15:53:24 +02:00
|
|
|
popover_menus.toggle_popover_menu(elt, {
|
2023-09-19 20:34:40 +02:00
|
|
|
// Add a delay to separate `hideOnClick` and `onShow` so that
|
|
|
|
// `onShow` is called after `hideOnClick`.
|
|
|
|
// See https://github.com/atomiks/tippyjs/issues/230 for more details.
|
|
|
|
delay: [100, 0],
|
2023-08-01 15:53:24 +02:00
|
|
|
...left_sidebar_tippy_options,
|
|
|
|
onCreate(instance) {
|
|
|
|
stream_popover_instance = instance;
|
|
|
|
const $popover = $(instance.popper);
|
|
|
|
$popover.addClass("stream-popover-root");
|
|
|
|
instance.setContent(ui_util.parse_html(content));
|
|
|
|
},
|
2023-09-13 19:21:07 +02:00
|
|
|
onMount(instance) {
|
|
|
|
const $popper = $(instance.popper);
|
2023-08-01 15:53:24 +02:00
|
|
|
show_left_sidebar_menu_icon(elt);
|
2023-09-13 19:21:07 +02:00
|
|
|
|
|
|
|
// Stream settings
|
|
|
|
$popper.on("click", ".open_stream_settings", (e) => {
|
|
|
|
const sub = stream_popover_sub(e);
|
|
|
|
hide_stream_popover();
|
|
|
|
|
|
|
|
const stream_edit_hash = hash_util.stream_edit_url(sub);
|
|
|
|
browser_history.go_to_location(stream_edit_hash);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Pin/unpin
|
|
|
|
$popper.on("click", ".pin_to_top", (e) => {
|
|
|
|
const sub = stream_popover_sub(e);
|
|
|
|
hide_stream_popover();
|
|
|
|
stream_settings_ui.toggle_pin_to_top_stream(sub);
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Mark all messages in stream as read
|
|
|
|
$popper.on("click", ".mark_stream_as_read", (e) => {
|
|
|
|
const sub = stream_popover_sub(e);
|
|
|
|
hide_stream_popover();
|
|
|
|
unread_ops.mark_stream_as_read(sub.stream_id);
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Mute/unmute
|
|
|
|
$popper.on("click", ".toggle_stream_muted", (e) => {
|
|
|
|
const sub = stream_popover_sub(e);
|
|
|
|
hide_stream_popover();
|
|
|
|
stream_settings_ui.set_muted(sub, !sub.is_muted);
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// New topic in stream menu
|
|
|
|
$popper.on("click", ".popover_new_topic_button", (e) => {
|
|
|
|
const sub = stream_popover_sub(e);
|
|
|
|
hide_stream_popover();
|
|
|
|
|
|
|
|
compose_actions.start("stream", {
|
|
|
|
trigger: "popover new topic button",
|
|
|
|
stream: sub.name,
|
|
|
|
topic: "",
|
|
|
|
});
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Unsubscribe
|
|
|
|
$popper.on("click", ".popover_sub_unsub_button", function (e) {
|
|
|
|
$(this).toggleClass("unsub");
|
|
|
|
$(this).closest(".popover").fadeOut(500).delay(500).remove();
|
|
|
|
|
|
|
|
const sub = stream_popover_sub(e);
|
|
|
|
stream_settings_ui.sub_or_unsub(sub);
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Choose a different color.
|
|
|
|
$popper.on("click", ".choose_stream_color", (e) => {
|
|
|
|
const $popover = $(e.target).closest(".streams_popover");
|
|
|
|
const $colorpicker = $popover.find(".colorpicker-container").find(".colorpicker");
|
|
|
|
$(".colorpicker-container").show();
|
|
|
|
$colorpicker.spectrum("destroy");
|
|
|
|
$colorpicker.spectrum(stream_color.sidebar_popover_colorpicker_options_full);
|
|
|
|
// In theory this should clean up the old color picker,
|
|
|
|
// but this seems a bit flaky -- the new colorpicker
|
|
|
|
// doesn't fire until you click a button, but the buttons
|
|
|
|
// have been hidden. We work around this by just manually
|
|
|
|
// fixing it up here.
|
|
|
|
$colorpicker.parent().find(".sp-container").removeClass("sp-buttons-disabled");
|
|
|
|
$(e.target).hide();
|
|
|
|
|
|
|
|
$(".streams_popover").on("click", "a.sp-cancel", () => {
|
|
|
|
hide_stream_popover();
|
|
|
|
});
|
|
|
|
if ($(window).width() <= media_breakpoints_num.md) {
|
|
|
|
$(".popover-inner").hide().fadeIn(300);
|
|
|
|
$(".popover").addClass("colorpicker-popover");
|
|
|
|
}
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2023-08-01 15:53:24 +02:00
|
|
|
},
|
|
|
|
onHidden() {
|
|
|
|
hide_stream_popover();
|
|
|
|
},
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-14 18:58:10 +02:00
|
|
|
export function build_move_topic_to_stream_popover(
|
|
|
|
current_stream_id,
|
|
|
|
topic_name,
|
|
|
|
only_topic_edit,
|
|
|
|
message,
|
|
|
|
) {
|
2023-05-18 15:53:21 +02:00
|
|
|
const current_stream_name = sub_store.maybe_get_stream_name(current_stream_id);
|
2020-06-03 16:44:57 +02:00
|
|
|
const args = {
|
2020-07-15 00:34:28 +02:00
|
|
|
topic_name,
|
|
|
|
current_stream_id,
|
2020-06-03 16:44:57 +02:00
|
|
|
notify_new_thread: message_edit.notify_new_thread_default,
|
|
|
|
notify_old_thread: message_edit.notify_old_thread_default,
|
2022-10-03 09:41:13 +02:00
|
|
|
from_message_actions_popover: message !== undefined,
|
2023-04-14 18:58:10 +02:00
|
|
|
only_topic_edit,
|
2020-06-03 16:44:57 +02:00
|
|
|
};
|
2020-02-19 01:38:34 +01:00
|
|
|
|
2022-12-22 11:12:31 +01:00
|
|
|
// When the modal is opened for moving the whole topic from left sidebar,
|
|
|
|
// we do not have any message object and so we disable the stream input
|
2023-03-24 15:28:02 +01:00
|
|
|
// based on the move_messages_between_streams_policy setting and topic
|
|
|
|
// input based on edit_topic_policy. In other cases, message object is
|
|
|
|
// available and thus we check the time-based permissions as well in the
|
|
|
|
// below if block to enable or disable the stream and topic input.
|
2022-12-22 11:12:31 +01:00
|
|
|
let disable_stream_input = !settings_data.user_can_move_messages_between_streams();
|
2023-03-24 15:28:02 +01:00
|
|
|
args.disable_topic_input = !settings_data.user_can_move_messages_to_another_topic();
|
2022-12-22 11:12:31 +01:00
|
|
|
|
2023-04-14 18:58:10 +02:00
|
|
|
let modal_heading;
|
|
|
|
if (only_topic_edit) {
|
|
|
|
modal_heading = $t_html({defaultMessage: "Rename topic"});
|
|
|
|
} else {
|
|
|
|
modal_heading = $t_html({defaultMessage: "Move topic"});
|
|
|
|
}
|
|
|
|
|
2022-10-03 09:41:13 +02:00
|
|
|
if (message !== undefined) {
|
|
|
|
modal_heading = $t_html({defaultMessage: "Move messages"});
|
2022-10-05 20:03:20 +02:00
|
|
|
// We disable topic input only for modal is opened from the message actions
|
|
|
|
// popover and not when moving the whole topic from left sidebar. This is
|
|
|
|
// because topic editing permission depend on message and we do not have
|
|
|
|
// any message object when opening the modal and the first message of
|
|
|
|
// topic is fetched from the server after clicking submit.
|
|
|
|
// Though, this will be changed soon as we are going to make topic
|
|
|
|
// edit permission independent of message.
|
2023-04-17 08:50:00 +02:00
|
|
|
|
|
|
|
// We potentially got to this function by clicking a button that implied the
|
|
|
|
// user would be able to move their message. Give a little bit of buffer in
|
|
|
|
// case the button has been around for a bit, e.g. we show the
|
|
|
|
// move_message_button (hovering plus icon) as long as the user would have
|
|
|
|
// been able to click it at the time the mouse entered the message_row. Also
|
|
|
|
// a buffer in case their computer is slow, or stalled for a second, etc
|
|
|
|
// If you change this number also change edit_limit_buffer in
|
|
|
|
// zerver.actions.message_edit.check_update_message
|
|
|
|
const move_limit_buffer = 5;
|
|
|
|
args.disable_topic_input = !message_edit.is_topic_editable(message, move_limit_buffer);
|
|
|
|
disable_stream_input = !message_edit.is_stream_editable(message, move_limit_buffer);
|
2022-10-03 09:41:13 +02:00
|
|
|
}
|
2020-02-19 01:38:34 +01:00
|
|
|
|
2022-04-14 06:43:38 +02:00
|
|
|
function get_params_from_form() {
|
|
|
|
return Object.fromEntries(
|
2021-07-18 11:18:03 +02:00
|
|
|
$("#move_topic_form")
|
|
|
|
.serializeArray()
|
|
|
|
.map(({name, value}) => [name, value]),
|
|
|
|
);
|
2022-04-14 06:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function update_submit_button_disabled_state(select_stream_id) {
|
|
|
|
const {current_stream_id, new_topic_name, old_topic_name} = get_params_from_form();
|
|
|
|
|
2022-04-19 01:21:56 +02:00
|
|
|
// Unlike most topic comparisons in Zulip, we intentionally do
|
|
|
|
// a case-sensitive comparison, since adjusting the
|
|
|
|
// capitalization of a topic is a valid operation.
|
2022-10-05 20:03:20 +02:00
|
|
|
// new_topic_name can be undefined when the new topic input is
|
|
|
|
// disabled in case when user does not have permission to edit
|
|
|
|
// topic and thus submit button is disabled if stream is also
|
|
|
|
// not changed.
|
2022-04-14 06:43:38 +02:00
|
|
|
$("#move_topic_modal .dialog_submit_button")[0].disabled =
|
|
|
|
Number.parseInt(current_stream_id, 10) === Number.parseInt(select_stream_id, 10) &&
|
2022-10-05 20:03:20 +02:00
|
|
|
(new_topic_name === undefined || new_topic_name.trim() === old_topic_name.trim());
|
2022-04-14 06:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function move_topic() {
|
|
|
|
const params = get_params_from_form();
|
2021-07-18 11:18:03 +02:00
|
|
|
|
|
|
|
const {old_topic_name} = params;
|
2023-04-14 18:58:10 +02:00
|
|
|
let select_stream_id;
|
|
|
|
if (only_topic_edit) {
|
|
|
|
select_stream_id = undefined;
|
|
|
|
} else {
|
2023-06-20 12:18:41 +02:00
|
|
|
select_stream_id = stream_widget_value;
|
2023-04-14 18:58:10 +02:00
|
|
|
}
|
2021-07-18 11:18:03 +02:00
|
|
|
|
|
|
|
let {
|
|
|
|
current_stream_id,
|
|
|
|
new_topic_name,
|
|
|
|
send_notification_to_new_thread,
|
|
|
|
send_notification_to_old_thread,
|
|
|
|
} = params;
|
|
|
|
send_notification_to_new_thread = send_notification_to_new_thread === "on";
|
|
|
|
send_notification_to_old_thread = send_notification_to_old_thread === "on";
|
|
|
|
current_stream_id = Number.parseInt(current_stream_id, 10);
|
|
|
|
|
2022-10-05 20:03:20 +02:00
|
|
|
if (new_topic_name !== undefined) {
|
|
|
|
// new_topic_name can be undefined when the new topic input is disabled when
|
|
|
|
// user does not have permission to edit topic.
|
|
|
|
new_topic_name = new_topic_name.trim();
|
|
|
|
}
|
|
|
|
if (old_topic_name.trim() === new_topic_name) {
|
2022-10-03 09:41:13 +02:00
|
|
|
// We use `undefined` to tell the server that
|
|
|
|
// there has been no change in the topic name.
|
|
|
|
new_topic_name = undefined;
|
|
|
|
}
|
2022-12-16 05:38:20 +01:00
|
|
|
if (select_stream_id === current_stream_id) {
|
|
|
|
// We use `undefined` to tell the server that
|
|
|
|
// there has been no change in stream. This is
|
|
|
|
// important for cases when changing stream is
|
|
|
|
// not allowed or when changes other than
|
|
|
|
// stream-change has been made.
|
|
|
|
select_stream_id = undefined;
|
|
|
|
}
|
2022-10-03 09:41:13 +02:00
|
|
|
|
|
|
|
let propagate_mode = "change_all";
|
|
|
|
if (message !== undefined) {
|
|
|
|
// We already have the message_id here which means that modal is opened using
|
|
|
|
// message popover.
|
|
|
|
propagate_mode = $("#move_topic_modal select.message_edit_topic_propagate").val();
|
|
|
|
message_edit.move_topic_containing_message_to_stream(
|
|
|
|
message.id,
|
|
|
|
select_stream_id,
|
|
|
|
new_topic_name,
|
|
|
|
send_notification_to_new_thread,
|
|
|
|
send_notification_to_old_thread,
|
|
|
|
propagate_mode,
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-18 11:18:03 +02:00
|
|
|
dialog_widget.show_dialog_spinner();
|
2021-07-27 21:14:18 +02:00
|
|
|
message_edit.with_first_message_id(
|
2021-07-18 11:18:03 +02:00
|
|
|
current_stream_id,
|
|
|
|
old_topic_name,
|
|
|
|
(message_id) => {
|
2023-02-04 01:52:39 +01:00
|
|
|
message_edit.move_topic_containing_message_to_stream(
|
|
|
|
message_id,
|
|
|
|
select_stream_id,
|
|
|
|
new_topic_name,
|
|
|
|
send_notification_to_new_thread,
|
|
|
|
send_notification_to_old_thread,
|
|
|
|
propagate_mode,
|
|
|
|
);
|
2021-07-18 11:18:03 +02:00
|
|
|
},
|
|
|
|
(xhr) => {
|
|
|
|
dialog_widget.hide_dialog_spinner();
|
2021-11-24 16:03:21 +01:00
|
|
|
ui_report.error(
|
|
|
|
$t_html({defaultMessage: "Error moving topic"}),
|
|
|
|
xhr,
|
|
|
|
$("#move_topic_modal #dialog_error"),
|
|
|
|
);
|
2021-07-18 11:18:03 +02:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-26 12:28:09 +01:00
|
|
|
function set_stream_topic_typeahead() {
|
2023-04-18 17:24:55 +02:00
|
|
|
const $topic_input = $("#move_topic_form .move_messages_edit_topic");
|
2023-06-20 12:18:41 +02:00
|
|
|
const new_stream_id = Number(stream_widget_value, 10);
|
2022-02-26 12:28:09 +01:00
|
|
|
const new_stream_name = sub_store.get(new_stream_id).name;
|
|
|
|
$topic_input.data("typeahead").unlisten();
|
|
|
|
composebox_typeahead.initialize_topic_edit_typeahead($topic_input, new_stream_name, false);
|
|
|
|
}
|
|
|
|
|
2023-06-20 12:18:41 +02:00
|
|
|
function render_selected_stream() {
|
2023-06-27 01:40:25 +02:00
|
|
|
const stream_id = Number.parseInt(stream_widget_value, 10);
|
|
|
|
stream_bar.decorate(stream_id, $stream_header_colorblock);
|
|
|
|
const stream = stream_data.get_sub_by_id(stream_id);
|
2023-06-20 12:18:41 +02:00
|
|
|
if (stream === undefined) {
|
2023-07-19 16:09:53 +02:00
|
|
|
$("#move_topic_to_stream_widget .dropdown_widget_value").text(
|
|
|
|
$t({defaultMessage: "Select a stream"}),
|
|
|
|
);
|
2023-06-20 12:18:41 +02:00
|
|
|
} else {
|
2023-07-19 16:09:53 +02:00
|
|
|
$("#move_topic_to_stream_widget .dropdown_widget_value").html(
|
2023-06-20 12:18:41 +02:00
|
|
|
render_inline_decorated_stream_name({stream, show_colored_icon: true}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function move_topic_on_update(event, dropdown) {
|
|
|
|
stream_widget_value = $(event.currentTarget).attr("data-unique-id");
|
|
|
|
|
|
|
|
update_submit_button_disabled_state(stream_widget_value);
|
2022-02-26 12:28:09 +01:00
|
|
|
set_stream_topic_typeahead();
|
2023-06-20 12:18:41 +02:00
|
|
|
render_selected_stream();
|
|
|
|
|
|
|
|
dropdown.hide();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2022-02-26 12:28:09 +01:00
|
|
|
}
|
|
|
|
|
2021-07-18 11:18:03 +02:00
|
|
|
function move_topic_post_render() {
|
2023-04-14 18:58:10 +02:00
|
|
|
$("#move_topic_modal .dialog_submit_button").prop("disabled", true);
|
|
|
|
|
2023-04-18 17:24:55 +02:00
|
|
|
const $topic_input = $("#move_topic_form .move_messages_edit_topic");
|
2023-04-14 18:58:10 +02:00
|
|
|
composebox_typeahead.initialize_topic_edit_typeahead(
|
|
|
|
$topic_input,
|
|
|
|
current_stream_name,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (only_topic_edit) {
|
|
|
|
// Set select_stream_id to current_stream_id since we user is not allowed
|
|
|
|
// to edit stream in topic-edit only UI.
|
|
|
|
const select_stream_id = current_stream_id;
|
|
|
|
$topic_input.on("input", () => {
|
|
|
|
update_submit_button_disabled_state(select_stream_id);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$stream_header_colorblock = $("#dialog_widget_modal .topic_stream_edit_header").find(
|
2021-07-18 11:18:03 +02:00
|
|
|
".stream_header_colorblock",
|
|
|
|
);
|
2023-06-20 12:18:41 +02:00
|
|
|
stream_widget_value = current_stream_id;
|
|
|
|
const streams_list_options = () =>
|
|
|
|
stream_data.get_options_for_dropdown_widget().filter((stream) => {
|
|
|
|
if (stream.stream_id === current_stream_id) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return stream_data.can_post_messages_in_stream(stream);
|
|
|
|
});
|
2023-07-19 16:09:53 +02:00
|
|
|
|
|
|
|
new dropdown_widget.DropdownWidget({
|
|
|
|
widget_name: "move_topic_to_stream",
|
|
|
|
get_options: streams_list_options,
|
|
|
|
item_click_callback: move_topic_on_update,
|
|
|
|
$events_container: $("#move_topic_modal"),
|
|
|
|
tippy_props: {
|
2023-06-20 12:18:41 +02:00
|
|
|
// Overlap dropdown search input with stream selection button.
|
|
|
|
placement: "bottom-start",
|
|
|
|
offset: [0, -30],
|
|
|
|
},
|
2023-07-19 16:09:53 +02:00
|
|
|
}).setup();
|
2022-04-14 06:43:38 +02:00
|
|
|
|
2023-06-20 12:18:41 +02:00
|
|
|
render_selected_stream();
|
2022-12-22 11:12:31 +01:00
|
|
|
$("#select_stream_widget .dropdown-toggle").prop("disabled", disable_stream_input);
|
2023-04-18 17:24:55 +02:00
|
|
|
$("#move_topic_modal .move_messages_edit_topic").on("input", () => {
|
2023-06-20 12:18:41 +02:00
|
|
|
update_submit_button_disabled_state(stream_widget_value);
|
|
|
|
});
|
2021-07-18 11:18:03 +02:00
|
|
|
}
|
2020-05-12 13:41:45 +02:00
|
|
|
|
2023-04-18 17:39:16 +02:00
|
|
|
function focus_on_move_modal_render() {
|
|
|
|
if (!disable_stream_input && args.disable_topic_input) {
|
|
|
|
$("#select_stream_widget .button").trigger("focus");
|
|
|
|
} else {
|
|
|
|
ui_util.place_caret_at_end($(".move_messages_edit_topic")[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-18 11:18:03 +02:00
|
|
|
dialog_widget.launch({
|
2022-10-03 09:41:13 +02:00
|
|
|
html_heading: modal_heading,
|
2021-07-18 11:18:03 +02:00
|
|
|
html_body: render_move_topic_to_stream(args),
|
|
|
|
html_submit_button: $t_html({defaultMessage: "Confirm"}),
|
|
|
|
id: "move_topic_modal",
|
|
|
|
on_click: move_topic,
|
|
|
|
loading_spinner: true,
|
2023-04-18 17:39:16 +02:00
|
|
|
on_shown: focus_on_move_modal_render,
|
2021-07-18 11:18:03 +02:00
|
|
|
post_render: move_topic_post_render,
|
|
|
|
});
|
2020-02-19 01:38:34 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function register_click_handlers() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#stream_filters").on("click", ".stream-sidebar-menu-icon", (e) => {
|
2023-08-29 19:28:31 +02:00
|
|
|
const elt = e.currentTarget;
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stream_li = $(elt).parents("li");
|
|
|
|
const stream_id = elem_to_stream_id($stream_li);
|
2019-02-22 17:07:49 +01:00
|
|
|
|
|
|
|
build_stream_popover({
|
2020-07-20 22:18:43 +02:00
|
|
|
elt,
|
|
|
|
stream_id,
|
2019-02-22 17:07:49 +01:00
|
|
|
});
|
2019-02-05 14:48:39 +01:00
|
|
|
|
2023-08-01 15:53:24 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2023-09-19 20:34:40 +02:00
|
|
|
|
|
|
|
$("body").on("click", ".inbox-stream-menu", (e) => {
|
|
|
|
const elt = e.currentTarget;
|
|
|
|
const stream_id = Number.parseInt($(elt).attr("data-stream-id"), 10);
|
|
|
|
|
|
|
|
build_stream_popover({
|
|
|
|
elt,
|
|
|
|
stream_id,
|
|
|
|
});
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|