partial #1424
This commit is contained in:
parent
eb5459d853
commit
9d28b37ff6
@ -122,6 +122,17 @@ var Location = function( params ) {
|
||||
return self.address().replace(', USA', '');
|
||||
};
|
||||
|
||||
self.formattedWithDiff = function(){
|
||||
var address = self.formatted();
|
||||
if( self.entered() && self.entered() != '' ){
|
||||
var diff = self.getDiff();
|
||||
if( diff ){
|
||||
return address + ' - ' + diff;
|
||||
}
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
// Return the zip code of a location
|
||||
self.zip = function() {
|
||||
return self._properties.zip || '';
|
||||
@ -154,6 +165,39 @@ var Location = function( params ) {
|
||||
}
|
||||
};
|
||||
|
||||
self.getDiff = function(){
|
||||
if( !self.entered() ){
|
||||
return;
|
||||
}
|
||||
var _formatted = self.formatted();
|
||||
var _entered = self.entered();
|
||||
_formatted = _formatted.replace(/,/g, '');
|
||||
_entered = _entered.replace(/,/g, '');
|
||||
a_formatted = _formatted.split(" ");
|
||||
a_entered = _entered.split(" ");
|
||||
var diff = new Array();
|
||||
if( a_formatted.length > a_entered.length ){
|
||||
var long = a_formatted;
|
||||
var short = a_entered;
|
||||
} else {
|
||||
var long = a_entered;
|
||||
var short = a_formatted;
|
||||
}
|
||||
|
||||
for( x=0; x < long.length; x++ ){
|
||||
var has = false;
|
||||
for( y=0; y < short.length; y++ ){
|
||||
if( short[ y ] == long[ x ] ){
|
||||
has = true;
|
||||
}
|
||||
}
|
||||
if(!has){
|
||||
diff.push( long[ x ] );
|
||||
}
|
||||
}
|
||||
return diff.join(" ");
|
||||
};
|
||||
|
||||
// determine if verified
|
||||
self.verified = function() {
|
||||
return self._properties.verified;
|
||||
@ -177,6 +221,10 @@ var Location = function( params ) {
|
||||
return self._properties.entered;
|
||||
}
|
||||
|
||||
self.setEntered = function( entered ){
|
||||
self._properties.entered = entered;
|
||||
}
|
||||
|
||||
for (var x in params) {
|
||||
this._properties[x] = params[x];
|
||||
}
|
||||
|
||||
@ -316,6 +316,8 @@ NGApp.factory('OrderService', function ($http, $location, $rootScope, $filter, A
|
||||
|
||||
App.busy.makeBusy();
|
||||
|
||||
service.form.address = service.location.ordinalReplace( service.form.address );
|
||||
|
||||
var order = {
|
||||
address: service.form.address,
|
||||
phone: service.form.phone,
|
||||
@ -436,14 +438,12 @@ NGApp.factory('OrderService', function ($http, $location, $rootScope, $filter, A
|
||||
var isTheAddressOk = service.location.validateAddressType(theClosestAddress.result);
|
||||
if (isTheAddressOk) {
|
||||
theClosestAddress = theClosestAddress.location;
|
||||
if( service.form.address != theClosestAddress.formatted() ){
|
||||
theClosestAddress.setEntered( service.form.address );
|
||||
}
|
||||
// Now lets check if the restaurant deliveries at the given address
|
||||
var lat = theClosestAddress.lat();
|
||||
var lon = theClosestAddress.lon();
|
||||
if (service._useCompleteAddress) {
|
||||
service.form.address = theClosestAddress.formatted();
|
||||
// Update the object order
|
||||
order.address = service.form.address;
|
||||
}
|
||||
|
||||
var distance = service.location.distance( { from : { lat : lat, lon : lon }, to : { lat : service.restaurant.loc_lat, lon : service.restaurant.loc_long } } );
|
||||
distance = service.location.km2Miles( distance );
|
||||
@ -458,7 +458,7 @@ NGApp.factory('OrderService', function ($http, $location, $rootScope, $filter, A
|
||||
service.showForm = true;
|
||||
$('[name="pay-address"]').focus();
|
||||
// Write the found address at the address field, so the user can check it.
|
||||
service.form.address = theClosestAddress.formatted();
|
||||
service.form.address = theClosestAddress.formattedWithDiff();
|
||||
} );
|
||||
|
||||
// Log the error
|
||||
@ -474,7 +474,7 @@ NGApp.factory('OrderService', function ($http, $location, $rootScope, $filter, A
|
||||
var zipCode = theClosestAddress.zip();
|
||||
var typed_address = service.form.address;
|
||||
// Check if the typed address already has the zip code
|
||||
if (typed_address.indexOf(zipCode) < 0) {
|
||||
if ( typed_address.indexOf(zipCode) < 0 ) {
|
||||
var addressWithZip = typed_address + ' - ' + zipCode;
|
||||
service.form.address = addressWithZip;
|
||||
}
|
||||
@ -512,7 +512,6 @@ NGApp.factory('OrderService', function ($http, $location, $rootScope, $filter, A
|
||||
'restaurant': service.restaurant.name
|
||||
}, 'address not found');
|
||||
};
|
||||
order.address = service.location.ordinalReplace( order.address );
|
||||
// Call the geo method
|
||||
service.location.doGeocodeWithBound( order.address, latLong, success, error );
|
||||
return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user