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