2014-05-07 22:28:29 +01:00
|
|
|
/*global Backbone, Ghost, _ */
|
2013-06-08 02:05:40 -03:00
|
|
|
(function () {
|
2013-09-24 12:46:30 +02:00
|
|
|
'use strict';
|
2013-09-11 16:37:23 +00:00
|
|
|
//id:0 is used to issue PUT requests
|
2013-11-22 21:47:03 +00:00
|
|
|
Ghost.Models.Settings = Ghost.ProgressModel.extend({
|
2014-02-23 12:32:35 +00:00
|
|
|
url: Ghost.paths.apiRoot + '/settings/?type=blog,theme,app',
|
2014-05-07 22:28:29 +01:00
|
|
|
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);
|
|
|
|
}
|
2013-06-08 02:05:40 -03:00
|
|
|
});
|
|
|
|
|
2014-05-07 22:28:29 +01:00
|
|
|
}());
|