var RecoveryHandler = function(TripSvc, MapSvc, $location){ this.jobStates = { PENDING: "PENDING", ACCEPTED: "ACCEPTED", DRIVER_COLLECTED: "DRIVER_COLLECTED", PASSENGER_COLLECTED: "PASSENGER_COLLECTED" }; this.recoverState = function(response){ // EXAMPLE_SUCCESS_DRIVER_EN_ROUTE = { // "data": { // "job": { // "fare": { // "estFare": 210000, //estFare // "meteredFare": 0, // "bookingId": 0, // "jobFee": 21000, // "jobId": 2984, //jobId // "surchargeFee": 0, // "recommendedBookingFee": 0, // "surchargeFeeGST": 0, // "fareReceived": 0, // "id": 2960, // "driverTotalFareGST": 0, // "regulatedBookingFee": 0, // "dfv": -21000, // "tip": 0, // "actualFareGST": 0, // "creditGST": 0, // "bidGST": 1909, // "bid": 210000, //myBid // "farePaid": 0, // "regulatedBookingFeeGST": 0, // "dfvGST": -1909, // "driverTotalFare": 0, // "setMeteredFareAttempts": 0, // "credit": 0, // "meteredFareGST": 0, // "tipGST": 0, // "driverTotalCredit": 0, // "actualFare": 0, // "jobFeeGST": 1909 // }, // "passenger": { // "emailAddress": "", // "mobileNumber": "", // "passengerId": 0, // "deviceId": "ee9762f51d0383e2e23fd1d74c0413f25ed687b0" // }, // "jobSM": { // "lastChangeTimestamp": 1406729033, // "postTimestamp": 1406728949, // "jobState": "ACCEPTED", // "jobType": "FLAG_ALL", // "acceptTimestamp": 1406729033 // }, // "destination": { // "distance": 6182, //tripDistance // "destination": "Sea Point", //destinationAddress, geocode if destinationLatLng is needed (can use 'distance' to limit search results to relevant ones) // "tip": "" // }, // "driver": { //driverDetails // "driverIdTag": None, // "mobileNumber": "0820000000", // "vehicleClass": "TAXI_STANDARD", // "taxiNumber": None, // "driverType": "LUXURY", //taxiType, needs to be mapped // "deviceId": "92995048e0ab12ba324303e6361ad03b6c37cb39", //driverDeviceId // "vehicleNumber": "CA 1", // "position": { //MapSvc.mapOptions.center // "lat": -33.92648, // "lng": 18.4478433 // }, // "originDistance": 97.97016151903118, // "name": "Tester Testerson" // }, // "filter": { // "driverType": {}, // "bookingId": 0, // "vehicleClass": {}, // "id": 2960, // "jobId": 2984 // }, // "status": { // "pb": {}, // "points": { // "acceptPoints": 0, // "rejectPoints": 0, // "totalPoints": 0, // "ranking": 1, // "driverDeviceId": "92995048e0ab12ba324303e6361ad03b6c37cb39", // "payPoints": 0, // "abandonPoints": 0, // "completePoints": 0, // "originDistance": 97, // "jobId": 2984, // "reservePoints": 0, // "actualPoints": 0, // "passengerAbandonPoints": 0, // "collectPoints": 0, // "id": 13815, // "releasePoints": 0 // }, // "level": 0 // }, // "id": 2984, // "origin": { // "pickupPosition": { //fromLatLng, reverse geocode if fromAddressComponents are needed, MapSvc.mapOptions.center, MapSvc.marker_fromLocation, MapSvc.marker_destinationLocation // "lat": -33.9270211, // "lng": 18.4470053 // }, // "passengerCount": 1, // "pickupTimestamp": 1406728949, // "instructions211": "", // "pickupNumberObfuscated": "", // "pickupNumber": "7", //fromAddress // "locationId": -1, // "pickupStreet": "Sussex Street", //fromAddress // "pickupSuburb": "Woodstock", //fromAddress // "passengerPosition": { // "lat": 0.0, // "lng": 0.0 // }, // "timeZone": 0 // } // } // }, // "result": True // } if(!response.data.job){ return; } TripSvc.finishJobAndClearState(); switch (response.data.job.jobSM.jobState.toUpperCase()) { case this.jobStates.PENDING: this.recoverPendingJobState(response); break; case this.jobStates.ACCEPTED: this.recoverAcceptedJobState(response); break; case this.jobStates.PASSENGER_COLLECTED: case this.jobStates.DRIVER_COLLECTED: this.recoverDriverCollectedJobState(response); break; default: console.log('Received unknown jobState in RecoveryHandler: ' + response.data.job.jobSM.jobState.toUpperCase()); break; } }; this.recoverPendingJobState = function(response){ var job = response.data.job; TripSvc.fromLatLng = new google.maps.LatLng(job.origin.pickupPosition.lat, job.origin.pickupPosition.lng); TripSvc.destinationLatLng = new google.maps.LatLng(job.destination.destinationPosition.lat, job.destination.destinationPosition.lng); var addressParts = []; if (job.origin.pickupNumber){ addressParts.push(job.origin.pickupNumber); } addressParts.push(job.origin.pickupStreet, job.origin.pickupSuburb); TripSvc.fromAddress = addressParts.join(', '); TripSvc.destinationAddress = job.destination.destination; // suburb only // Geocoding work to fill in the blanks MapSvc.reverseGeocode(TripSvc.fromLatLng, function(geocoderResult){ TripSvc.fromAddress = geocoderResult.formatted_address; TripSvc.fromAddressComponents = geocoderResult.address_components; }); MapSvc.reverseGeocode(TripSvc.destinationLatLng, function(geocoderResult){ TripSvc.destinationAddress = geocoderResult.formatted_address; TripSvc.destinationAddressComponents = geocoderResult.address_components; }); TripSvc.generateTaxiTypeRangeLookup(response.data.branch); TripSvc.branch = response.data.branch; for(var i=0; i