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-10 15:03:03 +05:30
committed by Tim Abbott
parent f6f5697ccb
commit ad27f38d93
2 changed files with 39 additions and 7 deletions

View File

@@ -47,11 +47,17 @@ function get_common_invitation_data() {
expires_in = Number.parseFloat($("#expires_in").val()); 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 () { $("#invite-stream-checkboxes input:checked").each(function () {
const stream_id = Number.parseInt($(this).val(), 10); const stream_id = Number.parseInt($(this).val(), 10);
stream_ids.push(stream_id); stream_ids.push(stream_id);
}); });
}
const data = { const data = {
csrfmiddlewaretoken: $('input[name="csrfmiddlewaretoken"]').attr("value"), csrfmiddlewaretoken: $('input[name="csrfmiddlewaretoken"]').attr("value"),
invite_as, invite_as,
@@ -185,9 +191,11 @@ function update_subscription_checkboxes() {
const data = { const data = {
streams: get_invite_streams(), streams: get_invite_streams(),
notifications_stream: stream_data.get_notifications_stream(), notifications_stream: stream_data.get_notifications_stream(),
show_select_default_streams_option: stream_data.get_default_stream_ids().length !== 0,
}; };
const html = render_invite_subscription(data); const html = render_invite_subscription(data);
$("#streams_to_add").html(html); $("#streams_to_add").html(html);
set_streams_to_join_list_visibility();
} }
function prepare_form_to_be_shown() { function prepare_form_to_be_shown() {
@@ -270,6 +278,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();
}
}
export function initialize() { export function initialize() {
const time_unit_choices = ["minutes", "hours", "days", "weeks"]; const time_unit_choices = ["minutes", "hours", "days", "weeks"];
const rendered = render_invite_user({ const rendered = render_invite_user({
@@ -286,11 +305,15 @@ export function initialize() {
set_expires_on_text(); set_expires_on_text();
$(document).on("click", "#invite_check_all_button", () => { $(document).on("click", "#invite_check_all_button", () => {
$("#streams_to_add :checkbox").prop("checked", true); $("#invite-stream-checkboxes :checkbox").prop("checked", true);
}); });
$(document).on("click", "#invite_uncheck_all_button", () => { $(document).on("click", "#invite_uncheck_all_button", () => {
$("#streams_to_add :checkbox").prop("checked", false); $("#invite-stream-checkboxes :checkbox").prop("checked", false);
});
$(document).on("change", "#invite_select_default_streams", () => {
set_streams_to_join_list_visibility();
}); });
$("#submit-invitation").on("click", () => { $("#submit-invitation").on("click", () => {

View File

@@ -1,4 +1,13 @@
{{! Client-side Mustache template for rendering subscriptions in the "invite user" form.}} {{! Client-side Mustache template for rendering subscriptions in the "invite user" form.}}
{{#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"> <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_check_all_button">{{t "Check all" }}</button> |
<button class="btn btn-link" type="button" id="invite_uncheck_all_button">{{t "Uncheck all" }}</button> <button class="btn btn-link" type="button" id="invite_uncheck_all_button">{{t "Uncheck all" }}</button>