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', fallbackRouteCancel: 'protected.strains.show',
actions: { actions: {
save: function(properties, deleteQueue) {
deleteQueue.forEach((val) => {
val.destroyRecord();
});
this._super(properties);
},
addCharacteristic: function() { addCharacteristic: function() {
return this.store.createRecord('measurement', { return this.store.createRecord('measurement', {
characteristic: this.store.createRecord('characteristic', { sortOrder: -999 }), 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") add-characteristic=(action "addCharacteristic")
allCharacteristics=allCharacteristics allCharacteristics=allCharacteristics
save-measurement=(action "saveMeasurement") save-measurement=(action "saveMeasurement")
delete-measurement=(action "deleteMeasurement")
on-save=(action "save") on-save=(action "save")
on-cancel=(action "cancel") on-cancel=(action "cancel")
}} }}

View file

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