2014-06-04 23:18:23 -04:00
|
|
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
2014-06-21 08:44:53 -06:00
|
|
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
2014-06-13 13:35:22 -06:00
|
|
|
|
2014-07-25 15:38:13 +02:00
|
|
|
var PostsPostRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, ShortcutsRoute, {
|
2014-03-02 15:12:06 -05:00
|
|
|
model: function (params) {
|
2014-06-17 15:17:08 -04:00
|
|
|
var self = this,
|
|
|
|
post,
|
2014-07-30 17:44:49 +01:00
|
|
|
postId,
|
|
|
|
paginationSettings;
|
2014-05-23 23:25:20 -04:00
|
|
|
|
2014-06-17 15:17:08 -04:00
|
|
|
postId = Number(params.post_id);
|
|
|
|
|
2014-07-02 14:09:04 +00:00
|
|
|
if (!_.isNumber(postId) || !_.isFinite(postId) || postId % 1 !== 0 || postId <= 0)
|
|
|
|
{
|
|
|
|
return this.transitionTo('error404', params.post_id);
|
2014-05-23 23:25:20 -04:00
|
|
|
}
|
|
|
|
|
2014-06-17 15:17:08 -04:00
|
|
|
post = this.store.getById('post', postId);
|
|
|
|
|
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
|
|
|
|
2014-07-30 17:44:49 +01:00
|
|
|
paginationSettings = {
|
|
|
|
id: postId,
|
2014-06-17 15:17:08 -04:00
|
|
|
status: 'all',
|
2014-07-30 17:44:49 +01:00
|
|
|
staticPages: 'all'
|
|
|
|
};
|
2014-06-17 15:17:08 -04:00
|
|
|
|
2014-07-30 17:44:49 +01:00
|
|
|
return this.store.find('user', 'me').then(function (user) {
|
|
|
|
if (user.get('isAuthor')) {
|
|
|
|
paginationSettings.author = user.get('slug');
|
2014-06-17 15:17:08 -04:00
|
|
|
}
|
|
|
|
|
2014-07-30 17:44:49 +01:00
|
|
|
return self.store.find('post', paginationSettings).then(function (records) {
|
|
|
|
var post = records.get('firstObject');
|
|
|
|
|
2014-07-31 17:23:08 -04:00
|
|
|
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
|
2014-07-30 22:44:51 -04:00
|
|
|
// do not show the post if they are an author but not this posts author
|
|
|
|
post = null;
|
|
|
|
}
|
|
|
|
|
2014-07-30 17:44:49 +01:00
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.transitionTo('posts.index');
|
|
|
|
});
|
2014-06-17 15:17:08 -04:00
|
|
|
});
|
|
|
|
},
|
2014-07-30 20:33:05 -06:00
|
|
|
setupController: function (controller, model) {
|
|
|
|
this._super(controller, model);
|
2014-07-31 09:29:05 +01:00
|
|
|
|
2014-07-30 20:33:05 -06:00
|
|
|
this.controllerFor('posts').set('currentPost', model);
|
|
|
|
},
|
2014-07-31 09:29:05 +01:00
|
|
|
|
2014-06-21 08:44:53 -06:00
|
|
|
shortcuts: {
|
2014-06-24 23:55:25 +01:00
|
|
|
'enter': 'openEditor'
|
2014-06-21 08:44:53 -06:00
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
openEditor: function () {
|
|
|
|
this.transitionTo('editor.edit', this.get('controller.model'));
|
|
|
|
}
|
|
|
|
}
|
2014-03-03 21:18:10 +01:00
|
|
|
});
|
2014-06-02 19:55:37 +01:00
|
|
|
|
2014-06-13 13:35:22 -06:00
|
|
|
export default PostsPostRoute;
|