2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-06-20 06:29:49 +04:00
|
|
|
import ApplicationSerializer from 'ghost/serializers/application';
|
|
|
|
|
2015-08-19 14:55:40 +03:00
|
|
|
export default ApplicationSerializer.extend({
|
2014-06-20 06:29:49 +04:00
|
|
|
serializeIntoHash: function (hash, type, record, options) {
|
|
|
|
// Settings API does not want ids
|
|
|
|
options = options || {};
|
|
|
|
options.includeId = false;
|
|
|
|
|
2015-06-03 05:56:42 +03:00
|
|
|
var root = Ember.String.pluralize(type.modelName),
|
2014-06-20 06:29:49 +04:00
|
|
|
data = this.serialize(record, options),
|
|
|
|
payload = [];
|
|
|
|
|
|
|
|
delete data.id;
|
|
|
|
|
|
|
|
Object.keys(data).forEach(function (k) {
|
2014-10-25 01:09:50 +04:00
|
|
|
payload.push({key: k, value: data[k]});
|
2014-06-20 06:29:49 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
hash[root] = payload;
|
|
|
|
},
|
|
|
|
|
2015-09-03 14:06:50 +03:00
|
|
|
normalizeArrayResponse: function (store, primaryModelClass, _payload, id, requestType) {
|
|
|
|
var payload = {settings: [this._extractObjectFromArrayPayload(_payload)]};
|
|
|
|
return this._super(store, primaryModelClass, payload, id, requestType);
|
|
|
|
},
|
|
|
|
|
|
|
|
normalizeSingleResponse: function (store, primaryModelClass, _payload, id, requestType) {
|
|
|
|
var payload = {setting: this._extractObjectFromArrayPayload(_payload)};
|
|
|
|
return this._super(store, primaryModelClass, payload, id, requestType);
|
|
|
|
},
|
|
|
|
|
|
|
|
_extractObjectFromArrayPayload: function (_payload) {
|
2014-10-25 01:09:50 +04:00
|
|
|
var payload = {id: '0'};
|
2014-06-20 06:29:49 +04:00
|
|
|
|
|
|
|
_payload.settings.forEach(function (setting) {
|
|
|
|
payload[setting.key] = setting.value;
|
|
|
|
});
|
|
|
|
|
2015-09-03 14:06:50 +03:00
|
|
|
return payload;
|
2014-06-20 06:29:49 +04:00
|
|
|
}
|
|
|
|
});
|