parent
4dbfb73b3c
commit
58cbf4027d
3 changed files with 47 additions and 27 deletions
31
app/mixins/save-model.js
Normal file
31
app/mixins/save-model.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import Ember from 'ember';
|
||||
import ajaxError from '../utils/ajax-error';
|
||||
|
||||
export default Ember.Mixin.create({
|
||||
actions: {
|
||||
save: function() {
|
||||
const model = this.get('model');
|
||||
const fallbackRoute = this.get('fallbackRoute');
|
||||
|
||||
if (model.get('hasDirtyAttributes')) {
|
||||
model.save().then((model) => {
|
||||
this.transitionToRoute(fallbackRoute, model);
|
||||
}, () => {
|
||||
ajaxError(model.get('errors'), this.get('flashMessages'));
|
||||
});
|
||||
} else {
|
||||
this.transitionToRoute(fallbackRoute, model);
|
||||
}
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
const model = this.get('model');
|
||||
const fallbackRoute = this.get('fallbackRoute');
|
||||
|
||||
model.get('errors').clear();
|
||||
model.rollbackAttributes();
|
||||
|
||||
this.transitionToRoute(fallbackRoute, model);
|
||||
},
|
||||
},
|
||||
});
|
Reference in a new issue