mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
refs #2606 - Use new API format when updating settings from the client side - Add additional test to test new API format - Adjust functional tests to work with the new format
33 lines
1 KiB
JavaScript
33 lines
1 KiB
JavaScript
/*global Backbone, Ghost, _ */
|
|
(function () {
|
|
'use strict';
|
|
//id:0 is used to issue PUT requests
|
|
Ghost.Models.Settings = Ghost.ProgressModel.extend({
|
|
url: Ghost.paths.apiRoot + '/settings/?type=blog,theme,app',
|
|
id: '0',
|
|
|
|
parse: function (response) {
|
|
var result = _.reduce(response.settings, function (settings, setting) {
|
|
settings[setting.key] = setting.value;
|
|
|
|
return settings;
|
|
}, {});
|
|
|
|
return result;
|
|
},
|
|
|
|
sync: function (method, model, options) {
|
|
var settings = _.map(this.attributes, function (value, key) {
|
|
return { key: key, value: value };
|
|
});
|
|
//wrap settings in {settings: [{...}]}
|
|
if (method === 'update') {
|
|
options.data = JSON.stringify({settings: settings});
|
|
options.contentType = 'application/json';
|
|
}
|
|
|
|
return Backbone.Model.prototype.sync.apply(this, arguments);
|
|
}
|
|
});
|
|
|
|
}());
|