Last active
December 17, 2015 15:28
-
-
Save pzuraq/5631464 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Case.Router.reopen({ | |
location: 'history' | |
}); | |
Case.Router.map(function() { | |
this.resource('inventory', function(){ | |
this.route('review'); | |
this.route('sheets'); | |
this.resource('vehicle', { path: '/vehicle/:vehicle_id' }, function(){ | |
this.route('index'); | |
this.route('details'); | |
this.route('additional'); | |
this.route('options'); | |
this.route('consignor'); | |
this.route('price'); | |
this.route('dmv'); | |
this.route('fees'); | |
this.route('description'); | |
this.route('photos'); | |
this.route('tasks'); | |
}); | |
}); | |
// Catch all route for any unmatched routes. Transitions back to index. | |
this.route('catchAll', { path: '*:' }); | |
}); | |
Case.CatchAllRoute = Ember.Route.extend({ | |
redirect: function() { | |
this.transitionTo('index'); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Case.VehicleFilterRoute = Ember.Route.extend({ | |
setupController: function(controller) { | |
controller.set('content', this.modelFor('vehicle')); | |
controller.set('BodyStyles', Case.BodyStyle.all()); | |
controller.set('Customers', Case.Customer.all()); | |
controller.set('DriveTrains', Case.DriveTrain.all()); | |
controller.set('Employees', Case.Employee.all()); | |
controller.set('FuelTypes', Case.FuelType.all()); | |
controller.set('IntMaterials', Case.IntMaterial.all()); | |
controller.set('Makes', Case.Make.all()); | |
controller.set('Models', Case.Model.all()); | |
controller.set('OdoStatuses', Case.OdoStatus.all()); | |
controller.set('PaintColors', Case.PaintColor.all()); | |
controller.set('Showrooms', Case.Showroom.all()); | |
controller.set('Transmissions', Case.Transmission.all()); | |
controller.set('Trims', Case.Trim.all()); | |
controller.set('VehicleOptions', Case.VehicleOption.all()); | |
// Sets the last 'filter,' or known path. This allows the user | |
// to navigate away from the current item, then return and be directed | |
// to the same subview as was open when they left. This is used in | |
// vehicle_route.js as well. | |
var vehicleController = this.controllerFor('vehicle'); | |
vehicleController.set('lastFilter', this.routeName); | |
} | |
}); | |
Case.VehicleDetailsRoute = Case.VehicleFilterRoute.extend(); | |
Case.VehicleAdditionalRoute = Case.VehicleFilterRoute.extend(); | |
Case.VehicleOptionsRoute = Case.VehicleFilterRoute.extend(); | |
Case.VehicleConsignorRoute = Case.VehicleFilterRoute.extend(); | |
Case.VehiclePriceRoute = Case.VehicleFilterRoute.extend(); | |
Case.VehicleDmvRoute = Case.VehicleFilterRoute.extend(); | |
Case.VehicleExpensesRoute = Case.VehicleFilterRoute.extend(); | |
Case.VehicleDescriptionRoute = Case.VehicleFilterRoute.extend(); | |
Case.VehiclePhotosRoute = Case.VehicleFilterRoute.extend(); | |
Case.VehicleTasksRoute = Case.VehicleFilterRoute.extend(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Case.VehicleRoute = Ember.Route.extend({ | |
renderTemplate: function(controller, model) { | |
this._super(); | |
// Get the last breadcrumb in the current route. This way we can check the route | |
// to see if it is vehicle.index. If so, redirect to details or last known filter | |
// (i.e. last page user was editing on, whatever that was. Maintains continuity.) | |
var lastCrumb = Case.get('Router.router.currentHandlerInfos').get('lastObject'); | |
console.log(lastCrumb); | |
// Check to see if the last crumb is the index. If so, redirect, if not continue. | |
if(lastCrumb.name.indexOf('vehicle') > 0) { | |
// Here we get the lastFilter, which is set in VehicleFilterRoutes. All vehicle | |
// subroutes extend VehicleFilterRoute, and so they set lastFilter to their route | |
// when entered. Thus, we can return to the route if we leave that vehicle to edit | |
// another or do something else. If lastFilter is not set, we default to | |
// vehicle.details. | |
var lastFilter = controller.get('lastFilter'); | |
this.transitionTo(lastFilter || 'vehicle.details'); | |
} | |
}, | |
setupController: function(controller, model) { | |
// Here we do two things. If the vehicle is inactive (has not been opened yet in | |
// this session) we set the active property of the vehicle to true so that it will | |
// appear in the module sidebar as a tab, and we open a transaction on the vehicle | |
// which will not be closed until the vehicle is closed (TODO: Add ability to close | |
// vehicle...) | |
if(model.get('active') === undefined){ | |
model.set('active', true); | |
controller.startEditing(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment