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,25 @@
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
save: function() {
let species = this.get('model');
if (species.get('isDirty')) {
species.save().then((species) => {
this.transitionToRoute('species.show', species.get('id'));
}, (err) => {
this.get('flashMessages').error(err.responseJSON.error);
});
} else {
species.deleteRecord();
this.transitionToRoute('species.index');
}
},
cancel: function() {
this.transitionToRoute('species.index');
},
},
});

View file

@ -0,0 +1,27 @@
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('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();
}
},
},
});

View file

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