Edit user
This commit is contained in:
parent
69dbdcaa89
commit
f2f16e15a4
5 changed files with 91 additions and 0 deletions
32
app/pods/protected/users/edit/controller.js
Normal file
32
app/pods/protected/users/edit/controller.js
Normal 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);
|
||||
},
|
||||
|
||||
},
|
||||
});
|
8
app/pods/protected/users/edit/route.js
Normal file
8
app/pods/protected/users/edit/route.js
Normal 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 });
|
||||
},
|
||||
|
||||
});
|
6
app/pods/protected/users/edit/template.hbs
Normal file
6
app/pods/protected/users/edit/template.hbs
Normal file
|
@ -0,0 +1,6 @@
|
|||
{{
|
||||
protected/users/user-form
|
||||
user=model
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
13
app/pods/protected/users/user-form/component.js
Normal file
13
app/pods/protected/users/user-form/component.js
Normal 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');
|
||||
},
|
||||
}
|
||||
});
|
32
app/pods/protected/users/user-form/template.hbs
Normal file
32
app/pods/protected/users/user-form/template.hbs
Normal 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>
|
Reference in a new issue