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 SaveModel from '../../../../mixins/save-model';
import ajaxError from '../../../../utils/ajax-error';
const { Controller } = Ember;
@ -14,5 +15,14 @@ export default Controller.extend(SaveModel, {
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
add-characteristic=(action "addCharacteristic")
allCharacteristics=allCharacteristics
save-measurement=(action "saveMeasurement")
on-save=(action "save")
on-cancel=(action "cancel")
}}

View file

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

View file

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

View file

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

View file

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

View file

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