2020-02-03 08:22:14 -05:00
|
|
|
import { gte, reads } from "@ember/object/computed";
|
2018-03-29 02:57:10 -04:00
|
|
|
import ComboBoxComponent from "select-kit/components/combo-box";
|
|
|
|
import DiscourseURL from "discourse/lib/url";
|
2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2020-02-03 08:22:14 -05:00
|
|
|
import { computed } from "@ember/object";
|
|
|
|
import { setting } from "discourse/lib/computed";
|
2018-03-29 02:57:10 -04:00
|
|
|
|
|
|
|
export default ComboBoxComponent.extend({
|
|
|
|
pluginApiIdentifiers: ["group-dropdown"],
|
2020-02-03 08:22:14 -05:00
|
|
|
classNames: ["group-dropdown"],
|
|
|
|
content: reads("groupsWithShortcut"),
|
2018-03-29 02:57:10 -04:00
|
|
|
tagName: "li",
|
2020-02-03 08:22:14 -05:00
|
|
|
valueProperty: null,
|
|
|
|
nameProperty: null,
|
|
|
|
hasManyGroups: gte("content.length", 10),
|
|
|
|
enableGroupDirectory: setting("enable_group_directory"),
|
2018-03-29 02:57:10 -04:00
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
selectKitOptions: {
|
|
|
|
caretDownIcon: "caret-right",
|
|
|
|
caretUpIcon: "caret-down",
|
|
|
|
filterable: "hasManyGroups",
|
2018-03-29 02:57:10 -04:00
|
|
|
},
|
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
groupsWithShortcut: computed("groups.[]", function () {
|
|
|
|
const shortcuts = [];
|
2018-03-29 02:57:10 -04:00
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
if (this.enableGroupDirectory || this.get("currentUser.staff")) {
|
|
|
|
shortcuts.push(I18n.t("groups.index.all").toLowerCase());
|
2018-03-29 02:57:10 -04:00
|
|
|
}
|
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
return shortcuts.concat(this.groups);
|
|
|
|
}),
|
2018-03-29 02:57:10 -04:00
|
|
|
|
|
|
|
actions: {
|
2020-02-03 08:22:14 -05:00
|
|
|
onChange(groupName) {
|
|
|
|
if ((this.groups || []).includes(groupName)) {
|
|
|
|
DiscourseURL.routeToUrl(`/g/${groupName}`);
|
|
|
|
} else {
|
|
|
|
DiscourseURL.routeToUrl(`/g`);
|
|
|
|
}
|
2018-03-29 02:57:10 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|