2017-11-21 18:53:09 +08:00
|
|
|
import MultiSelectComponent from "select-kit/components/multi-select";
|
2018-03-22 18:29:55 +08:00
|
|
|
const { isNone, makeArray } = Ember;
|
2017-11-21 18:53:09 +08:00
|
|
|
|
|
|
|
export default MultiSelectComponent.extend({
|
|
|
|
pluginApiIdentifiers: ["list-setting"],
|
|
|
|
classNames: "list-setting",
|
|
|
|
tokenSeparator: "|",
|
|
|
|
settingValue: "",
|
|
|
|
choices: null,
|
|
|
|
filterable: true,
|
|
|
|
|
|
|
|
init() {
|
2019-01-19 17:05:51 +08:00
|
|
|
this._super(...arguments);
|
2017-11-21 18:53:09 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
if (!isNone(this.settingName)) {
|
|
|
|
this.set("nameProperty", this.settingName);
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.nameProperty.indexOf("color") > -1) {
|
|
|
|
this.headerComponentOptions.setProperties({
|
2018-09-12 18:19:04 +08:00
|
|
|
selectedNameComponent: "multi-select/selected-color"
|
|
|
|
});
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computeContent() {
|
|
|
|
let content;
|
2019-05-27 16:15:39 +08:00
|
|
|
if (isNone(this.choices)) {
|
|
|
|
content = this.settingValue.split(this.tokenSeparator);
|
2018-06-15 23:03:24 +08:00
|
|
|
} else {
|
2019-05-27 16:15:39 +08:00
|
|
|
content = this.choices;
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
|
|
|
|
2018-03-22 18:29:55 +08:00
|
|
|
return makeArray(content).filter(c => c);
|
2017-11-21 18:53:09 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
mutateValues(values) {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("settingValue", values.join(this.tokenSeparator));
|
2017-11-21 18:53:09 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
computeValues() {
|
2019-05-27 16:42:53 +08:00
|
|
|
return this.settingValue.split(this.tokenSeparator).filter(c => c);
|
2017-11-21 18:53:09 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
_handleTabOnKeyDown(event) {
|
|
|
|
if (this.$highlightedRow().length === 1) {
|
|
|
|
this._super(event);
|
|
|
|
} else {
|
|
|
|
this.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|