2022-08-21 16:34:56 +02:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2022-08-21 16:37:32 +02:00
|
|
|
import render_browse_user_groups_list_item from "../templates/user_group_settings/browse_user_groups_list_item.hbs";
|
2022-08-21 16:34:56 +02:00
|
|
|
import render_user_group_settings_overlay from "../templates/user_group_settings/user_group_settings_overlay.hbs";
|
|
|
|
|
|
|
|
import * as browser_history from "./browser_history";
|
2022-08-21 17:59:39 +02:00
|
|
|
import {$t} from "./i18n";
|
2022-08-21 16:37:32 +02:00
|
|
|
import * as ListWidget from "./list_widget";
|
2022-08-21 16:34:56 +02:00
|
|
|
import * as overlays from "./overlays";
|
2022-08-21 16:37:32 +02:00
|
|
|
import * as people from "./people";
|
2022-07-09 16:37:13 +02:00
|
|
|
import * as settings_data from "./settings_data";
|
2022-08-21 16:34:56 +02:00
|
|
|
import * as ui from "./ui";
|
2022-08-21 17:59:39 +02:00
|
|
|
import * as user_group_create from "./user_group_create";
|
2022-08-21 16:37:32 +02:00
|
|
|
import * as user_groups from "./user_groups";
|
2022-08-21 16:34:56 +02:00
|
|
|
|
2022-08-21 16:43:08 +02:00
|
|
|
export function set_up_click_handlers() {
|
|
|
|
$("#groups_overlay").on("click", ".left #clear_search_group_name", (e) => {
|
|
|
|
const $input = $("#groups_overlay .left #search_group_name");
|
|
|
|
$input.val("");
|
|
|
|
|
|
|
|
// This is a hack to rerender complete
|
|
|
|
// stream list once the text is cleared.
|
|
|
|
$input.trigger("input");
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-21 17:59:39 +02:00
|
|
|
export const show_user_group_settings_pane = {
|
|
|
|
nothing_selected() {
|
|
|
|
$(".settings, #user-group-creation").hide();
|
|
|
|
$(".nothing-selected").show();
|
|
|
|
$("#groups_overlay .user-group-info-title").text(
|
|
|
|
$t({defaultMessage: "User group settings"}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
create_user_group() {
|
|
|
|
$(".nothing-selected, .settings, #user-group-creation").hide();
|
|
|
|
$("#user-group-creation").show();
|
|
|
|
$("#groups_overlay .user-group-info-title").text($t({defaultMessage: "Create user group"}));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export function open_create_user_group() {
|
|
|
|
user_group_create.create_user_group_clicked();
|
|
|
|
browser_history.update("#groups/new");
|
|
|
|
}
|
|
|
|
|
2022-08-21 16:34:56 +02:00
|
|
|
export function setup_page(callback) {
|
|
|
|
function populate_and_fill() {
|
2022-07-09 16:37:13 +02:00
|
|
|
const template_data = {
|
|
|
|
can_create_or_edit_user_groups: settings_data.user_can_edit_user_groups(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const rendered = render_user_group_settings_overlay(template_data);
|
2022-08-21 16:34:56 +02:00
|
|
|
|
|
|
|
const $manage_groups_container = ui.get_content_element($("#manage_groups_container"));
|
|
|
|
$manage_groups_container.empty();
|
|
|
|
$manage_groups_container.append(rendered);
|
|
|
|
|
2022-08-21 16:37:32 +02:00
|
|
|
const $container = $("#manage_groups_container .user-groups-list");
|
|
|
|
const user_groups_list = user_groups.get_realm_user_groups();
|
|
|
|
|
|
|
|
ListWidget.create($container, user_groups_list, {
|
|
|
|
name: "user-groups-overlay",
|
|
|
|
modifier(item) {
|
|
|
|
item.is_member = user_groups.is_direct_member_of(
|
|
|
|
people.my_current_user_id(),
|
|
|
|
item.id,
|
|
|
|
);
|
|
|
|
return render_browse_user_groups_list_item(item);
|
|
|
|
},
|
2022-08-21 16:43:08 +02:00
|
|
|
filter: {
|
|
|
|
$element: $("#manage_groups_container .left #search_group_name"),
|
|
|
|
predicate(item, value) {
|
|
|
|
return (
|
|
|
|
item &&
|
|
|
|
(item.name.toLocaleLowerCase().includes(value) ||
|
|
|
|
item.description.toLocaleLowerCase().includes(value))
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2022-08-21 16:37:32 +02:00
|
|
|
$simplebar_container: $container,
|
|
|
|
});
|
|
|
|
|
2022-08-21 16:43:08 +02:00
|
|
|
set_up_click_handlers();
|
2022-08-21 17:59:39 +02:00
|
|
|
user_group_create.set_up_handlers();
|
2022-08-21 16:43:08 +02:00
|
|
|
|
2022-07-09 16:37:13 +02:00
|
|
|
// show the "User group settings" header by default.
|
|
|
|
$(".display-type #user_group_settings_title").show();
|
|
|
|
|
2022-08-21 16:34:56 +02:00
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
populate_and_fill();
|
|
|
|
}
|
|
|
|
|
2022-08-21 17:59:39 +02:00
|
|
|
export function initialize() {
|
|
|
|
$("#manage_groups_container").on("click", ".create_user_group_button", (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
open_create_user_group();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-21 16:34:56 +02:00
|
|
|
export function launch() {
|
|
|
|
setup_page(() => {
|
|
|
|
overlays.open_overlay({
|
|
|
|
name: "group_subscriptions",
|
|
|
|
$overlay: $("#groups_overlay"),
|
|
|
|
on_close() {
|
|
|
|
browser_history.exit_overlay();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|