SaveModel Mixin

#43
This commit is contained in:
Matthew Ryan Dillon 2015-11-03 13:41:04 -07:00
parent 4dbfb73b3c
commit 58cbf4027d
3 changed files with 47 additions and 27 deletions

View file

@ -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',
});