You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HelenaExpressApp/www/assets/js/dropandsend.js

68 lines
2.5 KiB
JavaScript

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
function captureAndSendPickupCode() {
scanBarcode(function (result) {
var code = "";
var coderegex = /^[0-9a-zA-Z]{5,40}$/;
if (result.startsWith("https://helena.express/dropandsend#")) {
code = result.split("#")[1];
} else if (result.startsWith("https://helena.express/das/pickup#")) {
code = result.split("#")[1];
} else if (coderegex.test(result)) {
code = result;
} else {
app.dialog.alert("That's not a valid Drop and Send pickup code.", "Error");
return;
}
sendPickupCode(code);
}, function () {
app.dialog.prompt("Something went wrong while trying to scan the barcode. Type the location number to request a pickup.", "Send Pickup Code", function (code) {
if (code == "") {
app.dialog.alert("You didn't enter a location number.", "Error");
} else {
sendPickupCode(code);
}
}, function (cancel) {
}, "");
});
}
function sendPickupCode(code) {
app.dialog.preloader("Loading...");
apirequest(SETTINGS.apis.dropandsendpickup, {
phone: getStorage("phonenumber"),
accountkey: getStorage("accountkey"),
locationnumber: code
}, function (resp) {
app.dialog.close();
if (resp.status == "OK") {
app.dialog.alert("Thank you for using Helena Express! You'll get an emailed receipt after we pick up and process your package(s).", "Pickup Requested!");
} else if (resp.status == "ERROR") {
app.dialog.alert(resp.msg, "Error");
}
}, function (error) {
app.dialog.close();
app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later.", "Error");
});
}
$("#app").on("click", "#pickupCodeQRScanBtn", function () {
captureAndSendPickupCode();
});
$("#app").on("click", "#pickupCodeManualEntryBtn", function () {
app.dialog.prompt("Enter the location number to request a pickup.", "Send Pickup Code", function (code) {
if (code == "") {
app.dialog.alert("You didn't enter a location number.", "Error");
} else {
sendPickupCode(code);
}
}, function (cancel) {
}, "");
});