parent
4dbfb73b3c
commit
58cbf4027d
3 changed files with 47 additions and 27 deletions
|
@ -1,32 +1,9 @@
|
|||
import Ember from 'ember';
|
||||
import ajaxError from '../../../../utils/ajax-error';
|
||||
import SaveModel from '../../../../mixins/save-model';
|
||||
|
||||
const { Controller } = Ember;
|
||||
|
||||
export default Controller.extend({
|
||||
actions: {
|
||||
save: function() {
|
||||
const model = this.get('model');
|
||||
|
||||
if (model.get('hasDirtyAttributes')) {
|
||||
model.save().then((model) => {
|
||||
this.transitionToRoute('protected.species.show', model);
|
||||
}, () => {
|
||||
ajaxError(model.get('errors'), this.get('flashMessages'));
|
||||
});
|
||||
} else {
|
||||
this.transitionToRoute('protected.species.show', model);
|
||||
}
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
const model = this.get('model');
|
||||
|
||||
model.get('errors').clear();
|
||||
model.rollbackAttributes();
|
||||
|
||||
this.transitionToRoute('protected.species.show', model);
|
||||
},
|
||||
|
||||
},
|
||||
export default Controller.extend(SaveModel, {
|
||||
// Required for SaveModel mixin
|
||||
fallbackRoute: 'protected.species.show',
|
||||
});
|
||||
|
|
Reference in a new issue