Better behavior when network/geocoding API is slow
This commit is contained in:
parent
333c0282f0
commit
4369bb80c0
@ -234,9 +234,21 @@ function countPackages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addPackageByAddress(address, citystate, type, callback) {
|
function addPackageByAddress(address, citystate, type, callback) {
|
||||||
$.getJSON(SETTINGS.geocodeapi, {
|
var requestfinished = false;
|
||||||
|
var searchingdialogopen = false;
|
||||||
|
$.ajax({
|
||||||
|
url: SETTINGS.geocodeapi,
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
address: address + " " + citystate
|
address: address + " " + citystate
|
||||||
}, function (resp) {
|
},
|
||||||
|
timeout: 15 * 1000,
|
||||||
|
success: function (resp) {
|
||||||
|
if (searchingdialogopen) {
|
||||||
|
app.dialog.close();
|
||||||
|
searchingdialogopen = false;
|
||||||
|
}
|
||||||
|
requestfinished = true;
|
||||||
if (resp.status == "OK") {
|
if (resp.status == "OK") {
|
||||||
if (resp.accuracy.ok) {
|
if (resp.accuracy.ok) {
|
||||||
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback);
|
addPackage(resp.address.street, resp.coords[0], resp.coords[1], type, callback);
|
||||||
@ -254,10 +266,27 @@ function addPackageByAddress(address, citystate, type, callback) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
playSound("error");
|
playSound("error");
|
||||||
app.dialog.alert(resp.message, "Error");
|
app.dialog.alert(resp.message, "Error");
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
error: function (jqXHR, status, errorThrown) {
|
||||||
|
if (searchingdialogopen) {
|
||||||
|
app.dialog.close();
|
||||||
|
searchingdialogopen = false;
|
||||||
|
}
|
||||||
|
requestfinished = true;
|
||||||
|
playSound("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