diff --git a/app/pods/protected/strains/edit/controller.js b/app/pods/protected/strains/edit/controller.js index 4d68665..b3bf9b8 100644 --- a/app/pods/protected/strains/edit/controller.js +++ b/app/pods/protected/strains/edit/controller.js @@ -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')); diff --git a/app/pods/protected/strains/measurements-table-row/component.js b/app/pods/protected/strains/measurements-table-row/component.js index ad63dc9..61a60fb 100644 --- a/app/pods/protected/strains/measurements-table-row/component.js +++ b/app/pods/protected/strains/measurements-table-row/component.js @@ -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() { diff --git a/app/pods/protected/strains/measurements-table-row/loading/template.hbs b/app/pods/protected/strains/measurements-table-row/loading/template.hbs new file mode 100644 index 0000000..e5a3e05 --- /dev/null +++ b/app/pods/protected/strains/measurements-table-row/loading/template.hbs @@ -0,0 +1 @@ +{{loading-panel}} diff --git a/app/pods/protected/strains/measurements-table-row/template.hbs b/app/pods/protected/strains/measurements-table-row/template.hbs index 0dc03b7..3e3fd4d 100644 --- a/app/pods/protected/strains/measurements-table-row/template.hbs +++ b/app/pods/protected/strains/measurements-table-row/template.hbs @@ -15,14 +15,13 @@ {{#if canEdit}} - {{#if isDirty}} - - {{else}} - + {{#if isDirty}} + {{/if}} {{/if}}