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.
710 lines
26 KiB
JavaScript
710 lines
26 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/.
|
|
*/
|
|
|
|
var dynamicPages = [
|
|
"notary",
|
|
"telegram",
|
|
"trailer"
|
|
];
|
|
var compiledPages = {};
|
|
var pagesToCompile = [
|
|
"home",
|
|
"send",
|
|
"welcome",
|
|
"notary",
|
|
"servicearea",
|
|
"appointment",
|
|
"dropandsend",
|
|
"pickup",
|
|
"shop",
|
|
"shoppingcart_fragment",
|
|
"rateresult",
|
|
"account",
|
|
"trackresult",
|
|
"settings",
|
|
"receipts",
|
|
"trailer",
|
|
"kiosk",
|
|
"locations",
|
|
"quicksend"
|
|
];
|
|
console.log("Compiling page templates...");
|
|
for (var i = 0; i < pagesToCompile.length; i++) {
|
|
compiledPages[pagesToCompile[i]] = Template7.compile($.ajax({
|
|
type: "GET",
|
|
url: "./pages/" + pagesToCompile[i] + ".html",
|
|
async: false
|
|
}).responseText);
|
|
}
|
|
console.log("Compiled page templates.");
|
|
|
|
var routes = [
|
|
{
|
|
path: '/welcome',
|
|
content: compiledPages.welcome(),
|
|
name: 'welcome',
|
|
on: {
|
|
pageAfterIn: function () {
|
|
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/home',
|
|
name: 'home',
|
|
alias: ["/"],
|
|
on: {
|
|
pageBeforeIn: function () {
|
|
// make sure it's not shown right after account setup
|
|
var accountsetup = (inStorage("accountkey") && inStorage("accountnumber"));
|
|
if (accountsetup) {
|
|
$("#finishaccountsetupnag").css("display", "none");
|
|
}
|
|
}
|
|
},
|
|
async: function ( { resolve, reject }) {
|
|
// Show a nag message if no account is set up
|
|
var accountsetup = (inStorage("accountkey") && inStorage("accountnumber")) || getStorage("hideaccountnag") == "true";
|
|
// add escape hatch to regular website if running online
|
|
var escapehatch = false;
|
|
if (window.location.hostname == "app.helena.express") {
|
|
escapehatch = true;
|
|
}
|
|
resolve({
|
|
content: compiledPages.home({
|
|
accountsetup: accountsetup,
|
|
escapehatch: escapehatch,
|
|
pages: [
|
|
{
|
|
title: "Send a Package",
|
|
href: "/send",
|
|
icon: "fa-duotone fa-box-alt",
|
|
text: "Find locations or request a pickup."
|
|
},
|
|
{
|
|
title: "Notarize a Document",
|
|
href: "/notary",
|
|
icon: "fa-duotone fa-file-signature",
|
|
text: "Book a mobile notary visit."
|
|
},
|
|
{
|
|
title: "Locations",
|
|
href: "/locations",
|
|
icon: "fa-duotone fa-map-location-dot",
|
|
text: "Find a shipping kiosk or drop box near you."
|
|
},
|
|
{
|
|
title: "Shop for Supplies",
|
|
href: "/shop",
|
|
icon: "fa-duotone fa-shopping-cart",
|
|
text: "Get boxes, labels, and shipping supplies delivered to your door."
|
|
},
|
|
{
|
|
title: "Write a Telegram",
|
|
href: "/telegram",
|
|
icon: "fa-duotone fa-typewriter",
|
|
text: "Send a hand-delivered telegram anywhere in the Helena area."
|
|
},
|
|
{
|
|
title: "My Account",
|
|
href: "/account",
|
|
icon: "fa-duotone fa-user-circle",
|
|
text: "View receipts, get account number, update payment method, and more."
|
|
}
|
|
]
|
|
})
|
|
}, {});
|
|
}
|
|
},
|
|
{
|
|
path: '/send',
|
|
name: 'send',
|
|
async: function ( { resolve, reject }) {
|
|
resolve({
|
|
content: compiledPages.send({
|
|
pages: [
|
|
{
|
|
title: "Self-Serve Kiosk",
|
|
href: "/kiosk",
|
|
icon: "fa-duotone fa-display",
|
|
text: "Visit a friendly neighborhood PostalPoint™ shipping kiosk to send mail and packages with no lines or hassle."
|
|
},
|
|
{
|
|
title: "Drop Box",
|
|
href: "/das",
|
|
icon: "fa-duotone fa-box-alt",
|
|
text: "Just drop your package into a Drop and Send℠ drop box and scan the QR code. We'll charge the postage to your Helena Express account."
|
|
},
|
|
{
|
|
title: "Pickup",
|
|
href: "/pickup",
|
|
icon: "fa-duotone fa-home",
|
|
text: "Leave your package on your porch and we'll pick it up and ship it for you. No postage or appointment needed."
|
|
},
|
|
{
|
|
title: "Appointment",
|
|
href: "/appointment/shipping",
|
|
icon: "fa-duotone fa-calendar-alt",
|
|
text: "We'll come to your home or business on your schedule. It's like a post office in your driveway!"
|
|
},
|
|
{
|
|
title: "Mobile Shipping Center",
|
|
href: "/mobile",
|
|
icon: "fa-duotone fa-caravan",
|
|
text: "Our Mobile Shipping Center is a specially-designed trailer for printing postage, shipping mail and packages, and more."
|
|
}
|
|
]
|
|
})
|
|
}, {});
|
|
}
|
|
},
|
|
{
|
|
path: '/notary',
|
|
content: compiledPages.notary(),
|
|
name: 'notary',
|
|
on: {
|
|
pageBeforeIn: function () {
|
|
dyncontent = getDynamicPageContent("notary");
|
|
if (dyncontent != null) {
|
|
$("#notary-dyncontent").html(dyncontent);
|
|
}
|
|
},
|
|
pageAfterIn: function () {
|
|
app.swiper.destroy("#notary-info-swiper");
|
|
app.swiper.create("#notary-info-swiper", {
|
|
pagination: {
|
|
el: "#notary-info-swiper-pagination",
|
|
type: "bullets",
|
|
clickable: true
|
|
}
|
|
});
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/locations',
|
|
content: compiledPages.locations(),
|
|
name: 'locations',
|
|
on: {
|
|
pageAfterIn: function () {
|
|
loadLocationMap();
|
|
},
|
|
pageAfterOut: function () {
|
|
locationMap = null;
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/servicearea',
|
|
content: compiledPages.servicearea(),
|
|
name: 'servicearea',
|
|
on: {
|
|
pageAfterIn: function () {
|
|
loadServiceAreaMap();
|
|
},
|
|
pageAfterOut: function () {
|
|
serviceAreaMap = null;
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/quicksend',
|
|
name: 'quicksend',
|
|
async: function ( {resolve}) {
|
|
resolve({
|
|
content: compiledPages.quicksend({
|
|
from_name: inStorage("quicksend_name") ? getStorage("quicksend_name") : "",
|
|
from_company: inStorage("quicksend_company") ? getStorage("quicksend_company") : "",
|
|
from_street1: inStorage("quicksend_street1") ? getStorage("quicksend_street1") : (inStorage("lastpickupaddress") ? getStorage("lastpickupaddress") : ""),
|
|
from_street2: inStorage("quicksend_street2") ? getStorage("quicksend_street2") : "",
|
|
from_zip: inStorage("quicksend_zip") ? getStorage("quicksend_zip") : (inStorage("lastpickupzipcode") ? getStorage("lastpickupzipcode") : ""),
|
|
from_phone: inStorage("quicksend_phone") ? getStorage("quicksend_phone") : ""
|
|
})
|
|
}, {});
|
|
},
|
|
},
|
|
{
|
|
path: '/appointment',
|
|
name: 'appointment',
|
|
async: function ( { resolve, reject }) {
|
|
resolve({
|
|
content: compiledPages.appointment({
|
|
services: [
|
|
{
|
|
title: "Package Pickup",
|
|
text: "A courier will come to you and ship your mail, packages, etc.",
|
|
icon: "fa-duotone fa-hand-holding-box",
|
|
serviceid: "shipping"
|
|
},
|
|
{
|
|
title: "Mobile Notary",
|
|
text: "A notary public will come to you and notarize your documents.",
|
|
icon: "fa-duotone fa-file-signature",
|
|
serviceid: "notary"
|
|
}
|
|
]
|
|
})
|
|
}, {
|
|
});
|
|
},
|
|
routes: [
|
|
{
|
|
path: "/:serviceId",
|
|
async: function ( { resolve, reject, to }) {
|
|
var url = SETTINGS.apis.appointmentredirect + "?service=" + to.params.serviceId;
|
|
if ($("body").hasClass("dark")) {
|
|
url += "&darkmode=1";
|
|
}
|
|
resolve({
|
|
content: compiledPages.appointment({
|
|
url: url,
|
|
serviceid: to.params.serviceId
|
|
})
|
|
}, {
|
|
});
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: '/das',
|
|
name: 'dropandsend',
|
|
content: compiledPages.dropandsend(),
|
|
on: {
|
|
pageBeforeIn: function () {
|
|
checkIfAccountGoodWithPaymentMethod(function (ok) {
|
|
if (!ok) {
|
|
$("#addPaymentMethodNag").css("display", "");
|
|
}
|
|
}, function (error) {
|
|
$("#addPaymentMethodNag").css("display", "");
|
|
});
|
|
var dayofweek = formatTimestamp("l");
|
|
switch (dayofweek) {
|
|
case "Saturday":
|
|
case "Sunday":
|
|
$("#pickupWeekendWarning").css("display", "");
|
|
break;
|
|
}
|
|
var hourofday = formatTimestamp("H");
|
|
if (hourofday > 12 + 3) {
|
|
$("#pickupLateInDayWarning").css("display", "");
|
|
}
|
|
},
|
|
pageAfterOut: function () {
|
|
dropboxMap = null;
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/postalpoint',
|
|
name: 'postalpoint',
|
|
async: function ( {resolve, reject}) {
|
|
app.dialog.preloader("Loading...");
|
|
apirequest(SETTINGS.apis.postalpoint_locations, [], function (resp) {
|
|
app.dialog.close();
|
|
|
|
var locations = [];
|
|
for (var i = 0; i < resp.features.length; i++) {
|
|
locations.push({
|
|
name: resp.features[i].properties.name,
|
|
info: resp.features[i].properties.info,
|
|
hours: resp.features[i].properties.hours,
|
|
geo: resp.features[i].geometry.coordinates[1] + "," + resp.features[i].geometry.coordinates[0]
|
|
});
|
|
}
|
|
resolve({
|
|
content: compiledPages.postalpoint({
|
|
locations: locations
|
|
})
|
|
}, {});
|
|
}, function (error) {
|
|
app.dialog.close();
|
|
app.dialog.alert("Couldn't download the list of PostalPoint locations. Try again later.", "Whoops!");
|
|
sendErrorReport("PostalPoint", "Loading locations");
|
|
resolve({
|
|
content: compiledPages.postalpoint({
|
|
locations: []
|
|
})
|
|
}, {});
|
|
}, "GET");
|
|
},
|
|
on: {
|
|
pageBeforeIn: function () {
|
|
dyncontent = getDynamicPageContent("postalpoint");
|
|
if (dyncontent != null) {
|
|
$("#postalpoint-dyncontent").html(dyncontent);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/pickup',
|
|
name: 'pickup',
|
|
async: function ( {resolve}) {
|
|
resolve({
|
|
content: compiledPages.pickup({
|
|
streetaddress: inStorage("lastpickupaddress") ? getStorage("lastpickupaddress") : "",
|
|
zipcode: inStorage("lastpickupzipcode") ? getStorage("lastpickupzipcode") : ""
|
|
})
|
|
}, {});
|
|
},
|
|
on: {
|
|
pageBeforeIn: function () {
|
|
checkIfAccountGoodWithPaymentMethod(function (ok) {
|
|
if (!ok) {
|
|
$("#addPaymentMethodNag").css("display", "");
|
|
}
|
|
}, function (error) {
|
|
$("#addPaymentMethodNag").css("display", "");
|
|
});
|
|
var dayofweek = formatTimestamp("l");
|
|
switch (dayofweek) {
|
|
case "Saturday":
|
|
case "Sunday":
|
|
$("#pickupWeekendWarning").css("display", "");
|
|
break;
|
|
}
|
|
var hourofday = formatTimestamp("H");
|
|
if (hourofday > 12 + 4) {
|
|
$("#pickupLateInDayWarning").css("display", "");
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/shop',
|
|
name: 'shop',
|
|
async: loadShopPage,
|
|
on: {
|
|
pageBeforeIn: function () {
|
|
checkIfAccountGoodWithPaymentMethod(function (ok) {
|
|
if (!ok) {
|
|
$("#addPaymentMethodNag").css("display", "");
|
|
}
|
|
}, function (error) {
|
|
$("#addPaymentMethodNag").css("display", "");
|
|
});
|
|
updateCart();
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/mobile',
|
|
name: 'trailer',
|
|
async: function ( {resolve, reject}) {
|
|
app.dialog.preloader("Checking the schedule...");
|
|
apirequest(SETTINGS.apis.trailerschedule, [], function (resp) {
|
|
app.dialog.close();
|
|
|
|
resolve({
|
|
content: compiledPages.trailer({
|
|
schedule: resp
|
|
})
|
|
}, {});
|
|
}, function (error) {
|
|
app.dialog.close();
|
|
app.dialog.alert("Couldn't get the latest schedule. Try again later.", "Whoops!");
|
|
sendErrorReport("Trailer", "Loading schedule");
|
|
resolve({
|
|
content: compiledPages.trailer({
|
|
schedule: []
|
|
})
|
|
}, {});
|
|
}, "GET");
|
|
},
|
|
on: {
|
|
pageBeforeIn: function () {
|
|
dyncontent = getDynamicPageContent("trailer");
|
|
if (dyncontent != null) {
|
|
$("#trailer-dyncontent").html(dyncontent);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/kiosk',
|
|
name: 'kiosk',
|
|
async: function ( {resolve, reject}) {
|
|
app.dialog.preloader("Loading...");
|
|
apirequest(SETTINGS.apis.locations, [], function (resp) {
|
|
app.dialog.close();
|
|
|
|
var kioskLocations = [];
|
|
for (var i = 0; i < resp.features.length; i++) {
|
|
if (resp.features[i].properties.branding != "PP") {
|
|
continue;
|
|
}
|
|
kioskLocations.push({
|
|
name: resp.features[i].properties.name,
|
|
hours: resp.features[i].properties.hours,
|
|
info: resp.features[i].properties.info,
|
|
geo: "geo:" + (Math.round(resp.features[i].geometry.coordinates[1] * 1000000) / 1000000) + "," + (Math.round(resp.features[i].geometry.coordinates[0] * 1000000) / 1000000)
|
|
});
|
|
}
|
|
|
|
resolve({
|
|
content: compiledPages.kiosk({
|
|
locations: kioskLocations
|
|
})
|
|
}, {});
|
|
}, function (error) {
|
|
app.dialog.close();
|
|
app.dialog.alert("Couldn't get the kiosk locations. Try again later.", "Whoops!");
|
|
sendErrorReport("Kiosks", "Loading locations");
|
|
resolve({
|
|
content: compiledPages.kiosk({
|
|
locations: []
|
|
})
|
|
}, {});
|
|
}, "GET");
|
|
},
|
|
on: {
|
|
pageBeforeIn: function () {
|
|
dyncontent = getDynamicPageContent("kiosk");
|
|
if (dyncontent != null) {
|
|
$("#kiosk-dyncontent").html(dyncontent);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/telegram',
|
|
name: 'telegram',
|
|
url: './pages/telegram.html',
|
|
on: {
|
|
pageBeforeIn: function () {
|
|
checkIfAccountGoodWithPaymentMethod(function (ok) {
|
|
if (!ok) {
|
|
$("#addPaymentMethodNag").css("display", "");
|
|
}
|
|
}, function (error) {
|
|
$("#addPaymentMethodNag").css("display", "");
|
|
});
|
|
dyncontent = getDynamicPageContent("telegram");
|
|
if (dyncontent != null) {
|
|
$("#telegram-dyncontent").html(dyncontent);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/track',
|
|
url: './pages/track.html',
|
|
name: 'track',
|
|
on: {
|
|
pageBeforeIn: function () {
|
|
addTrackingSuggestions();
|
|
$("#trackingcode").val("0");
|
|
app.input.validate("#trackingcode");
|
|
$("#trackingcode").val("");
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/rates',
|
|
url: './pages/rates.html',
|
|
name: 'rates',
|
|
on: {
|
|
pageAfterIn: function () {
|
|
initRateForm();
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/account',
|
|
name: 'account',
|
|
content: compiledPages.account(),
|
|
on: {
|
|
pageAfterIn: function () {
|
|
initAccountPage();
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/track/:code',
|
|
name: 'trackresult',
|
|
async: trackOpenAsync,
|
|
on: {
|
|
pageAfterIn: function () {
|
|
var mapboxel = document.getElementById("mapbox-track");
|
|
var trackingMap = new MapControl(mapboxel, false);
|
|
trackingMap.reloadMap();
|
|
var latitude = $(mapboxel).data("latitude");
|
|
var longitude = $(mapboxel).data("longitude");
|
|
var accurate = $(mapboxel).data("accurate") == true;
|
|
var geoiscountrylevel = $(mapboxel).data("geoiscountrylevel") == true;
|
|
trackingMap.clearMarkersAndCenterMapOnNewMarker("package-marker", latitude, longitude, accurate, geoiscountrylevel);
|
|
}
|
|
}
|
|
},
|
|
{
|
|
path: '/receipts',
|
|
name: 'receipts',
|
|
async: function ( {resolve, reject}) {
|
|
app.dialog.preloader("Loading...");
|
|
apirequest(SETTINGS.apis.getreceipts, {
|
|
accountnumber: getStorage("accountnumber"),
|
|
accountkey: getStorage("accountkey")
|
|
}, function (success) {
|
|
app.dialog.close();
|
|
if (success.status == "OK") {
|
|
var receipts = success.receipts;
|
|
if (receipts.length == 0) {
|
|
receipts = false;
|
|
}
|
|
resolve({
|
|
content: compiledPages.receipts({
|
|
receipts: receipts
|
|
})
|
|
});
|
|
} else {
|
|
app.dialog.alert(success.msg, "Error");
|
|
sendErrorReport("Receipts", "Loading receipt list", success.msg);
|
|
reject();
|
|
}
|
|
}, function (xhr, status, error) {
|
|
app.dialog.close();
|
|
app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later.", "Error");
|
|
sendErrorReport("Receipts", "Couldn't load receipts", "Server/network problem: " + xhr.status + ": " + xhr.statusText);
|
|
reject();
|
|
}, "POST");
|
|
}
|
|
},
|
|
{
|
|
path: '/credits',
|
|
url: './pages/credits.html',
|
|
name: 'credits'
|
|
},
|
|
{
|
|
path: '/settings',
|
|
name: 'settings',
|
|
async: function ( {resolve}) {
|
|
var settings = [];
|
|
settings.push(
|
|
{
|
|
setting: "display",
|
|
title: "Display and Appearance",
|
|
text: "",
|
|
onclick: "router.navigate('/settings/display')",
|
|
link: true
|
|
}
|
|
);
|
|
|
|
settings.push(
|
|
{
|
|
setting: "resetaccount",
|
|
title: "Forget Account",
|
|
text: "Log out and disconnect from your Helena Express account.",
|
|
onclick: "resetAccountPrompt()",
|
|
link: true
|
|
},
|
|
{
|
|
setting: "versions",
|
|
title: "Helena Express app v" + app_version,
|
|
text: "Copyright © 2019-2023 Helena Express and Netsyms Technologies.",
|
|
onclick: ""
|
|
},
|
|
{
|
|
setting: "opensource",
|
|
title: "Credits and open source info",
|
|
text: "",
|
|
onclick: "router.navigate('/credits')",
|
|
link: true
|
|
},
|
|
{
|
|
setting: "legal",
|
|
title: "Terms of Use and Privacy Policy",
|
|
text: "",
|
|
onclick: "openBrowser('https://helena.express/appterms?mtm_campaign=HelenaExpressApp')",
|
|
link: true
|
|
},
|
|
{
|
|
setting: "analytics",
|
|
title: "Analytics",
|
|
text: "If turned on, we'll collect some anonymous information to help improve the app. It is not sent to any third parties.",
|
|
toggle: true,
|
|
checked: getStorage("analytics") !== "false",
|
|
onclick: ""
|
|
}, );
|
|
resolve({
|
|
content: compiledPages.settings({
|
|
page_title: "Settings",
|
|
settings: settings
|
|
})
|
|
});
|
|
},
|
|
routes: [
|
|
{
|
|
path: '/display',
|
|
name: 'settings',
|
|
async: function ( {resolve}) {
|
|
var settings = [
|
|
{
|
|
setting: "apptheme",
|
|
title: "Color theme",
|
|
select: true,
|
|
options: [
|
|
{
|
|
value: "auto",
|
|
label: "Auto",
|
|
selected: getStorage("apptheme") == null || getStorage("apptheme") == "auto"
|
|
},
|
|
{
|
|
value: "dark",
|
|
label: "Dark",
|
|
selected: getStorage("apptheme") == "dark"
|
|
},
|
|
{
|
|
value: "light",
|
|
label: "Light",
|
|
selected: getStorage("apptheme") == "light"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
setting: "animation",
|
|
title: "Animations",
|
|
select: true,
|
|
options: [
|
|
{
|
|
value: "auto",
|
|
label: "On",
|
|
selected: getStorage("animation") == null || getStorage("animation") == "auto" || getStorage("animation") == "on"
|
|
},
|
|
// {
|
|
// value: "on",
|
|
// label: "On",
|
|
// selected: getStorage("animation") == "on"
|
|
// },
|
|
{
|
|
value: "off",
|
|
label: "Off",
|
|
selected: getStorage("animation") == "off"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
setting: "hideaccountnag",
|
|
title: "Hide \"Finish Account Setup\"",
|
|
text: "",
|
|
toggle: true,
|
|
checked: getStorage("hideaccountnag") == "true",
|
|
onclick: ""
|
|
}
|
|
];
|
|
resolve({
|
|
content: compiledPages.settings({
|
|
page_title: "Display Settings",
|
|
settings: settings
|
|
})
|
|
});
|
|
}
|
|
}
|
|
]
|
|
}
|
|
];
|