2016-05-24 15:06:59 +03:00
|
|
|
import NavigationItem from 'ghost-admin/models/navigation-item';
|
2020-01-16 20:01:12 +03:00
|
|
|
import Transform from '@ember-data/serializer/transform';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {A as emberA, isArray as isEmberArray} from '@ember/array';
|
2016-04-26 12:45:59 +03:00
|
|
|
|
|
|
|
export default Transform.extend({
|
2019-12-04 07:14:45 +03:00
|
|
|
deserialize(serialized, options) {
|
2016-04-26 12:45:59 +03:00
|
|
|
let navItems, settingsArray;
|
|
|
|
|
|
|
|
try {
|
|
|
|
settingsArray = JSON.parse(serialized) || [];
|
|
|
|
} catch (e) {
|
|
|
|
settingsArray = [];
|
|
|
|
}
|
|
|
|
|
2019-12-04 07:14:45 +03:00
|
|
|
navItems = settingsArray.map((itemDetails) => {
|
|
|
|
itemDetails.isSecondary = options && options.isSecondary || false;
|
|
|
|
return NavigationItem.create(itemDetails);
|
|
|
|
});
|
2016-04-26 12:45:59 +03:00
|
|
|
|
|
|
|
return emberA(navItems);
|
|
|
|
},
|
|
|
|
|
|
|
|
serialize(deserialized) {
|
|
|
|
let settingsArray;
|
|
|
|
|
2016-06-30 13:21:47 +03:00
|
|
|
if (isEmberArray(deserialized)) {
|
2016-04-26 12:45:59 +03:00
|
|
|
settingsArray = deserialized.map((item) => {
|
|
|
|
let label = item.get('label').trim();
|
|
|
|
let url = item.get('url').trim();
|
|
|
|
|
|
|
|
return {label, url};
|
|
|
|
}).compact();
|
|
|
|
} else {
|
|
|
|
settingsArray = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return JSON.stringify(settingsArray);
|
|
|
|
}
|
|
|
|
});
|