Add include parameter for posts API

closes #2609
- added include parameter to api.posts.*
- changed toJSON to omit objects that are not included
- added include parameter to admin
- added include parameter to frontend.js
- updated tests
- removed duplicate code from posts model

**Known Issue:** It is not possible to attach a tag using an ID.
This commit is contained in:
Sebastian Gierlinger 2014-04-27 18:58:34 +02:00
parent 8d2cf655c2
commit 254b6618f3
3 changed files with 4 additions and 3 deletions

View File

@ -49,6 +49,7 @@
if (method === 'create' || method === 'update') {
options.data = JSON.stringify({posts: [this.attributes]});
options.contentType = 'application/json';
options.url = model.url() + '?include=tags';
}
return Backbone.Model.prototype.sync.apply(this, arguments);

View File

@ -3,7 +3,7 @@
'use strict';
Ghost.Models.Themes = Backbone.Model.extend({
url: Ghost.paths.apiRoot + '/themes'
url: Ghost.paths.apiRoot + '/themes/'
});
}());

View File

@ -36,7 +36,7 @@
blog: function () {
var posts = new Ghost.Collections.Posts();
NProgress.start();
posts.fetch({ data: { status: 'all', staticPages: 'all'} }).then(function () {
posts.fetch({ data: { status: 'all', staticPages: 'all', include: 'author'} }).then(function () {
Ghost.currentView = new Ghost.Views.Blog({ el: '#main', collection: posts });
NProgress.done();
});
@ -63,7 +63,7 @@
post.urlRoot = Ghost.paths.apiRoot + '/posts';
if (id) {
post.id = id;
post.fetch({ data: {status: 'all'}}).then(function () {
post.fetch({ data: {status: 'all', include: 'tags'}}).then(function () {
Ghost.currentView = new Ghost.Views.Editor({ el: '#main', model: post });
});
} else {