Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

popovers: Replace move topic error with conditionally disabled button.

George A. Michelca60660dc36c
diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js
index 3facc5309a1..f40071d219c 100644
--- a/static/js/stream_popover.js
+++ b/static/js/stream_popover.js
@@ -406,12 +406,24 @@ function build_move_topic_to_stream_popover(e, current_stream_id, topic_name) {
hide_topic_popover();
- function move_topic() {
- const params = Object.fromEntries(
+ function get_params_from_form() {
+ return Object.fromEntries(
$("#move_topic_form")
.serializeArray()
.map(({name, value}) => [name, value]),
);
+ }
+
+ function update_submit_button_disabled_state(select_stream_id) {
+ const {current_stream_id, new_topic_name, old_topic_name} = get_params_from_form();
+
+ $("#move_topic_modal .dialog_submit_button")[0].disabled =
+ Number.parseInt(current_stream_id, 10) === Number.parseInt(select_stream_id, 10) &&
+ new_topic_name.trim().toLowerCase() === old_topic_name.trim().toLowerCase();
+ }
+
+ function move_topic() {
+ const params = get_params_from_form();
const {old_topic_name} = params;
const select_stream_id = stream_widget.value();
@@ -427,18 +439,6 @@ function build_move_topic_to_stream_popover(e, current_stream_id, topic_name) {
send_notification_to_old_thread = send_notification_to_old_thread === "on";
current_stream_id = Number.parseInt(current_stream_id, 10);
- if (
- current_stream_id === Number.parseInt(select_stream_id, 10) &&
- new_topic_name.toLowerCase() === old_topic_name.toLowerCase()
- ) {
- dialog_widget.hide_dialog_spinner();
- ui_report.client_error(
- $t_html({defaultMessage: "Please select a different stream or change topic name."}),
- $("#move_topic_modal #dialog_error"),
- );
- return;
- }
-
dialog_widget.show_dialog_spinner();
message_edit.with_first_message_id(
current_stream_id,
@@ -486,8 +486,14 @@ function build_move_topic_to_stream_popover(e, current_stream_id, topic_name) {
default_text: $t({defaultMessage: "No streams"}),
include_current_item: false,
value: current_stream_id,
+ on_update: update_submit_button_disabled_state,
};
stream_widget = new DropdownListWidget(opts);
+
+ update_submit_button_disabled_state(stream_widget.value());
+ $("#move_topic_modal .inline_topic_edit").on("input", () => {
+ update_submit_button_disabled_state(stream_widget.value());
+ });
}
dialog_widget.launch({