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-06-30 16:58:10 +04:00
|
|
|
var PostsPostRoute = Ember.Route.extend(Ember.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,
|
|
|
|
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-06-24 03:52:10 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.store.find('post', {
|
|
|
|
id: params.post_id,
|
|
|
|
status: 'all',
|
2014-06-27 06:35:25 +04:00
|
|
|
staticPages: 'all',
|
|
|
|
include: 'tags'
|
2014-06-17 23:17:08 +04:00
|
|
|
}).then(function (records) {
|
|
|
|
var post = records.get('firstObject');
|
|
|
|
|
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.transitionTo('posts.index');
|
|
|
|
});
|
|
|
|
},
|
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;
|