2019-10-23 12:30:52 -04:00
|
|
|
import Component from "@ember/component";
|
2019-11-07 16:38:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2019-10-23 12:30:52 -04:00
|
|
|
export default Component.extend({
|
2017-11-21 05:53:09 -05:00
|
|
|
attributeBindings: [
|
|
|
|
"tabindex",
|
2017-12-22 07:08:12 -05:00
|
|
|
"ariaLabel:aria-label",
|
|
|
|
"title",
|
|
|
|
"name:data-name",
|
|
|
|
"value:data-value",
|
2017-11-21 05:53:09 -05:00
|
|
|
"guid:data-guid"
|
|
|
|
],
|
|
|
|
classNames: ["selected-name", "choice"],
|
2017-11-09 13:57:53 -05:00
|
|
|
classNameBindings: ["isHighlighted", "isLocked"],
|
2017-11-21 05:53:09 -05:00
|
|
|
layoutName: "select-kit/templates/components/multi-select/selected-name",
|
2017-11-26 11:21:39 -05:00
|
|
|
tagName: "span",
|
2017-11-09 13:57:53 -05:00
|
|
|
tabindex: -1,
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("computedContent")
|
2018-06-15 11:03:24 -04:00
|
|
|
guid(computedContent) {
|
|
|
|
return Ember.guidFor(computedContent);
|
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-12-22 07:08:12 -05:00
|
|
|
ariaLabel: Ember.computed.or("computedContent.ariaLabel", "title"),
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("computedContent.title", "name")
|
2017-12-22 07:08:12 -05:00
|
|
|
title(computedContentTitle, name) {
|
|
|
|
if (computedContentTitle) return computedContentTitle;
|
|
|
|
if (name) return name;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
label: Ember.computed.or("computedContent.label", "title", "name"),
|
|
|
|
|
|
|
|
name: Ember.computed.alias("computedContent.name"),
|
|
|
|
|
|
|
|
value: Ember.computed.alias("computedContent.value"),
|
|
|
|
|
|
|
|
isLocked: Ember.computed("computedContent.locked", function() {
|
|
|
|
return this.getWithDefault("computedContent.locked", false);
|
2017-11-09 13:57:53 -05:00
|
|
|
}),
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("computedContent", "highlightedSelection.[]")
|
2018-03-22 06:29:55 -04:00
|
|
|
isHighlighted(computedContent, highlightedSelection) {
|
2019-05-27 04:15:39 -04:00
|
|
|
return highlightedSelection.includes(this.computedContent);
|
2018-02-26 05:42:57 -05:00
|
|
|
},
|
|
|
|
|
2018-03-22 06:29:55 -04:00
|
|
|
click() {
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.isLocked) return false;
|
|
|
|
this.onClickSelectionItem([this.computedContent]);
|
2018-03-22 06:29:55 -04:00
|
|
|
return false;
|
2017-11-09 13:57:53 -05:00
|
|
|
}
|
|
|
|
});
|