Better behavior when network/geocoding API is slow
This commit is contained in:
parent
333c0282f0
commit
4369bb80c0
@ -148,7 +148,7 @@ function addPackage(address, latitude, longitude, type, callback) {
|
|||||||
packageID: packageID
|
packageID: packageID
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addAutofillEntry(address);
|
addAutofillEntry(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,30 +234,59 @@ function countPackages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addPackageByAddress(address, citystate, type, callback) {
|
function addPackageByAddress(address, citystate, type, callback) {
|
||||||
$.getJSON(SETTINGS.geocodeapi, {
|
var requestfinished = false;
|
||||||
address: address + " " + citystate
|
var searchingdialogopen = false;
|
||||||
}, function (resp) {
|
$.ajax({
|
||||||
if (resp.status == "OK") {
|
url: SETTINGS.geocodeapi,
|
||||||
if (resp.accuracy.ok) {
|
dataType: 'json',
|
||||||
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback);
|
data: {
|
||||||
|
address: address + " " + citystate
|
||||||
|
},
|
||||||
|
timeout: 15 * 1000,
|
||||||
|
success: function (resp) {
|
||||||
|
if (searchingdialogopen) {
|
||||||
|
app.dialog.close();
|
||||||
|
searchingdialogopen = false;
|
||||||
|
}
|
||||||
|
requestfinished = true;
|
||||||
|
if (resp.status == "OK") {
|
||||||
|
if (resp.accuracy.ok) {
|
||||||
|
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback);
|
||||||
|
} else {
|
||||||
|
playSound("error");
|
||||||
|
app.dialog.confirm(
|
||||||
|
"The address \"" + address + "\" couldn't be reliably located. Add it anyways?",
|
||||||
|
"Accuracy Warning",
|
||||||
|
function (ok) {
|
||||||
|
if (resp.address.street == "") {
|
||||||
|
addPackage(address, resp.coords[0], resp.coords[1], type, callback);
|
||||||
|
} else {
|
||||||
|
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
playSound("error");
|
playSound("error");
|
||||||
app.dialog.confirm(
|
app.dialog.alert(resp.message, "Error");
|
||||||
"The address \"" + address + "\" couldn't be reliably located. Add it anyways?",
|
|
||||||
"Accuracy Warning",
|
|
||||||
function (ok) {
|
|
||||||
if (resp.address.street == "") {
|
|
||||||
addPackage(address, resp.coords[0], resp.coords[1], type, callback);
|
|
||||||
} else {
|
|
||||||
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
} else {
|
error: function (jqXHR, status, errorThrown) {
|
||||||
|
if (searchingdialogopen) {
|
||||||
|
app.dialog.close();
|
||||||
|
searchingdialogopen = false;
|
||||||
|
}
|
||||||
|
requestfinished = true;
|
||||||
playSound("error");
|
playSound("error");
|
||||||
app.dialog.alert(resp.message, "Error");
|
app.dialog.alert("There was a network issue while finding the address. Please try adding the item again.", "Error");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Open a loading message if there's a delay finding the address
|
||||||
|
setTimeout(function () {
|
||||||
|
if (!requestfinished) {
|
||||||
|
app.dialog.preloader("Searching for address...");
|
||||||
|
searchingdialogopen = true;
|
||||||
|
}
|
||||||
|
}, 750);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user