protected route
This commit is contained in:
parent
72c957f8dc
commit
eb1a8bb6e3
41 changed files with 56 additions and 43 deletions
25
app/pods/protected/species/new/controller.js
Normal file
25
app/pods/protected/species/new/controller.js
Normal 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');
|
||||
},
|
||||
|
||||
},
|
||||
});
|
27
app/pods/protected/species/new/route.js
Normal file
27
app/pods/protected/species/new/route.js
Normal 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();
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
});
|
6
app/pods/protected/species/new/template.hbs
Normal file
6
app/pods/protected/species/new/template.hbs
Normal file
|
@ -0,0 +1,6 @@
|
|||
{{
|
||||
forms/species-form
|
||||
species=model
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
Reference in a new issue