2014-07-01 19:58:26 +04:00
|
|
|
var SettingsUserRoute = Ember.Route.extend({
|
2014-07-17 06:16:31 +04:00
|
|
|
model: function (params) {
|
2014-07-31 01:42:46 +04:00
|
|
|
var self = this;
|
2014-07-17 06:16:31 +04:00
|
|
|
// TODO: Make custom user adapter that uses /api/users/:slug endpoint
|
|
|
|
// return this.store.find('user', { slug: params.slug });
|
|
|
|
|
|
|
|
// Instead, get all the users and then find by slug
|
|
|
|
return this.store.find('user').then(function (result) {
|
2014-07-31 01:42:46 +04:00
|
|
|
var user = result.findBy('slug', params.slug);
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
return self.transitionTo('error404', 'settings/users/' + params.slug);
|
|
|
|
}
|
|
|
|
|
|
|
|
return user;
|
2014-07-01 19:58:26 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-07-25 11:52:17 +04:00
|
|
|
afterModel: function (user) {
|
|
|
|
var self = this;
|
|
|
|
this.store.find('user', 'me').then(function (currentUser) {
|
|
|
|
var isOwnProfile = user.get('id') === currentUser.get('id'),
|
|
|
|
isAuthor = currentUser.get('isAuthor'),
|
|
|
|
isEditor = currentUser.get('isEditor');
|
|
|
|
if (isAuthor && !isOwnProfile) {
|
|
|
|
self.transitionTo('settings.users.user', currentUser);
|
|
|
|
} else if (isEditor && !isOwnProfile && !user.get('isAuthor')) {
|
|
|
|
self.transitionTo('settings.users');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-07-01 19:58:26 +04:00
|
|
|
deactivate: function () {
|
2014-07-17 06:16:31 +04:00
|
|
|
var model = this.modelFor('settings.users.user');
|
2014-07-01 19:58:26 +04:00
|
|
|
|
|
|
|
// we want to revert any unsaved changes on exit
|
2014-07-17 06:16:31 +04:00
|
|
|
if (model && model.get('isDirty')) {
|
|
|
|
model.rollback();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._super();
|
2014-07-01 19:58:26 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default SettingsUserRoute;
|