2021-08-23 10:44:19 +02:00
|
|
|
import Component from "@ember/component";
|
|
|
|
import { computed } from "@ember/object";
|
2023-10-10 19:38:59 +01:00
|
|
|
import { guidFor } from "@ember/object/internals";
|
2024-08-23 12:17:07 +01:00
|
|
|
import { tagName } from "@ember-decorators/component";
|
2021-08-23 10:44:19 +02:00
|
|
|
import UtilsMixin from "select-kit/mixins/utils";
|
|
|
|
|
2024-08-23 12:17:07 +01:00
|
|
|
@tagName("")
|
|
|
|
export default class SelectedChoice extends Component.extend(UtilsMixin) {
|
|
|
|
item = null;
|
|
|
|
selectKit = null;
|
|
|
|
extraClass = null;
|
|
|
|
id = null;
|
2021-08-23 10:44:19 +02:00
|
|
|
|
|
|
|
init() {
|
2024-08-23 12:17:07 +01:00
|
|
|
super.init(...arguments);
|
2021-08-23 10:44:19 +02:00
|
|
|
|
|
|
|
this.set("id", guidFor(this));
|
2024-08-23 12:17:07 +01:00
|
|
|
}
|
2021-08-23 10:44:19 +02:00
|
|
|
|
2024-08-23 12:17:07 +01:00
|
|
|
@computed("item")
|
|
|
|
get itemValue() {
|
2021-08-23 10:44:19 +02:00
|
|
|
return this.getValue(this.item);
|
2024-08-23 12:17:07 +01:00
|
|
|
}
|
2021-08-23 10:44:19 +02:00
|
|
|
|
2024-08-23 12:17:07 +01:00
|
|
|
@computed("item")
|
|
|
|
get itemName() {
|
2021-08-23 10:44:19 +02:00
|
|
|
return this.getName(this.item);
|
2024-08-23 12:17:07 +01:00
|
|
|
}
|
2024-04-18 08:53:52 +10:00
|
|
|
|
2024-08-23 12:17:07 +01:00
|
|
|
@computed("item")
|
|
|
|
get mandatoryValuesArray() {
|
2024-04-18 08:53:52 +10:00
|
|
|
return this.get("mandatoryValues")?.split("|") || [];
|
2024-08-23 12:17:07 +01:00
|
|
|
}
|
2024-04-18 08:53:52 +10:00
|
|
|
|
2024-08-23 12:17:07 +01:00
|
|
|
@computed("item")
|
|
|
|
get readOnly() {
|
2024-10-23 16:16:08 +11:00
|
|
|
if (typeof this.item === "string") {
|
|
|
|
return this.mandatoryValuesArray.includes(this.item);
|
|
|
|
}
|
2024-04-18 08:53:52 +10:00
|
|
|
return this.mandatoryValuesArray.includes(this.item.id);
|
2024-08-23 12:17:07 +01:00
|
|
|
}
|
|
|
|
}
|