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";
|
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";
|
2021-02-28 01:03:09 +01:00
|
|
|
import * as popovers from "./popovers";
|
2022-11-10 01:24:41 +01:00
|
|
|
import * as resize from "./resize";
|
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";
|
2017-03-05 17:28:40 +01:00
|
|
|
// We handle stream popovers and topic popovers in this
|
|
|
|
// module. Both are popped up from the left sidebar.
|
2019-11-02 00:06:25 +01:00
|
|
|
let current_stream_sidebar_elem;
|
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) {
|
|
|
|
$(element).closest("[class*='-sidebar-menu-icon']").addClass("left_sidebar_menu_icon_visible");
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
const popover_data = $(sidebar_elem).data("popover");
|
|
|
|
if (!popover_data) {
|
|
|
|
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
|
|
|
}
|
|
|
|
return $("li:not(.divider):visible > a", popover_data.$tip);
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function stream_sidebar_menu_handle_keyboard(key) {
|
2020-07-08 22:17:16 +02:00
|
|
|
const items = get_popover_menu_items(current_stream_sidebar_elem);
|
|
|
|
popovers.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;
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function stream_popped() {
|
2017-03-05 17:28:40 +01:00
|
|
|
return current_stream_sidebar_elem !== undefined;
|
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() {
|
|
|
|
if (stream_popped()) {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(current_stream_sidebar_elem).popover("destroy");
|
2022-10-21 14:23:22 +02:00
|
|
|
hide_left_sidebar_menu_icon();
|
2017-03-05 17:28:40 +01:00
|
|
|
current_stream_sidebar_elem = undefined;
|
|
|
|
}
|
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 show_streamlist_sidebar() {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(".app-main .column-left").addClass("expanded");
|
2022-11-10 01:24:41 +01:00
|
|
|
resize.resize_stream_filters_container();
|
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_streamlist_sidebar() {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(".app-main .column-left").removeClass("expanded");
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This little function is a workaround for the fact that
|
|
|
|
// Bootstrap popovers don't properly handle being resized --
|
|
|
|
// so after resizing our popover to add in the spectrum color
|
|
|
|
// picker, we need to adjust its height accordingly.
|
2022-01-25 11:36:19 +01:00
|
|
|
function update_spectrum($popover, update_func) {
|
|
|
|
const initial_height = $popover[0].offsetHeight;
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $colorpicker = $popover.find(".colorpicker-container").find(".colorpicker");
|
|
|
|
update_func($colorpicker);
|
|
|
|
const after_height = $popover[0].offsetHeight;
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $popover_root = $popover.closest(".popover");
|
|
|
|
const current_top_px = Number.parseFloat($popover_root.css("top").replace("px", ""));
|
2019-11-02 00:06:25 +01:00
|
|
|
const height_delta = after_height - initial_height;
|
|
|
|
let top = current_top_px - height_delta / 2;
|
2019-02-15 01:43:17 +01:00
|
|
|
|
|
|
|
if (top < 0) {
|
|
|
|
top = 0;
|
2022-01-25 11:36:19 +01:00
|
|
|
$popover_root.find("div.arrow").hide();
|
2019-02-15 01:43:17 +01:00
|
|
|
} else if (top + after_height > $(window).height() - 20) {
|
|
|
|
top = $(window).height() - after_height - 20;
|
|
|
|
if (top < 0) {
|
|
|
|
top = 0;
|
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
$popover_root.find("div.arrow").hide();
|
2019-02-15 01:43:17 +01:00
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$popover_root.css("top", top + "px");
|
2017-03-05 17:28:40 +01:00
|
|
|
}
|
|
|
|
|
2019-02-22 17:07:49 +01:00
|
|
|
function build_stream_popover(opts) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const elt = opts.elt;
|
|
|
|
const stream_id = opts.stream_id;
|
2019-02-22 17:07:49 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
if (stream_popped() && current_stream_sidebar_elem === elt) {
|
2017-03-05 17:28:40 +01:00
|
|
|
// If the popover is already shown, clicking again should toggle it.
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2017-03-05 17:28:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-10 01:09:21 +01:00
|
|
|
popovers.hide_all_except_sidebars();
|
2017-03-05 17:28:40 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
$(elt).popover({
|
2020-07-20 22:18:43 +02:00
|
|
|
content,
|
2019-09-17 23:54:52 +02:00
|
|
|
html: true,
|
2017-03-05 17:28:40 +01:00
|
|
|
trigger: "manual",
|
|
|
|
fixed: true,
|
2019-02-15 01:43:17 +01:00
|
|
|
fix_positions: true,
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$(elt).popover("show");
|
2022-01-25 11:36:19 +01:00
|
|
|
const $popover = $(`.streams_popover[data-stream-id="${CSS.escape(stream_id)}"]`);
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
update_spectrum($popover, ($colorpicker) => {
|
|
|
|
$colorpicker.spectrum(stream_color.sidebar_popover_colorpicker_options);
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
current_stream_sidebar_elem = elt;
|
2022-10-21 14:23:22 +02:00
|
|
|
show_left_sidebar_menu_icon(elt);
|
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) => {
|
2019-02-22 17:07:49 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const elt = e.target;
|
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
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
register_stream_handlers();
|
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2021-02-28 01:02:37 +01:00
|
|
|
export function register_stream_handlers() {
|
2017-03-05 17:28:40 +01:00
|
|
|
// Stream settings
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".open_stream_settings", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_popover_sub(e);
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2017-03-05 17:28:40 +01:00
|
|
|
|
2022-03-01 19:14:26 +01:00
|
|
|
const stream_edit_hash = hash_util.stream_edit_url(sub);
|
2021-03-22 16:09:12 +01:00
|
|
|
browser_history.go_to_location(stream_edit_hash);
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Pin/unpin
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".pin_to_top", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_popover_sub(e);
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.toggle_pin_to_top_stream(sub);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2018-02-15 20:38:06 +01:00
|
|
|
// Mark all messages in stream as read
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".mark_stream_as_read", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_popover_sub(e);
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2017-08-15 19:34:15 +02:00
|
|
|
unread_ops.mark_stream_as_read(sub.stream_id);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2023-04-01 20:49:16 +02:00
|
|
|
|
2017-03-05 17:28:40 +01:00
|
|
|
// Mute/unmute
|
2020-07-22 02:08:20 +02:00
|
|
|
$("body").on("click", ".toggle_stream_muted", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_popover_sub(e);
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.set_muted(sub, !sub.is_muted);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.stopPropagation();
|
2021-01-19 15:27:49 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// New topic in stream menu
|
|
|
|
$("body").on("click", ".popover_new_topic_button", (e) => {
|
|
|
|
const sub = stream_popover_sub(e);
|
|
|
|
hide_stream_popover();
|
|
|
|
|
2021-04-06 02:38:57 +02:00
|
|
|
compose_actions.start("stream", {
|
|
|
|
trigger: "popover new topic button",
|
|
|
|
stream: sub.name,
|
|
|
|
topic: "",
|
|
|
|
});
|
2021-01-19 15:27:49 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Unsubscribe
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".popover_sub_unsub_button", function (e) {
|
2017-03-05 17:28:40 +01:00
|
|
|
$(this).toggleClass("unsub");
|
|
|
|
$(this).closest(".popover").fadeOut(500).delay(500).remove();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_popover_sub(e);
|
2021-07-04 08:03:07 +02:00
|
|
|
stream_settings_ui.sub_or_unsub(sub);
|
2017-03-05 17:28:40 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2020-06-10 18:55:51 +02:00
|
|
|
// Choose a different color.
|
2020-07-15 01:29:15 +02:00
|
|
|
$("body").on("click", ".choose_stream_color", (e) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
update_spectrum($(e.target).closest(".streams_popover"), ($colorpicker) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".colorpicker-container").show();
|
2022-01-25 11:36:19 +01:00
|
|
|
$colorpicker.spectrum("destroy");
|
|
|
|
$colorpicker.spectrum(stream_color.sidebar_popover_colorpicker_options_full);
|
2017-03-05 17:28:40 +01:00
|
|
|
// 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.
|
2022-01-25 11:36:19 +01:00
|
|
|
$colorpicker.parent().find(".sp-container").removeClass("sp-buttons-disabled");
|
2017-03-05 17:28:40 +01:00
|
|
|
$(e.target).hide();
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".streams_popover").on("click", "a.sp-cancel", () => {
|
2021-02-28 01:02:37 +01:00
|
|
|
hide_stream_popover();
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
2020-10-20 19:43:41 +02:00
|
|
|
if ($(window).width() <= 768) {
|
|
|
|
$(".popover-inner").hide().fadeIn(300);
|
|
|
|
$(".popover").addClass("colorpicker-popover");
|
|
|
|
}
|
2017-03-05 17:28:40 +01:00
|
|
|
});
|
2021-02-28 01:02:37 +01:00
|
|
|
}
|