protected route

This commit is contained in:
Matthew Dillon 2015-07-10 09:29:12 -08:00
parent 72c957f8dc
commit eb1a8bb6e3
41 changed files with 56 additions and 43 deletions

View file

@ -0,0 +1,24 @@
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
save: function() {
let strain = this.get('strain');
if (strain.get('isDirty')) {
strain.save().then((strain) => {
this.transitionToRoute('strains.show', strain);
}, (err) => {
this.get('flashMessages').error(err.responseJSON.error);
});
} else {
this.transitionToRoute('strains.index');
}
},
cancel: function() {
this.transitionToRoute('strains.index');
},
},
});

View file

@ -0,0 +1,34 @@
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
beforeModel: function(transition) {
this._super(transition);
if (this.get('session.currentUser.role') === 'R') {
this.transitionTo('strains.index');
}
},
model: function() {
return Ember.RSVP.hash({
strain: this.store.createRecord('strain'),
species: this.store.findAll('species'), // Need for dropdown
});
},
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();
}
},
},
});

View file

@ -0,0 +1,7 @@
{{
forms/strain-form
strain=strain
species=species
save="save"
cancel="cancel"
}}