diff --git a/app/pods/species/new/controller.js b/app/pods/species/new/controller.js index 10704f8..b3cb74e 100644 --- a/app/pods/species/new/controller.js +++ b/app/pods/species/new/controller.js @@ -18,12 +18,6 @@ export default Ember.Controller.extend({ }, cancel: function() { - let species = this.get('model'); - - if (species.get('isNew')) { - species.deleteRecord(); - } - this.transitionToRoute('species.index'); }, diff --git a/app/pods/species/new/route.js b/app/pods/species/new/route.js index 98741c6..0cdcf55 100644 --- a/app/pods/species/new/route.js +++ b/app/pods/species/new/route.js @@ -2,8 +2,25 @@ import Ember from 'ember'; import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'; export default Ember.Route.extend(AuthenticatedRouteMixin, { + beforeModel: function() { + if (this.get('session.currentUser.role') === 'R') { + this.transitionTo('species.index'); + } + }, + model: function() { return this.store.createRecord('species'); }, + actions: { + willTransition: function(transition) { + let controller = this.get('controller'); + let species = controller.get('model'); + + if (species.get('isNew')) { + species.deleteRecord(); + } + }, + }, + }); diff --git a/app/pods/strains/new/controller.js b/app/pods/strains/new/controller.js index a6c3139..fa0bcf2 100644 --- a/app/pods/strains/new/controller.js +++ b/app/pods/strains/new/controller.js @@ -17,12 +17,6 @@ export default Ember.Controller.extend({ }, cancel: function() { - let strain = this.get('strain'); - - if (strain.get('isNew')) { - strain.deleteRecord(); - } - this.transitionToRoute('strains.index'); }, diff --git a/app/pods/strains/new/route.js b/app/pods/strains/new/route.js index 03b7907..e2bdecb 100644 --- a/app/pods/strains/new/route.js +++ b/app/pods/strains/new/route.js @@ -2,6 +2,12 @@ import Ember from 'ember'; import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'; export default Ember.Route.extend(AuthenticatedRouteMixin, { + beforeModel: function() { + if (this.get('session.currentUser.role') === 'R') { + this.transitionTo('strains.index'); + } + }, + model: function() { return Ember.RSVP.hash({ strain: this.store.createRecord('strain'), @@ -9,12 +15,19 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { }); }, - afterModel: function(models) { - console.log('after model'); - }, - setupController: function(controller, models) { controller.setProperties(models); }, + actions: { + willTransition: function(transition) { + let controller = this.get('controller'); + let strain = controller.get('strain'); + + if (strain.get('isNew')) { + strain.deleteRecord(); + } + }, + }, + });