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