2016-03-29 11:40:44 +03:00
|
|
|
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
|
|
|
|
import Ember from 'ember';
|
|
|
|
import Transform from 'ember-data/transform';
|
2016-05-24 15:06:59 +03:00
|
|
|
import SlackObject from 'ghost-admin/models/slack-integration';
|
2016-03-29 11:40:44 +03:00
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
const {
|
|
|
|
isArray,
|
|
|
|
A: emberA
|
|
|
|
} = Ember;
|
2016-03-29 11:40:44 +03:00
|
|
|
|
|
|
|
export default Transform.extend({
|
|
|
|
deserialize(serialized) {
|
|
|
|
let slackObj, settingsArray;
|
|
|
|
try {
|
|
|
|
settingsArray = JSON.parse(serialized) || [];
|
|
|
|
} catch (e) {
|
|
|
|
settingsArray = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
slackObj = settingsArray.map((itemDetails) => {
|
|
|
|
return SlackObject.create(itemDetails);
|
|
|
|
});
|
|
|
|
return emberA(slackObj);
|
|
|
|
},
|
|
|
|
|
|
|
|
serialize(deserialized) {
|
|
|
|
let settingsArray;
|
|
|
|
if (isArray(deserialized)) {
|
|
|
|
settingsArray = deserialized.map((item) => {
|
|
|
|
let url = (item.get('url') || '').trim();
|
|
|
|
|
|
|
|
return {url};
|
|
|
|
}).compact();
|
|
|
|
} else {
|
|
|
|
settingsArray = [];
|
|
|
|
}
|
|
|
|
return JSON.stringify(settingsArray);
|
|
|
|
}
|
|
|
|
});
|