2017-11-21 18:53:09 +08:00
|
|
|
const { get, isNone, guidFor } = Ember;
|
2017-11-10 02:57:53 +08:00
|
|
|
|
2017-10-20 03:51:08 +08:00
|
|
|
export default Ember.Mixin.create({
|
2017-11-21 18:53:09 +08:00
|
|
|
valueForContentItem(content) {
|
|
|
|
switch (typeof content) {
|
2018-06-15 23:03:24 +08:00
|
|
|
case "string":
|
|
|
|
case "number":
|
|
|
|
return content;
|
|
|
|
default:
|
2019-05-27 16:15:39 +08:00
|
|
|
return get(content, this.valueAttribute);
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-10 02:57:53 +08:00
|
|
|
_nameForContent(content) {
|
|
|
|
if (isNone(content)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof content === "object") {
|
2019-05-27 16:15:39 +08:00
|
|
|
return get(content, this.nameProperty);
|
2017-11-10 02:57:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
2017-11-14 10:51:19 +08:00
|
|
|
_isNumeric(input) {
|
|
|
|
return !isNaN(parseFloat(input)) && isFinite(input);
|
|
|
|
},
|
|
|
|
|
2018-06-26 18:19:14 +08:00
|
|
|
_normalize(input) {
|
|
|
|
input = input.toLowerCase();
|
|
|
|
|
|
|
|
if (typeof input.normalize === "function") {
|
|
|
|
input = input.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
return input;
|
|
|
|
},
|
|
|
|
|
2018-05-25 05:41:39 +08:00
|
|
|
_cast(value) {
|
|
|
|
if (value === this.noneValue) return value;
|
|
|
|
return this._castInteger(this._castBoolean(value));
|
|
|
|
},
|
|
|
|
|
|
|
|
_castBoolean(value) {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
2019-05-27 16:15:39 +08:00
|
|
|
this.castBoolean &&
|
2018-06-15 23:03:24 +08:00
|
|
|
Ember.isPresent(value) &&
|
|
|
|
typeof value === "string"
|
|
|
|
) {
|
2018-05-25 05:41:39 +08:00
|
|
|
return value === "true";
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
2017-10-20 03:51:08 +08:00
|
|
|
_castInteger(value) {
|
2019-05-27 16:42:53 +08:00
|
|
|
if (this.castInteger && Ember.isPresent(value) && this._isNumeric(value)) {
|
2017-10-20 03:51:08 +08:00
|
|
|
return parseInt(value, 10);
|
|
|
|
}
|
|
|
|
|
2017-11-10 02:57:53 +08:00
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
2017-11-21 18:53:09 +08:00
|
|
|
_findComputedContentItemByGuid(guid) {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (guidFor(this.createRowComputedContent) === guid) {
|
|
|
|
return this.createRowComputedContent;
|
2018-03-22 18:29:55 +08:00
|
|
|
}
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
if (guidFor(this.noneRowComputedContent) === guid) {
|
|
|
|
return this.noneRowComputedContent;
|
2018-03-22 18:29:55 +08:00
|
|
|
}
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
return this.collectionComputedContent.find(c => {
|
2017-11-21 18:53:09 +08:00
|
|
|
return guidFor(c) === guid;
|
2017-11-10 02:57:53 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-11-21 18:53:09 +08:00
|
|
|
_filterRemovableComputedContents(computedContent) {
|
2018-03-22 18:29:55 +08:00
|
|
|
return computedContent.filter(c => c.created);
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
2017-10-20 03:51:08 +08:00
|
|
|
});
|