2023-11-27 11:36:07 +01:00
|
|
|
import $ from "jquery";
|
2024-07-01 22:48:21 +02:00
|
|
|
import assert from "minimalistic-assert";
|
2023-11-27 11:36:07 +01:00
|
|
|
|
|
|
|
import * as dropdown_widget from "./dropdown_widget";
|
2023-08-04 16:07:18 +02:00
|
|
|
import * as group_permission_settings from "./group_permission_settings";
|
2024-05-18 04:51:36 +02:00
|
|
|
import {$t_html} from "./i18n";
|
2023-11-27 11:36:07 +01:00
|
|
|
import * as settings_components from "./settings_components";
|
|
|
|
import * as user_groups from "./user_groups";
|
2024-04-01 22:55:55 +02:00
|
|
|
import type {UserGroup} from "./user_groups";
|
2023-11-27 11:36:07 +01:00
|
|
|
|
2024-05-18 04:51:36 +02:00
|
|
|
export let active_group_id: number | undefined;
|
|
|
|
|
2024-08-26 05:54:48 +02:00
|
|
|
type group_setting = "can_mention_group";
|
2024-07-01 22:48:21 +02:00
|
|
|
export function setup_permissions_dropdown(
|
2023-08-04 16:07:18 +02:00
|
|
|
setting_name: group_setting,
|
2024-07-01 22:48:21 +02:00
|
|
|
group: UserGroup | undefined,
|
|
|
|
for_group_creation: boolean,
|
|
|
|
): void {
|
2024-04-01 22:55:55 +02:00
|
|
|
let widget_name: string;
|
|
|
|
let default_id: number;
|
2023-11-27 11:36:07 +01:00
|
|
|
if (for_group_creation) {
|
2023-08-04 16:07:18 +02:00
|
|
|
widget_name = "new_group_" + setting_name;
|
|
|
|
const group_setting_config = group_permission_settings.get_group_permission_setting_config(
|
|
|
|
setting_name,
|
|
|
|
"group",
|
|
|
|
)!;
|
|
|
|
const default_group_name = group_setting_config.default_group_name;
|
|
|
|
default_id = user_groups.get_user_group_from_name(default_group_name)!.id;
|
2023-11-27 11:36:07 +01:00
|
|
|
} else {
|
2024-07-01 22:48:21 +02:00
|
|
|
assert(group !== undefined);
|
2023-08-04 16:07:18 +02:00
|
|
|
widget_name = setting_name;
|
|
|
|
default_id = group[setting_name];
|
2023-11-27 11:36:07 +01:00
|
|
|
}
|
|
|
|
|
2023-08-04 16:07:18 +02:00
|
|
|
const group_setting_widget = new dropdown_widget.DropdownWidget({
|
2023-11-27 11:36:07 +01:00
|
|
|
widget_name,
|
|
|
|
get_options: () =>
|
2023-08-04 16:07:18 +02:00
|
|
|
user_groups.get_realm_user_groups_for_dropdown_list_widget(setting_name, "group"),
|
2023-11-27 11:36:07 +01:00
|
|
|
item_click_callback(event, dropdown) {
|
|
|
|
dropdown.hide();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2023-08-04 16:07:18 +02:00
|
|
|
group_setting_widget.render();
|
2023-11-27 11:36:07 +01:00
|
|
|
if (!for_group_creation) {
|
2024-07-01 22:48:21 +02:00
|
|
|
assert(group !== undefined);
|
2024-05-20 21:36:38 +02:00
|
|
|
settings_components.save_discard_group_widget_status_handler(
|
2023-11-27 11:36:07 +01:00
|
|
|
$("#group_permission_settings"),
|
|
|
|
group,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
$events_container: $("#groups_overlay .group-permissions"),
|
|
|
|
default_id,
|
2024-02-19 14:22:38 +01:00
|
|
|
unique_id_type: dropdown_widget.DataTypes.NUMBER,
|
2023-11-27 11:36:07 +01:00
|
|
|
on_mount_callback(dropdown) {
|
|
|
|
$(dropdown.popper).css("min-width", "300px");
|
2024-07-04 16:55:23 +02:00
|
|
|
$(dropdown.popper).find(".simplebar-content").css("width", "max-content");
|
2023-11-27 11:36:07 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
if (for_group_creation) {
|
2024-08-26 05:54:48 +02:00
|
|
|
settings_components.set_new_group_can_mention_group_widget(group_setting_widget);
|
2023-11-27 11:36:07 +01:00
|
|
|
} else {
|
2023-08-04 16:07:18 +02:00
|
|
|
settings_components.set_dropdown_setting_widget(setting_name, group_setting_widget);
|
2023-11-27 11:36:07 +01:00
|
|
|
}
|
2023-08-04 16:07:18 +02:00
|
|
|
group_setting_widget.setup();
|
2023-11-27 11:36:07 +01:00
|
|
|
}
|
2024-05-18 04:51:36 +02:00
|
|
|
|
|
|
|
export function set_active_group_id(group_id: number): void {
|
|
|
|
active_group_id = group_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reset_active_group_id(): void {
|
|
|
|
active_group_id = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const show_user_group_settings_pane = {
|
|
|
|
nothing_selected() {
|
|
|
|
$("#groups_overlay .settings, #user-group-creation").hide();
|
|
|
|
reset_active_group_id();
|
|
|
|
$("#groups_overlay .nothing-selected").show();
|
|
|
|
$("#groups_overlay .user-group-info-title").text(
|
|
|
|
$t_html({defaultMessage: "User group settings"}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
settings(group: UserGroup) {
|
|
|
|
$("#groups_overlay .nothing-selected, #user-group-creation").hide();
|
|
|
|
$("#groups_overlay .settings").show();
|
|
|
|
set_active_group_id(group.id);
|
|
|
|
$("#groups_overlay .user-group-info-title").text(group.name);
|
|
|
|
},
|
2024-07-01 22:48:21 +02:00
|
|
|
create_user_group(container_name = "configure_user_group_settings", group_name?: string) {
|
2024-05-09 21:56:09 +02:00
|
|
|
$(".user_group_creation").hide();
|
|
|
|
if (container_name === "configure_user_group_settings") {
|
|
|
|
$("#groups_overlay .user-group-info-title").text(
|
2024-06-18 21:05:52 +02:00
|
|
|
$t_html({defaultMessage: "Configure new group settings"}),
|
2024-05-09 21:56:09 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$("#groups_overlay .user-group-info-title").text(
|
2024-06-18 21:05:52 +02:00
|
|
|
$t_html({defaultMessage: "Add members to {group_name}"}, {group_name}),
|
2024-05-09 21:56:09 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
update_footer_buttons(container_name);
|
|
|
|
$(`.${container_name}`).show();
|
2024-05-18 04:51:36 +02:00
|
|
|
$("#groups_overlay .nothing-selected, #groups_overlay .settings").hide();
|
|
|
|
reset_active_group_id();
|
|
|
|
$("#user-group-creation").show();
|
|
|
|
},
|
|
|
|
};
|
2024-05-09 21:56:09 +02:00
|
|
|
|
|
|
|
export function update_footer_buttons(container_name: string): void {
|
|
|
|
if (container_name === "user_group_members_container") {
|
|
|
|
// Hide user group creation containers and show add members container
|
|
|
|
$("#groups_overlay .finalize_create_user_group").show();
|
|
|
|
$("#groups_overlay #user_group_go_to_members").hide();
|
|
|
|
$("#groups_overlay #user_group_go_to_configure_settings").show();
|
|
|
|
} else {
|
|
|
|
// Hide add members container and show user group creation containers
|
|
|
|
$("#groups_overlay .finalize_create_user_group").hide();
|
|
|
|
$("#groups_overlay #user_group_go_to_members").show();
|
|
|
|
$("#groups_overlay #user_group_go_to_configure_settings").hide();
|
|
|
|
}
|
|
|
|
}
|