Refactored users/edit
This commit is contained in:
parent
b742ddbb51
commit
1dd0910ed1
13 changed files with 92 additions and 65 deletions
|
@ -1,15 +1,61 @@
|
|||
import Ember from 'ember';
|
||||
import SetupMetaData from '../../../../mixins/setup-metadata';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
const { Component } = Ember;
|
||||
|
||||
export default Component.extend(SetupMetaData, {
|
||||
// Read-only attributes
|
||||
user: null,
|
||||
isDirty: false,
|
||||
roles: Ember.String.w('A R W'),
|
||||
|
||||
// Actions
|
||||
"on-save": null,
|
||||
"on-cancel": null,
|
||||
"on-update": null,
|
||||
|
||||
// Property mapping
|
||||
propertiesList: ['name', 'email', 'role'],
|
||||
name: null,
|
||||
email: null,
|
||||
role: null,
|
||||
|
||||
resetOnInit: Ember.on('init', function() {
|
||||
this.get('propertiesList').forEach((field) => {
|
||||
const valueInUser = this.get('user').get(field);
|
||||
this.set(field, valueInUser);
|
||||
});
|
||||
}),
|
||||
|
||||
updateField: function(property, value) {
|
||||
this.set(property, value);
|
||||
// Manually compare against passed in value
|
||||
if (this.get('user').get(property) !== value) {
|
||||
this.set('isDirty', true);
|
||||
} else {
|
||||
this.set('isDirty', false);
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
save: function() {
|
||||
this.sendAction('save');
|
||||
return this.attrs['on-save'](this.getProperties(this.get('propertiesList')));
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
this.sendAction('cancel');
|
||||
return this.attrs['on-cancel']();
|
||||
},
|
||||
}
|
||||
|
||||
nameDidChange: function(value) {
|
||||
this.updateField('name', value);
|
||||
},
|
||||
|
||||
emailDidChange: function(value) {
|
||||
this.updateField('email', value);
|
||||
},
|
||||
|
||||
roleDidChange: function(value) {
|
||||
this.updateField('role', value);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
Reference in a new issue