This repository has been archived on 2025-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
hymenobacterdotinfo/app/pods/protected/strains/edit/controller.js
Matthew Dillon 1ee0e0e5ed DDAU (WIP)
2015-11-10 21:21:59 -07:00

37 lines
1.1 KiB
JavaScript

import Ember from 'ember';
import SaveModel from '../../../../mixins/save-model';
import ajaxError from '../../../../utils/ajax-error';
const { Controller } = Ember;
export default Controller.extend(SaveModel, {
// Required for SaveModel mixin
fallbackRouteSave: 'protected.strains.show',
fallbackRouteCancel: 'protected.strains.show',
actions: {
addCharacteristic: function() {
return this.store.createRecord('measurement', {
characteristic: this.store.createRecord('characteristic', { sortOrder: -999 }),
});
},
saveMeasurement: function(measurement, properties) {
measurement.setProperties(properties);
measurement.save().then(() => {
this.get('flashMessages').clearMessages();
}, () => {
ajaxError(measurement.get('errors'), this.get('flashMessages'));
});
},
deleteMeasurement: function(measurement) {
const characteristic = measurement.get('characteristic');
if (characteristic.get('isNew')) {
characteristic.destroyRecord();
}
measurement.destroyRecord();
},
},
});