Refactor strain form and edit strain

This commit is contained in:
Matthew Dillon 2015-11-10 12:57:12 -07:00
parent 04486880a0
commit 29c507af6b
5 changed files with 122 additions and 69 deletions

View file

@ -1,32 +1,10 @@
import Ember from 'ember';
import ajaxError from '../../../../utils/ajax-error';
import SaveModel from '../../../../mixins/save-model';
export default Ember.Controller.extend({
actions: {
save: function() {
let strain = this.get('strain');
const { Controller } = Ember;
if (strain.get('hasDirtyAttributes')) {
strain.save().then((strain) => {
this.transitionToRoute('protected.strains.show', strain);
}, () => {
ajaxError(strain.get('errors'), this.get('flashMessages'));
});
} else {
strain.destroyRecord().then(() => {
this.transitionToRoute('protected.strains.show', strain);
});
}
},
cancel: function() {
let strain = this.get('strain');
strain.get('errors').clear();
strain.rollbackAttributes();
this.transitionToRoute('protected.strains.show', strain);
},
},
export default Controller.extend(SaveModel, {
// Required for SaveModel mixin
fallbackRouteSave: 'protected.strains.show',
fallbackRouteCancel: 'protected.strains.show',
});