invite: Add checkbox to select all default streams.

We now add a checkbox in "Steams they should join" to directly
select all default streams in the realm for the invite.
We hide the stream list if that option is selected.
This commit is contained in:
Sahil Batra 2023-05-09 15:00:41 +05:30 committed by Tim Abbott
parent 4ca887bade
commit 0ec16407ba
2 changed files with 39 additions and 7 deletions

View File

@ -45,11 +45,17 @@ function get_common_invitation_data() {
expires_in = Number.parseFloat($("#expires_in").val());
}
const stream_ids = [];
let stream_ids = [];
const default_stream_ids = stream_data.get_default_stream_ids();
if (default_stream_ids.length !== 0 && $("#invite_select_default_streams").prop("checked")) {
stream_ids = default_stream_ids;
} else {
$("#invite-stream-checkboxes input:checked").each(function () {
const stream_id = Number.parseInt($(this).val(), 10);
stream_ids.push(stream_id);
});
}
const data = {
csrfmiddlewaretoken: csrf_token,
invite_as,
@ -231,6 +237,17 @@ function set_custom_time_inputs_visibility() {
}
}
function set_streams_to_join_list_visibility() {
const default_streams_selected = $("#invite_select_default_streams").prop("checked");
if (default_streams_selected) {
$("#streams_to_add .invite-stream-controls").hide();
$("#invite-stream-checkboxes").hide();
} else {
$("#streams_to_add .invite-stream-controls").show();
$("#invite-stream-checkboxes").show();
}
}
function open_invite_user_modal(e) {
e.stopPropagation();
e.preventDefault();
@ -247,6 +264,7 @@ function open_invite_user_modal(e) {
time_choices: time_unit_choices,
streams: get_invite_streams(),
notifications_stream: stream_data.get_notifications_stream(),
show_select_default_streams_option: stream_data.get_default_stream_ids().length !== 0,
});
function invite_user_modal_post_render() {
@ -256,6 +274,7 @@ function open_invite_user_modal(e) {
set_custom_time_inputs_visibility();
set_expires_on_text();
set_streams_to_join_list_visibility();
function toggle_invite_submit_button() {
$("#invite-user-modal .dialog_submit_button").prop(
@ -319,12 +338,16 @@ function open_invite_user_modal(e) {
});
$("#invite_check_all_button").on("click", () => {
$("#streams_to_add input[type=checkbox]").prop("checked", true);
$("#invite-stream-checkboxes input[type=checkbox]").prop("checked", true);
toggle_invite_submit_button();
});
$("#invite_uncheck_all_button").on("click", () => {
$("#streams_to_add input[type=checkbox]").prop("checked", false);
$("#invite-stream-checkboxes input[type=checkbox]").prop("checked", false);
});
$("#invite_select_default_streams").on("change", () => {
set_streams_to_join_list_visibility();
});
}

View File

@ -56,6 +56,15 @@
<div>
<label>{{t "Streams they should join" }}</label>
<div id="streams_to_add">
{{#if show_select_default_streams_option}}
<div class="select_default_streams new-style">
<label class="checkbox display-block">
<input type="checkbox" id="invite_select_default_streams" checked="checked" />
<span></span>
{{t 'Default streams for this organization'}}
</label>
</div>
{{/if}}
<div class="invite-stream-controls">
<button class="btn btn-link" type="button" id="invite_check_all_button">{{t "Check all" }}</button> |
<button class="btn btn-link" type="button" id="invite_uncheck_all_button">{{t "Uncheck all" }}</button>