Refactoring delete measurement

This commit is contained in:
Matthew Dillon 2015-12-01 07:03:43 -07:00
parent a4dbb4a94d
commit 233a2d09a1
3 changed files with 22 additions and 14 deletions

View file

@ -10,6 +10,14 @@ export default Controller.extend(SaveModel, {
fallbackRouteCancel: 'protected.strains.show',
actions: {
save: function(properties, deleteQueue) {
deleteQueue.forEach((val) => {
val.destroyRecord();
});
this._super(properties);
},
addCharacteristic: function() {
return this.store.createRecord('measurement', {
characteristic: this.store.createRecord('characteristic', { sortOrder: -999 }),
@ -25,13 +33,5 @@ export default Controller.extend(SaveModel, {
});
},
deleteMeasurement: function(measurement) {
const characteristic = measurement.get('characteristic');
if (characteristic.get('isNew')) {
characteristic.destroyRecord();
}
measurement.destroyRecord();
},
},
});

View file

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

View file

@ -10,6 +10,7 @@ export default Component.extend(SetupMetaData, {
isDirty: false,
speciesList: null,
allCharacteristics: null,
deleteQueue: [],
// Actions
"on-save": null,
@ -17,14 +18,13 @@ export default Component.extend(SetupMetaData, {
"on-update": null,
"add-characteristic": null,
"save-measurement": null,
"delete-measurement": null,
// CPs
sortParams: ['sortOrder'],
sortedSpeciesList: sort('speciesList', 'sortParams'),
// Property mapping
propertiesList: ['strainName', 'typeStrain', 'species', 'isolatedFrom', 'accessionNumbers', 'genbank', 'wholeGenomeSequence', 'notes'],
propertiesList: ['strainName', 'typeStrain', 'species', 'isolatedFrom', 'accessionNumbers', 'genbank', 'wholeGenomeSequence', 'notes', 'measurements'],
strainName: null,
typeStrain: null,
species: null,
@ -33,6 +33,7 @@ export default Component.extend(SetupMetaData, {
genbank: null,
wholeGenomeSequence: null,
notes: null,
measurements: [],
resetOnInit: Ember.on('init', function() {
this.get('propertiesList').forEach((field) => {
@ -55,7 +56,7 @@ export default Component.extend(SetupMetaData, {
actions: {
save: function() {
return this.attrs['on-save'](this.getProperties(this.get('propertiesList')));
return this.attrs['on-save'](this.getProperties(this.get('propertiesList')), this.get('deleteQueue'));
},
cancel: function() {
@ -70,8 +71,16 @@ export default Component.extend(SetupMetaData, {
return this.attrs['save-measurement'](measurement, properties);
},
deleteMeasurement: function(measurement) {
return this.attrs['delete-measurement'](measurement);
deleteMeasurement: function(value) {
const characteristic = value.get('characteristic');
if (characteristic.get('isNew')) {
this.get('deleteQueue').pushObject(characteristic);
}
this.get('deleteQueue').pushObject(value);
let measurements = this.get('measurements');
measurements.removeObject(value);
this.set('isDirty', true);
},
strainNameDidChange: function(value) {