mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 10:26:28 +00:00
stream settings: Refactor logic for stream_subscriber_info display.
This refactor helps to avoid code duplication that occurs if we need to add any extra info to the stream_subscriber_info and also cleans up code in `add_subscriber_form` and `.subscriber_list_remove form` handler to make it more readable. It is preparatory commit to add information about ignored deactivated users when bulk subscribing users to streams.
This commit is contained in:
committed by
Tim Abbott
parent
afe0b7df61
commit
ffb811ef6e
@@ -234,6 +234,28 @@ export function invite_user_to_stream(user_ids, sub, success, failure) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function show_stream_subcription_info({
|
||||||
|
message,
|
||||||
|
add_class,
|
||||||
|
remove_class,
|
||||||
|
subscribed_users,
|
||||||
|
already_subscribed_users,
|
||||||
|
}) {
|
||||||
|
const stream_subscription_info_elem = $(".stream_subscription_info").expectOne();
|
||||||
|
const html = render_stream_subscription_info({
|
||||||
|
message,
|
||||||
|
subscribed_users,
|
||||||
|
already_subscribed_users,
|
||||||
|
});
|
||||||
|
ui.get_content_element(stream_subscription_info_elem).html(html);
|
||||||
|
if (add_class) {
|
||||||
|
stream_subscription_info_elem.addClass(add_class);
|
||||||
|
}
|
||||||
|
if (remove_class) {
|
||||||
|
stream_subscription_info_elem.removeClass(remove_class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function submit_add_subscriber_form(e) {
|
function submit_add_subscriber_form(e) {
|
||||||
const sub = get_sub_for_target(e.target);
|
const sub = get_sub_for_target(e.target);
|
||||||
if (!sub) {
|
if (!sub) {
|
||||||
@@ -241,7 +263,6 @@ function submit_add_subscriber_form(e) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream_subscription_info_elem = $(".stream_subscription_info").expectOne();
|
|
||||||
let user_ids = user_pill.get_user_ids(pill_widget);
|
let user_ids = user_pill.get_user_ids(pill_widget);
|
||||||
user_ids = user_ids.concat(stream_pill.get_user_ids(pill_widget));
|
user_ids = user_ids.concat(stream_pill.get_user_ids(pill_widget));
|
||||||
user_ids = user_ids.concat(user_group_pill.get_user_ids(pill_widget));
|
user_ids = user_ids.concat(user_group_pill.get_user_ids(pill_widget));
|
||||||
@@ -255,10 +276,11 @@ function submit_add_subscriber_form(e) {
|
|||||||
user_ids.delete(page_params.user_id);
|
user_ids.delete(page_params.user_id);
|
||||||
}
|
}
|
||||||
if (user_ids.size === 0) {
|
if (user_ids.size === 0) {
|
||||||
stream_subscription_info_elem
|
show_stream_subcription_info({
|
||||||
.text($t({defaultMessage: "No user to subscribe."}))
|
message: $t({defaultMessage: "No user to subscribe."}),
|
||||||
.addClass("text-error")
|
add_class: "text-error",
|
||||||
.removeClass("text-success");
|
remove_class: "text-success",
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
user_ids = Array.from(user_ids);
|
user_ids = Array.from(user_ids);
|
||||||
@@ -272,17 +294,21 @@ function submit_add_subscriber_form(e) {
|
|||||||
people.get_by_email(email),
|
people.get_by_email(email),
|
||||||
);
|
);
|
||||||
|
|
||||||
const html = render_stream_subscription_info({subscribed_users, already_subscribed_users});
|
show_stream_subcription_info({
|
||||||
ui.get_content_element(stream_subscription_info_elem).html(html);
|
add_class: "text-success",
|
||||||
stream_subscription_info_elem.addClass("text-success").removeClass("text-error");
|
remove_class: "text-error",
|
||||||
|
subscribed_users,
|
||||||
|
already_subscribed_users,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function invite_failure(xhr) {
|
function invite_failure(xhr) {
|
||||||
const error = JSON.parse(xhr.responseText);
|
const error = JSON.parse(xhr.responseText);
|
||||||
stream_subscription_info_elem
|
show_stream_subcription_info({
|
||||||
.text(error.msg)
|
message: error.msg,
|
||||||
.addClass("text-error")
|
add_class: "text-error",
|
||||||
.removeClass("text-success");
|
remove_class: "text-success",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
invite_user_to_stream(user_ids, sub, invite_success, invite_failure);
|
invite_user_to_stream(user_ids, sub, invite_success, invite_failure);
|
||||||
@@ -829,29 +855,30 @@ export function initialize() {
|
|||||||
blueslip.error(".subscriber_list_remove form submit fails");
|
blueslip.error(".subscriber_list_remove form submit fails");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const stream_subscription_info_elem = $(".stream_subscription_info").expectOne();
|
let message;
|
||||||
|
|
||||||
function removal_success(data) {
|
function removal_success(data) {
|
||||||
if (data.removed.length > 0) {
|
if (data.removed.length > 0) {
|
||||||
// Remove the user from the subscriber list.
|
// Remove the user from the subscriber list.
|
||||||
list_entry.remove();
|
list_entry.remove();
|
||||||
stream_subscription_info_elem.text(
|
message = $t({defaultMessage: "Unsubscribed successfully!"});
|
||||||
$t({defaultMessage: "Unsubscribed successfully!"}),
|
|
||||||
);
|
|
||||||
// The rest of the work is done via the subscription -> remove event we will get
|
// The rest of the work is done via the subscription -> remove event we will get
|
||||||
} else {
|
} else {
|
||||||
stream_subscription_info_elem.text(
|
message = $t({defaultMessage: "User is already not subscribed."});
|
||||||
$t({defaultMessage: "User is already not subscribed."}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
stream_subscription_info_elem.addClass("text-success").removeClass("text-error");
|
show_stream_subcription_info({
|
||||||
|
message,
|
||||||
|
add_class: "text-success",
|
||||||
|
remove_class: "text-remove",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function removal_failure() {
|
function removal_failure() {
|
||||||
stream_subscription_info_elem
|
show_stream_subcription_info({
|
||||||
.text($t({defaultMessage: "Error removing user from this stream."}))
|
message: $t({defaultMessage: "Error removing user from this stream."}),
|
||||||
.addClass("text-error")
|
add_class: "text-error",
|
||||||
.removeClass("text-success");
|
remove_class: "text-success",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_user_from_private_stream() {
|
function remove_user_from_private_stream() {
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
{{#if message}}
|
||||||
|
{{message}}
|
||||||
|
<br />
|
||||||
|
{{/if}}
|
||||||
{{#each subscribed_users}}
|
{{#each subscribed_users}}
|
||||||
{{#if @first}}
|
{{#if @first}}
|
||||||
{{t "Successfully subscribed users:" }}
|
{{t "Successfully subscribed users:" }}
|
||||||
|
|||||||
Reference in New Issue
Block a user