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"],
|
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-06-09 05:10:26 +08:00
|
|
|
selectedContent: computed(
|
|
|
|
"value",
|
|
|
|
"content.[]",
|
|
|
|
"selectKit.noneItem",
|
|
|
|
function () {
|
|
|
|
if (!isEmpty(this.value)) {
|
|
|
|
let content;
|
2018-03-22 18:29:55 +08:00
|
|
|
|
2020-06-09 05:10:26 +08:00
|
|
|
const value =
|
|
|
|
this.selectKit.options.castInteger && this._isNumeric(this.value)
|
|
|
|
? Number(this.value)
|
|
|
|
: this.value;
|
2020-02-14 17:00:40 +08:00
|
|
|
|
2020-06-09 05:10:26 +08:00
|
|
|
if (this.selectKit.valueProperty) {
|
|
|
|
content = (this.content || []).findBy(
|
|
|
|
this.selectKit.valueProperty,
|
|
|
|
value
|
|
|
|
);
|
2020-02-14 17:00:40 +08:00
|
|
|
|
2020-06-09 05:10:26 +08:00
|
|
|
return this.selectKit.modifySelection(
|
|
|
|
content || this.defaultItem(value, value)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return this.selectKit.modifySelection(
|
|
|
|
(this.content || []).filter((c) => c === value)
|
|
|
|
);
|
|
|
|
}
|
2020-02-03 21:22:14 +08:00
|
|
|
} else {
|
2020-06-09 05:10:26 +08:00
|
|
|
return this.selectKit.noneItem;
|
2020-02-03 21:22:14 +08:00
|
|
|
}
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
2020-06-09 05:10:26 +08:00
|
|
|
),
|
2017-11-21 18:53:09 +08:00
|
|
|
});
|