1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/routes/posts/post.js
Kevin Ansfield 604fda4348 Update package.json details, rename module to ghost-admin
no issue
- updates `package.json` details to better reflect the separation from the `Ghost` package
- update ember config and all import statements to reflect the new `ghost-admin` module name in `package.json`
2016-06-03 16:12:54 +01:00

78 lines
2.1 KiB
JavaScript

import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import ShortcutsRoute from 'ghost-admin/mixins/shortcuts-route';
import NotFoundHandler from 'ghost-admin/mixins/404-handler';
import isNumber from 'ghost-admin/utils/isNumber';
import isFinite from 'ghost-admin/utils/isFinite';
export default AuthenticatedRoute.extend(ShortcutsRoute, NotFoundHandler, {
model(params) {
let post,
postId,
query;
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
postId = Number(params.post_id);
if (!isNumber(postId) || !isFinite(postId) || postId % 1 !== 0 || postId <= 0) {
return this.transitionTo('error404', params.post_id);
}
/* jscs:enable requireCamelCaseOrUpperCaseIdentifiers */
post = this.store.peekRecord('post', postId);
if (post) {
return post;
}
query = {
id: postId,
status: 'all',
staticPages: 'all'
};
return this.store.query('post', query).then((records) => {
let post = records.get('firstObject');
if (post) {
return post;
}
return this.replaceWith('posts.index');
});
},
afterModel(post) {
return this.get('session.user').then((user) => {
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
return this.replaceWith('posts.index');
}
});
},
setupController(controller, model) {
this._super(controller, model);
this.controllerFor('posts').set('currentPost', model);
},
shortcuts: {
'enter, o': 'openEditor',
'command+backspace, ctrl+backspace': 'deletePost'
},
actions: {
openEditor(post) {
post = post || this.get('controller.model');
if (!post) {
return;
}
this.transitionTo('editor.edit', post.get('id'));
},
deletePost() {
this.controllerFor('posts').send('toggleDeletePostModal');
}
}
});