This repository has been archived on 2025-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
hymenobacterdotinfo/app/pods/protected/strains/new/route.js
2015-11-10 14:31:38 -07:00

42 lines
1.2 KiB
JavaScript

import Ember from 'ember';
import ElevatedAccess from '../../../../mixins/elevated-access';
const { Route } = Ember;
export default Route.extend(ElevatedAccess, {
// Required for ElevatedAccess mixin
fallbackRouteBefore: 'protected.strains.index',
fallbackRouteAfter: 'protected.strains.show',
model: function() {
return Ember.RSVP.hash({
strain: this.store.createRecord('strain'),
species: this.store.findAll('species'), // Need for dropdown
});
},
// Overriding afterModel because of RSVP hash
afterModel: function(models) {
if (!models.strain.get('isNew') && !models.strain.get('canEdit')) {
this.transitionTo(this.get('fallbackRouteAfter'), models.strain.get('id'));
}
},
// Setting up controller because of RSVP hash
setupController: function(controller, models) {
controller.set('model', models.strain);
controller.set('speciesList', models.species);
},
actions: {
// Overriding willTransition because of RSVP hash
willTransition: function(/*transition*/) {
const controller = this.get('controller');
const model = controller.get('model');
if (model.get('isNew')) {
model.destroyRecord();
}
},
},
});