Ghost/ghost/admin/app/routes/editor/edit.js
Kevin Ansfield 9d67980a7e Refactor modals
refs #5798, closes #5018
- adds new `gh-fullscreen-modal` component - modals are now specified in-context so that they can have deeper interaction with their surrounding components/controller/route, i.e. a modal component can be a thin confirm/deny wrapper over the underlying controller action keeping all context-sensitive logic in one place
- adds spin-buttons to all modals with async behaviour
- adds/improves behaviour of inline-validation in modals
- improves re-authenticate modal to properly handle validation and authentication errors
2016-01-12 20:53:08 +00:00

66 lines
1.7 KiB
JavaScript

/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
import AuthenticatedRoute from 'ghost/routes/authenticated';
import base from 'ghost/mixins/editor-base-route';
import NotFoundHandler from 'ghost/mixins/404-handler';
import isNumber from 'ghost/utils/isNumber';
import isFinite from 'ghost/utils/isFinite';
export default AuthenticatedRoute.extend(base, NotFoundHandler, {
titleToken: 'Editor',
beforeModel(transition) {
this.set('_transitionedFromNew', transition.data.fromNew);
this._super(...arguments);
},
model(params) {
let postId,
query;
postId = Number(params.post_id);
if (!isNumber(postId) || !isFinite(postId) || postId % 1 !== 0 || postId <= 0) {
return this.transitionTo('error404', `editor/${params.post_id}`);
}
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.replaceRoute('posts.index');
});
},
afterModel(post) {
this._super(...arguments);
return this.get('session.user').then((user) => {
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
return this.replaceRoute('posts.index');
}
});
},
setupController(controller) {
this._super(...arguments);
controller.set('shouldFocusEditor', this.get('_transitionedFromNew'));
},
actions: {
authorizationFailed() {
this.get('controller').send('toggleReAuthenticateModal');
}
}
});