Refactor strains/new
This commit is contained in:
parent
29c507af6b
commit
fa5b741e35
11 changed files with 45 additions and 60 deletions
|
@ -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',
|
||||
});
|
||||
|
|
Reference in a new issue