2015-10-28 14:36:45 +03:00
|
|
|
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
|
2014-10-28 17:29:42 +03:00
|
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
2015-04-14 18:04:16 +03:00
|
|
|
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
|
2014-09-23 17:04:49 +04:00
|
|
|
import styleBody from 'ghost/mixins/style-body';
|
2015-12-04 01:37:23 +03:00
|
|
|
import NotFoundHandler from 'ghost/mixins/404-handler';
|
2014-09-23 17:04:49 +04:00
|
|
|
|
2015-12-04 01:37:23 +03:00
|
|
|
export default AuthenticatedRoute.extend(styleBody, CurrentUserSettings, NotFoundHandler, {
|
2015-05-25 21:17:10 +03:00
|
|
|
titleToken: 'Team - User',
|
2014-11-25 23:56:08 +03:00
|
|
|
|
2015-06-18 13:59:08 +03:00
|
|
|
classNames: ['team-view-user'],
|
2014-09-23 17:04:49 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
model(params) {
|
2015-11-23 16:48:08 +03:00
|
|
|
return this.store.queryRecord('user', {slug: params.user_slug});
|
|
|
|
},
|
2014-07-31 01:42:46 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
serialize(model) {
|
2015-11-23 16:48:08 +03:00
|
|
|
return {user_slug: model.get('slug')};
|
2014-07-01 19:58:26 +04:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
afterModel(user) {
|
2015-11-15 14:06:49 +03:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
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');
|
|
|
|
|
2014-07-25 11:52:17 +04:00
|
|
|
if (isAuthor && !isOwnProfile) {
|
2015-10-28 14:36:45 +03:00
|
|
|
this.transitionTo('team.user', currentUser);
|
2014-07-25 11:52:17 +04:00
|
|
|
} else if (isEditor && !isOwnProfile && !user.get('isAuthor')) {
|
2015-10-28 14:36:45 +03:00
|
|
|
this.transitionTo('team');
|
2014-07-25 11:52:17 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
deactivate() {
|
|
|
|
let model = this.modelFor('team.user');
|
2014-07-01 19:58:26 +04:00
|
|
|
|
|
|
|
// we want to revert any unsaved changes on exit
|
2015-09-03 14:06:50 +03:00
|
|
|
if (model && model.get('hasDirtyAttributes')) {
|
|
|
|
model.rollbackAttributes();
|
2014-07-17 06:16:31 +04:00
|
|
|
}
|
|
|
|
|
2015-09-03 00:10:51 +03:00
|
|
|
model.get('errors').clear();
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
this._super(...arguments);
|
2014-11-12 23:35:41 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2015-10-28 14:36:45 +03:00
|
|
|
didTransition() {
|
2015-09-03 00:10:51 +03:00
|
|
|
this.modelFor('team.user').get('errors').clear();
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
save() {
|
2014-11-12 23:35:41 +03:00
|
|
|
this.get('controller').send('save');
|
|
|
|
}
|
2014-07-01 19:58:26 +04:00
|
|
|
}
|
|
|
|
});
|