From ff5ae21a9ee68229c01af6ea505c30df516f512c Mon Sep 17 00:00:00 2001 From: Sebastian Gierlinger Date: Wed, 16 Apr 2014 12:09:03 +0200 Subject: [PATCH] Move post API to primary document format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #2580 - added new format to post API methods - added post object parsing and wrapping to admin - removed unused ‚user‘ object from API response - updated tests --- ghost/admin/models/post.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ghost/admin/models/post.js b/ghost/admin/models/post.js index 157eb8e59d..26f5c792fa 100644 --- a/ghost/admin/models/post.js +++ b/ghost/admin/models/post.js @@ -1,4 +1,4 @@ -/*global Ghost, _, Backbone */ +/*global Ghost, _, Backbone, JSON */ (function () { 'use strict'; @@ -11,6 +11,10 @@ blacklist: ['published', 'draft'], parse: function (resp) { + + if (resp.posts) { + resp = resp.posts[0]; + } if (resp.status) { resp.published = resp.status === 'published'; resp.draft = resp.status === 'draft'; @@ -39,6 +43,15 @@ return tag.id === tagToRemove.id || tag.name === tagToRemove.name; }); this.set('tags', tags); + }, + sync: function (method, model, options) { + //wrap post in {posts: [{...}]} + if (method === 'create' || method === 'update') { + options.data = JSON.stringify({posts: [this.attributes]}); + options.contentType = 'application/json'; + } + + return Backbone.Model.prototype.sync.apply(this, arguments); } });