This repository has been archived on 2025-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
hymenobacterdotinfo/app/pods/protected/users/edit/controller.js
Matthew Dillon d353dc6e75 Clear store on role change
Fixes #18.
2015-10-12 15:05:02 -07:00

41 lines
1.1 KiB
JavaScript

import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
save: function() {
let user = this.get('model');
if (user.get('hasDirtyAttributes')) {
let attrs = user.changedAttributes(), roleChanged = false;
if (attrs.role) {
roleChanged = true;
}
user.save().then((user) => {
this.get('flashMessages').clearMessages();
if (roleChanged) {
// Need to clear the store so that canEdit and canAdd
// attributes reflect the new role.
this.get('store').unloadAll();
}
this.transitionToRoute('protected.users.show', user);
}, (err) => {
err.errors.forEach((error) => {
this.get('flashMessages').error(error.detail);
});
});
} else {
this.transitionToRoute('protected.users.show', user);
}
},
cancel: function() {
let user = this.get('model');
user.get('errors').clear();
user.rollbackAttributes();
this.transitionToRoute('protected.users.show', user);
},
},
});