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

51 lines
1.3 KiB
Plaintext
Raw Normal View History

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";
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",
content: alias("groups"),
2018-03-29 02:57:10 -04:00
tagName: "li",
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
@discourseComputed("content")
2018-03-29 02:57:10 -04:00
filterable(content) {
return content && content.length >= 10;
},
computeHeaderContent() {
let content = this._super(...arguments);
2018-03-29 02:57:10 -04:00
if (!this.hasSelection) {
2018-03-29 02:57:10 -04:00
content.label = `<span>${I18n.t("groups.index.all")}</span>`;
}
return content;
},
@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"))
) {
return `
<a href="${Discourse.getURL("/g")}" class="group-dropdown-filter">
${I18n.t("groups.index.all").toLowerCase()}
</a>
`.htmlSafe();
}
2018-03-29 02:57:10 -04:00
},
actions: {
onSelect(groupName) {
DiscourseURL.routeTo(Discourse.getURL(`/g/${groupName}`));
2018-03-29 02:57:10 -04:00
}
}
});