From 254b6618f3e87c325942d2d37746f4867216eb94 Mon Sep 17 00:00:00 2001 From: Sebastian Gierlinger Date: Sun, 27 Apr 2014 18:58:34 +0200 Subject: [PATCH] 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. --- ghost/admin/models/post.js | 1 + ghost/admin/models/themes.js | 2 +- ghost/admin/router.js | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ghost/admin/models/post.js b/ghost/admin/models/post.js index f39a1b3280..67082b7535 100644 --- a/ghost/admin/models/post.js +++ b/ghost/admin/models/post.js @@ -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); diff --git a/ghost/admin/models/themes.js b/ghost/admin/models/themes.js index 63e5f57931..86f19c0c13 100644 --- a/ghost/admin/models/themes.js +++ b/ghost/admin/models/themes.js @@ -3,7 +3,7 @@ 'use strict'; Ghost.Models.Themes = Backbone.Model.extend({ - url: Ghost.paths.apiRoot + '/themes' + url: Ghost.paths.apiRoot + '/themes/' }); }()); diff --git a/ghost/admin/router.js b/ghost/admin/router.js index 460f129c7a..9b19477337 100644 --- a/ghost/admin/router.js +++ b/ghost/admin/router.js @@ -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 {