Edit user

This commit is contained in:
Matthew Dillon 2015-10-01 07:13:36 -07:00
parent 69dbdcaa89
commit f2f16e15a4
5 changed files with 91 additions and 0 deletions

View file

@ -0,0 +1,32 @@
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
save: function() {
let user = this.get('model');
if (user.get('hasDirtyAttributes')) {
user.save().then((user) => {
this.get('flashMessages').clearMessages();
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);
},
},
});

View file

@ -0,0 +1,8 @@
import Ember from 'ember';
export default Ember.Route.extend({
model: function(params) {
return this.store.findRecord('user', params.user_id, { reload: true });
},
});

View file

@ -0,0 +1,6 @@
{{
protected/users/user-form
user=model
save="save"
cancel="cancel"
}}

View file

@ -0,0 +1,13 @@
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
save: function() {
this.sendAction('save');
},
cancel: function() {
this.sendAction('cancel');
},
}
});

View file

@ -0,0 +1,32 @@
<form class="grid-form" {{action 'save' on='submit'}}>
<fieldset>
<legend><em>{{user.name}}</em></legend>
<div data-row-span="1">
<div data-field-span="1">
<label>Name</label>
{{input value=user.name}}
</div>
</div>
<div data-row-span="1">
<div data-field-span="1">
<label>Email</label>
{{input value=user.email}}
</div>
</div>
<div data-row-span="1">
<div data-field-span="1">
<label>Role</label>
{{user.role}}
</div>
</div>
</fieldset>
<br>
<a class="button-red smaller" {{action 'cancel'}}>
Cancel
</a>
{{#if user.hasDirtyAttributes}}
<button type="submit" class="button-green smaller">
Save
</button>
{{/if}}
</form>