Using mixins on new species

This commit is contained in:
Matthew Ryan Dillon 2015-11-03 13:54:45 -07:00
parent 76942a10d0
commit cc85ee6f27
5 changed files with 29 additions and 49 deletions

View file

@ -5,6 +5,9 @@ const { Mixin , inject: { service } } = Ember;
export default Mixin.create({
currentUser: service('session-account'),
fallbackRouteBefore: null,
fallbackRouteAfter: null,
beforeModel: function(transition) {
this._super(transition);
this.get('currentUser.account').then((user) => {
@ -19,4 +22,15 @@ export default Mixin.create({
this.transitionTo(this.get('fallbackRouteAfter'), model.get('id'));
}
},
actions: {
willTransition: function(/*transition*/) {
const controller = this.get('controller');
const model = controller.get('model');
if (model.get('isNew')) {
model.destroyRecord();
}
},
},
});

View file

@ -4,6 +4,8 @@ import ajaxError from '../utils/ajax-error';
const { Mixin } = Ember;
export default Mixin.create({
fallbackRoute: null,
actions: {
save: function() {
const model = this.get('model');