2017-11-21 18:53:09 +08:00
|
|
|
import SelectKitComponent from "select-kit/components/select-kit";
|
2020-02-03 21:22:14 +08:00
|
|
|
import { computed } from "@ember/object";
|
|
|
|
import { isEmpty } from "@ember/utils";
|
2017-11-21 18:53:09 +08:00
|
|
|
|
|
|
|
export default SelectKitComponent.extend({
|
|
|
|
pluginApiIdentifiers: ["single-select"],
|
2018-02-26 18:42:57 +08:00
|
|
|
layoutName: "select-kit/templates/components/single-select",
|
2020-02-03 21:22:14 +08:00
|
|
|
classNames: ["single-select"],
|
|
|
|
singleSelect: true,
|
2018-03-22 18:29:55 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
selectKitOptions: {
|
|
|
|
headerComponent: "select-kit/single-select-header"
|
2017-11-21 18:53:09 +08:00
|
|
|
},
|
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
selectedContent: computed("value", "content.[]", function() {
|
|
|
|
if (!isEmpty(this.value)) {
|
|
|
|
let content;
|
2018-03-22 18:29:55 +08:00
|
|
|
|
2020-02-14 17:00:40 +08:00
|
|
|
const value =
|
|
|
|
this.selectKit.options.castInteger && this._isNumeric(this.value)
|
|
|
|
? Number(this.value)
|
|
|
|
: this.value;
|
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
if (this.selectKit.valueProperty) {
|
|
|
|
content = (this.content || []).findBy(
|
|
|
|
this.selectKit.valueProperty,
|
2020-02-14 17:00:40 +08:00
|
|
|
value
|
2018-03-22 18:29:55 +08:00
|
|
|
);
|
2020-02-14 17:00:40 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
return this.selectKit.modifySelection(
|
2020-02-14 17:00:40 +08:00
|
|
|
content || this.defaultItem(value, value)
|
2019-12-05 02:33:51 +08:00
|
|
|
);
|
2020-02-03 21:22:14 +08:00
|
|
|
} else {
|
|
|
|
return this.selectKit.modifySelection(
|
2020-02-14 17:00:40 +08:00
|
|
|
(this.content || []).filter(c => c === value)
|
2020-02-03 21:22:14 +08:00
|
|
|
);
|
|
|
|
}
|
2018-03-22 18:29:55 +08:00
|
|
|
} else {
|
2020-02-03 21:22:14 +08:00
|
|
|
return this.selectKit.noneItem;
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
2020-02-03 21:22:14 +08:00
|
|
|
})
|
2017-11-21 18:53:09 +08:00
|
|
|
});
|