Handle opening tracking URLs in receipts

master
Skylar Ittner 12 months ago
parent 8e64fdfe62
commit ed1f4dddcf

@ -324,4 +324,21 @@ function loadReceiptHTMLIntoPopup(receiptid) {
app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later.", "Error");
sendErrorReport("Receipts", "Couldn't load receipt", "Server/network problem: " + xhr.status + ": " + xhr.statusText);
}, "POST");
}
function receiptiframeloadevent() {
$("#receiptvieweriframe").contents().find("a").each(function () {
$(this).attr("data-href", $(this).attr("href"));
$(this).attr("href", "#");
$(this).on("click", function (evt) {
var href = evt.target.getAttribute("data-href");
window.parent.openReceiptIframeLink(href);
});
});
}
function openReceiptIframeLink(href) {
if (handleDeepLink(href)) {
app.popup.close();
}
}

@ -141,6 +141,81 @@ function setupCordovaBarcodeScanner() {
};
}
/**
* Handle a deep link.
* @param {string} href the link
* @returns {boolean} true if handled, false if rejected.
*/
function handleDeepLink(href) {
var link = new URL(href);
if (link.host != "helena.express") {
return false;
}
if (link.hash) {
link.fragment = link.hash.substr(1);
}
switch (link.pathname) {
case "/":
break;
case "/app":
break;
case "/track":
if (link.fragment) {
router.navigate("/track/" + link.fragment);
} else {
router.navigate("/track");
}
break;
case "/rates":
router.navigate("/rates");
break;
case "/schedule":
router.navigate("/appointment");
break;
case "/shop":
router.navigate("/shop");
break;
case "/pickup":
router.navigate("/send");
break;
case "/telegram":
case "/telegram/":
router.navigate("/telegram");
break;
case "/das":
router.navigate("/das");
break;
case "/das/map":
router.navigate("/das");
break;
case "/das/pickup":
if (link.fragment) {
sendPickupCode(link.fragment);
} else {
router.navigate("/das");
}
break;
case "/das/account":
router.navigate("/account");
break;
case "/mobile":
case "/mobile/":
router.navigate("/mobile");
break;
case "/postalpoint":
case "/postalpoint/":
router.navigate("/postalpoint");
break;
case "/money":
router.navigate("/moneyorder");
break;
default:
openBrowser(link.href);
break;
}
return true;
}
function initCordova() {
platform_type = "cordova";
@ -221,70 +296,9 @@ function initCordova() {
}
IonicDeeplink.onDeepLink(function (link) {
if (link.host != "helena.express") {
return;
}
// Wait a bit so the home page has time to load first.
setTimeout(function () {
switch (link.path) {
case "/":
break;
case "/app":
break;
case "/track":
if (link.fragment) {
router.navigate("/track/" + link.fragment);
} else {
router.navigate("/track");
}
break;
case "/rates":
router.navigate("/rates");
break;
case "/schedule":
router.navigate("/appointment");
break;
case "/shop":
router.navigate("/shop");
break;
case "/pickup":
router.navigate("/send");
break;
case "/telegram":
case "/telegram/":
router.navigate("/telegram");
break;
case "/das":
router.navigate("/das");
break;
case "/das/map":
router.navigate("/das");
break;
case "/das/pickup":
if (link.fragment) {
sendPickupCode(link.fragment);
} else {
router.navigate("/das");
}
break;
case "/das/account":
router.navigate("/account");
break;
case "/mobile":
case "/mobile/":
router.navigate("/mobile");
break;
case "/postalpoint":
case "/postalpoint/":
router.navigate("/postalpoint");
break;
case "/money":
router.navigate("/moneyorder");
break;
default:
openBrowser(link.url);
break;
}
handleDeepLink(link.url);
}, 1000);
});
}, false);

@ -62,7 +62,7 @@
<div class="title">Receipt</div>
</div>
</div>
<iframe id="receiptvieweriframe"></iframe>
<iframe id="receiptvieweriframe" onload="receiptiframeloadevent()"></iframe>
</div>
</div>
Loading…
Cancel
Save