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) { saveMeasurement: function(measurement, properties) {
measurement.setProperties(properties); measurement.setProperties(properties);
measurement.save().then(() => { return measurement.save().then(() => {
this.get('flashMessages').clearMessages(); this.get('flashMessages').clearMessages();
}, () => { }, () => {
ajaxError(measurement.get('errors'), this.get('flashMessages')); ajaxError(measurement.get('errors'), this.get('flashMessages'));

View file

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

View file

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

View file

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