Ghost/ghost/admin/app/routes/team/user.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

59 lines
1.7 KiB
JavaScript

/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
import AuthenticatedRoute from 'ghost/routes/authenticated';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
import styleBody from 'ghost/mixins/style-body';
import NotFoundHandler from 'ghost/mixins/404-handler';
export default AuthenticatedRoute.extend(styleBody, CurrentUserSettings, NotFoundHandler, {
titleToken: 'Team - User',
classNames: ['team-view-user'],
model(params) {
return this.store.queryRecord('user', {slug: params.user_slug, include: 'count.posts'});
},
serialize(model) {
return {user_slug: model.get('slug')};
},
afterModel(user) {
this._super(...arguments);
return this.get('session.user').then((currentUser) => {
let isOwnProfile = user.get('id') === currentUser.get('id');
let isAuthor = currentUser.get('isAuthor');
let isEditor = currentUser.get('isEditor');
if (isAuthor && !isOwnProfile) {
this.transitionTo('team.user', currentUser);
} else if (isEditor && !isOwnProfile && !user.get('isAuthor')) {
this.transitionTo('team');
}
});
},
deactivate() {
let model = this.modelFor('team.user');
// we want to revert any unsaved changes on exit
if (model && model.get('hasDirtyAttributes')) {
model.rollbackAttributes();
}
model.get('errors').clear();
this._super(...arguments);
},
actions: {
didTransition() {
this.modelFor('team.user').get('errors').clear();
},
save() {
this.get('controller').send('save');
}
}
});