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