protected route
This commit is contained in:
parent
72c957f8dc
commit
eb1a8bb6e3
41 changed files with 56 additions and 43 deletions
30
app/pods/protected/strains/edit/controller.js
Normal file
30
app/pods/protected/strains/edit/controller.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
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 {
|
||||
strain.deleteRecord();
|
||||
this.transitionToRoute('strains.show', strain);
|
||||
}
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
let strain = this.get('strain');
|
||||
|
||||
strain.get('errors').clear();
|
||||
strain.rollback();
|
||||
|
||||
this.transitionToRoute('strains.show', strain);
|
||||
},
|
||||
|
||||
},
|
||||
});
|
22
app/pods/protected/strains/edit/route.js
Normal file
22
app/pods/protected/strains/edit/route.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
model: function(params) {
|
||||
return Ember.RSVP.hash({
|
||||
strain: this.store.find('strain', params.strain_id),
|
||||
species: this.store.findAll('species'), // Need for dropdown
|
||||
});
|
||||
},
|
||||
|
||||
afterModel: function(models) {
|
||||
if (!models.strain.get('canEdit')) {
|
||||
this.transitionTo('strains.show', models.strain.get('id'));
|
||||
}
|
||||
},
|
||||
|
||||
setupController: function(controller, models) {
|
||||
controller.setProperties(models);
|
||||
},
|
||||
|
||||
});
|
7
app/pods/protected/strains/edit/template.hbs
Normal file
7
app/pods/protected/strains/edit/template.hbs
Normal file
|
@ -0,0 +1,7 @@
|
|||
{{
|
||||
forms/strain-form
|
||||
strain=strain
|
||||
species=species
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
Reference in a new issue