2019-11-09 00:32:20 +08:00
|
|
|
import { alias } 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";
|
2020-01-17 01:56:53 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2018-03-29 14:57:10 +08:00
|
|
|
|
|
|
|
export default ComboBoxComponent.extend({
|
|
|
|
pluginApiIdentifiers: ["group-dropdown"],
|
|
|
|
classNames: "group-dropdown",
|
2019-11-09 00:32:20 +08:00
|
|
|
content: alias("groups"),
|
2018-03-29 14:57:10 +08:00
|
|
|
tagName: "li",
|
2018-04-12 16:56:32 +08:00
|
|
|
caretDownIcon: "caret-right",
|
|
|
|
caretUpIcon: "caret-down",
|
2018-03-29 14:57:10 +08:00
|
|
|
allowAutoSelectFirst: false,
|
2018-06-15 23:03:24 +08:00
|
|
|
valueAttribute: "name",
|
2018-03-29 14:57:10 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("content")
|
2018-03-29 14:57:10 +08:00
|
|
|
filterable(content) {
|
|
|
|
return content && content.length >= 10;
|
|
|
|
},
|
|
|
|
|
|
|
|
computeHeaderContent() {
|
2019-01-19 17:05:51 +08:00
|
|
|
let content = this._super(...arguments);
|
2018-03-29 14:57:10 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
if (!this.hasSelection) {
|
2018-03-29 14:57:10 +08:00
|
|
|
content.label = `<span>${I18n.t("groups.index.all")}</span>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed
|
2018-03-29 14:57:10 +08:00
|
|
|
collectionHeader() {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
this.siteSettings.enable_group_directory ||
|
|
|
|
(this.currentUser && this.currentUser.get("staff"))
|
|
|
|
) {
|
2018-05-28 11:32:55 +08:00
|
|
|
return `
|
2019-02-21 13:44:25 +08:00
|
|
|
<a href="${Discourse.getURL("/g")}" class="group-dropdown-filter">
|
2018-05-28 11:32:55 +08:00
|
|
|
${I18n.t("groups.index.all").toLowerCase()}
|
|
|
|
</a>
|
|
|
|
`.htmlSafe();
|
|
|
|
}
|
2018-03-29 14:57:10 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
onSelect(groupName) {
|
2019-02-21 13:44:25 +08:00
|
|
|
DiscourseURL.routeTo(Discourse.getURL(`/g/${groupName}`));
|
2018-03-29 14:57:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|