Refactor strains/new

This commit is contained in:
Matthew Dillon 2015-11-10 14:31:38 -07:00
parent 29c507af6b
commit fa5b741e35
11 changed files with 45 additions and 60 deletions

View file

@ -1,29 +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.index');
});
}
},
cancel: function() {
this.get('strain').destroyRecord().then(() => {
this.transitionToRoute('protected.strains.index');
});
},
},
export default Controller.extend(SaveModel, {
// Required for SaveModel mixin
fallbackRouteSave: 'protected.strains.show',
fallbackRouteCancel: 'protected.strains.index',
});