Add measurement table cancel

This commit is contained in:
Matthew Dillon 2015-11-30 17:31:12 -07:00
parent 6d97466075
commit a4dbb4a94d
4 changed files with 32 additions and 11 deletions

View file

@ -18,7 +18,7 @@ export default Controller.extend(SaveModel, {
saveMeasurement: function(measurement, properties) {
measurement.setProperties(properties);
measurement.save().then(() => {
return measurement.save().then(() => {
this.get('flashMessages').clearMessages();
}, () => {
ajaxError(measurement.get('errors'), this.get('flashMessages'));

View file

@ -10,6 +10,7 @@ export default Component.extend({
allCharacteristics: null,
measurement: null,
isDirty: null,
isNew: false,
// Actions
"save-measurement": null,
@ -22,11 +23,20 @@ export default Component.extend({
notes: null,
resetOnInit: Ember.on('init', function() {
this._resetProperties();
}),
_resetProperties: function() {
this.get('propertiesList').forEach((field) => {
const valueInMeasurement = this.get('measurement').get(field);
this.set(field, valueInMeasurement);
});
}),
// Read-only attributes
this.set('isNew', this.get('measurement.isNew'));
if (this.get('isNew')) {
this.set('isEditing', true);
}
},
updateField: function(property, value) {
this.set(property, value);
@ -40,12 +50,23 @@ export default Component.extend({
actions: {
edit: function() {
this.toggleProperty('isEditing');
this.set('isEditing', true);
},
save: function() {
this.attrs['save-measurement'](this.get('measurement'), this.getProperties(this.get('propertiesList')));
this.toggleProperty('isEditing');
this.attrs['save-measurement'](this.get('measurement'), this.getProperties(this.get('propertiesList'))).then(() => {
this._resetProperties();
this.set('isEditing', false);
});
},
cancel: function() {
if (this.get('isNew')) {
this.attrs['delete-measurement'](this.get('measurement'));
} else {
this._resetProperties();
this.set('isEditing', false);
}
},
delete: function() {

View file

@ -0,0 +1 @@
{{loading-panel}}

View file

@ -15,14 +15,13 @@
</td>
{{#if canEdit}}
<td>
{{#if isDirty}}
<button class="button-green smaller" {{action 'save'}}>
Save
</button>
{{else}}
<button class="button-gray smaller" {{action 'save'}}>
<button class="button-gray smaller" {{action 'cancel'}}>
Cancel
</button>
{{#if isDirty}}
<button class="button-green smaller" {{action 'save'}}>
Save
</button>
{{/if}}
</td>
{{/if}}