Save measurement

This commit is contained in:
Matthew Dillon 2015-11-10 16:08:40 -07:00
parent 15474c76f3
commit b2fa171d17
7 changed files with 25 additions and 11 deletions

View file

@ -1,5 +1,6 @@
import Ember from 'ember'; import Ember from 'ember';
import SaveModel from '../../../../mixins/save-model'; import SaveModel from '../../../../mixins/save-model';
import ajaxError from '../../../../utils/ajax-error';
const { Controller } = Ember; const { Controller } = Ember;
@ -14,5 +15,14 @@ export default Controller.extend(SaveModel, {
characteristic: this.store.createRecord('characteristic', { sortOrder: -999 }), characteristic: this.store.createRecord('characteristic', { sortOrder: -999 }),
}); });
}, },
saveMeasurement: function(measurement) {
measurement.save().then(() => {
this.get('flashMessages').clearMessages();
}, () => {
ajaxError(measurement.get('errors'), this.get('flashMessages'));
});
},
}, },
}); });

View file

@ -4,6 +4,7 @@
speciesList=speciesList speciesList=speciesList
add-characteristic=(action "addCharacteristic") add-characteristic=(action "addCharacteristic")
allCharacteristics=allCharacteristics allCharacteristics=allCharacteristics
save-measurement=(action "saveMeasurement")
on-save=(action "save") on-save=(action "save")
on-cancel=(action "cancel") on-cancel=(action "cancel")
}} }}

View file

@ -1,5 +1,4 @@
import Ember from 'ember'; import Ember from 'ember';
import ajaxError from '../../../../utils/ajax-error';
const { Component, computed } = Ember; const { Component, computed } = Ember;
@ -25,16 +24,8 @@ export default Component.extend({
}, },
save: function() { save: function() {
if (this.get('rowChanged')) { this.attrs['save-measurement'](this.get('measurement'));
this.get('measurement').save().then(() => { this.toggleProperty('isEditing');
this.get('flashMessages').clearMessages();
this.toggleProperty('isEditing');
}, () => {
ajaxError(this.get('measurement.errors'), this.get('flashMessages'));
});
} else {
this.toggleProperty('isEditing');
}
}, },
delete: function() { delete: function() {

View file

@ -12,6 +12,7 @@ export default Component.extend({
// Actions // Actions
"add-characteristic": null, "add-characteristic": null,
"save-measurement": null,
// Properties // Properties
sortParams: ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName'], sortParams: ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName'],
@ -40,6 +41,10 @@ export default Component.extend({
this.set('paramsChanged', false); this.set('paramsChanged', false);
this.set('sortAsc', true); this.set('sortAsc', true);
}, },
saveMeasurement: function(measurement) {
return this.attrs['save-measurement'](measurement);
},
}, },
}); });

View file

@ -43,6 +43,7 @@
{{ {{
protected/strains/measurements-table-row protected/strains/measurements-table-row
measurement=measurement measurement=measurement
save-measurement=(action "saveMeasurement")
allCharacteristics=allCharacteristics allCharacteristics=allCharacteristics
canEdit=canEdit canEdit=canEdit
}} }}

View file

@ -16,6 +16,7 @@ export default Component.extend(SetupMetaData, {
"on-cancel": null, "on-cancel": null,
"on-update": null, "on-update": null,
"add-characteristic": null, "add-characteristic": null,
"save-measurement": null,
// Property mapping // Property mapping
propertiesList: ['strainName', 'typeStrain', 'species', 'isolatedFrom', 'accessionNumbers', 'genbank', 'wholeGenomeSequence', 'notes'], propertiesList: ['strainName', 'typeStrain', 'species', 'isolatedFrom', 'accessionNumbers', 'genbank', 'wholeGenomeSequence', 'notes'],
@ -60,6 +61,10 @@ export default Component.extend(SetupMetaData, {
return this.attrs['add-characteristic'](); return this.attrs['add-characteristic']();
}, },
saveMeasurement: function(measurement) {
return this.attrs['save-measurement'](measurement);
},
strainNameDidChange: function(value) { strainNameDidChange: function(value) {
this.updateField('strainName', value); this.updateField('strainName', value);
}, },

View file

@ -55,6 +55,7 @@
strain=strain strain=strain
add-characteristic=(action "addCharacteristic") add-characteristic=(action "addCharacteristic")
allCharacteristics=allCharacteristics allCharacteristics=allCharacteristics
save-measurement=(action "saveMeasurement")
canEdit=strain.canEdit canEdit=strain.canEdit
canAdd=metaData.canAdd canAdd=metaData.canAdd
}} }}