2017-11-21 05:53:09 -05:00
|
|
|
const { get, isNone, guidFor } = Ember;
|
2017-11-09 13:57:53 -05:00
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
export default Ember.Mixin.create({
|
2017-11-21 05:53:09 -05:00
|
|
|
valueForContentItem(content) {
|
|
|
|
switch (typeof content) {
|
|
|
|
case "string":
|
|
|
|
case "number":
|
|
|
|
return content;
|
|
|
|
default:
|
|
|
|
return get(content, this.get("valueAttribute"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-09 13:57:53 -05:00
|
|
|
_nameForContent(content) {
|
|
|
|
if (isNone(content)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof content === "object") {
|
|
|
|
return get(content, this.get("nameProperty"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
2017-11-13 21:51:19 -05:00
|
|
|
_isNumeric(input) {
|
|
|
|
return !isNaN(parseFloat(input)) && isFinite(input);
|
|
|
|
},
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
_castInteger(value) {
|
2017-11-22 07:40:22 -05:00
|
|
|
if (this.get("castInteger") && Ember.isPresent(value) && this._isNumeric(value)) {
|
2017-10-19 15:51:08 -04:00
|
|
|
return parseInt(value, 10);
|
|
|
|
}
|
|
|
|
|
2017-11-09 13:57:53 -05:00
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
2017-11-21 05:53:09 -05:00
|
|
|
_findComputedContentItemByGuid(guid) {
|
2017-11-09 13:57:53 -05:00
|
|
|
return this.get("computedContent").find(c => {
|
2017-11-21 05:53:09 -05:00
|
|
|
return guidFor(c) === guid;
|
2017-11-09 13:57:53 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-11-21 05:53:09 -05:00
|
|
|
_filterRemovableComputedContents(computedContent) {
|
|
|
|
return computedContent.filter(c => c.created === true);
|
|
|
|
}
|
2017-10-19 15:51:08 -04:00
|
|
|
});
|