2014-06-13 23:35:22 +04:00
|
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
2014-06-05 07:18:23 +04:00
|
|
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
2014-06-13 23:35:22 +04:00
|
|
|
|
2014-06-05 07:18:23 +04:00
|
|
|
var PostsPostRoute = AuthenticatedRoute.extend(loadingIndicator, {
|
2014-03-03 00:12:06 +04:00
|
|
|
model: function (params) {
|
2014-06-17 23:17:08 +04:00
|
|
|
var self = this,
|
|
|
|
post,
|
|
|
|
postId;
|
2014-05-24 07:25:20 +04:00
|
|
|
|
2014-06-17 23:17:08 +04:00
|
|
|
postId = Number(params.post_id);
|
|
|
|
|
|
|
|
if (!Number.isInteger(postId) || !Number.isFinite(postId) || postId <= 0) {
|
2014-05-24 07:25:20 +04:00
|
|
|
this.transitionTo('posts.index');
|
|
|
|
}
|
|
|
|
|
2014-06-17 23:17:08 +04:00
|
|
|
post = this.store.getById('post', postId);
|
|
|
|
|
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.store.find('post', {
|
|
|
|
id: params.post_id,
|
|
|
|
status: 'all',
|
|
|
|
staticPages: 'all'
|
|
|
|
}).then(function (records) {
|
|
|
|
var post = records.get('firstObject');
|
|
|
|
|
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.transitionTo('posts.index');
|
|
|
|
});
|
|
|
|
},
|
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;
|