2023-11-27 11:36:07 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
|
|
|
import * as dropdown_widget from "./dropdown_widget";
|
|
|
|
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-04-01 22:55:55 +02:00
|
|
|
export function setup_permissions_dropdown(group: UserGroup, for_group_creation: boolean): void {
|
|
|
|
let widget_name: string;
|
|
|
|
let default_id: number;
|
2023-11-27 11:36:07 +01:00
|
|
|
if (for_group_creation) {
|
|
|
|
widget_name = "new_group_can_mention_group";
|
2024-04-01 22:55:55 +02:00
|
|
|
default_id = user_groups.get_user_group_from_name("role:everyone")!.id;
|
2023-11-27 11:36:07 +01:00
|
|
|
} else {
|
|
|
|
widget_name = "can_mention_group";
|
|
|
|
default_id = group.can_mention_group;
|
|
|
|
}
|
|
|
|
|
|
|
|
const can_mention_group_widget = new dropdown_widget.DropdownWidget({
|
|
|
|
widget_name,
|
|
|
|
get_options: () =>
|
|
|
|
user_groups.get_realm_user_groups_for_dropdown_list_widget(
|
|
|
|
"can_mention_group",
|
|
|
|
"group",
|
|
|
|
),
|
|
|
|
item_click_callback(event, dropdown) {
|
|
|
|
dropdown.hide();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
can_mention_group_widget.render();
|
|
|
|
if (!for_group_creation) {
|
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"),
|
|
|
|
tippy_props: {
|
|
|
|
placement: "bottom-start",
|
|
|
|
},
|
|
|
|
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");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (for_group_creation) {
|
|
|
|
settings_components.set_new_group_can_mention_group_widget(can_mention_group_widget);
|
|
|
|
} else {
|
2024-06-11 14:01:39 +02:00
|
|
|
settings_components.set_dropdown_setting_widget(
|
|
|
|
"can_mention_group",
|
|
|
|
can_mention_group_widget,
|
|
|
|
);
|
2023-11-27 11:36:07 +01:00
|
|
|
}
|
|
|
|
can_mention_group_widget.setup();
|
|
|
|
}
|