2014-03-03 21:18:10 +01:00
|
|
|
import styleBody from 'ghost/mixins/style-body';
|
2014-03-11 17:23:32 +01:00
|
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
2014-05-09 00:00:10 -05:00
|
|
|
|
2014-03-11 17:23:32 +01:00
|
|
|
var EditorRoute = AuthenticatedRoute.extend(styleBody, {
|
2014-03-03 21:18:10 +01:00
|
|
|
classNames: ['editor'],
|
2014-06-08 02:02:21 -04:00
|
|
|
|
2014-03-02 15:30:35 +01:00
|
|
|
model: function (params) {
|
2014-06-09 00:18:39 +00:00
|
|
|
var self = this,
|
|
|
|
post,
|
|
|
|
postId;
|
|
|
|
|
|
|
|
postId = Number(params.post_id);
|
|
|
|
|
|
|
|
if (!Number.isInteger(postId) || !Number.isFinite(postId) || postId <= 0) {
|
|
|
|
this.transitionTo('posts.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
post = this.store.getById('post', postId);
|
2014-06-05 13:23:28 -04:00
|
|
|
|
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
|
|
|
|
2014-06-08 02:02:21 -04:00
|
|
|
return this.store.filter('post', { status: 'all', staticPages: 'all' }, function (post) {
|
2014-06-09 00:18:39 +00:00
|
|
|
return post.get('id') === postId;
|
2014-06-05 13:23:28 -04:00
|
|
|
}).then(function (records) {
|
2014-06-09 00:18:39 +00:00
|
|
|
var post = records.get('firstObject');
|
|
|
|
|
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.transitionTo('posts.index');
|
2014-06-05 13:23:28 -04:00
|
|
|
});
|
2014-03-02 15:30:35 +01:00
|
|
|
}
|
2014-03-03 21:18:10 +01:00
|
|
|
});
|
|
|
|
|
2014-04-20 08:48:34 -06:00
|
|
|
export default EditorRoute;
|