discourse/app/assets/javascripts/select-kit/addon/components/group-dropdown.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.2 KiB
JavaScript
Raw Normal View History

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