...
+-
+
-
+ ++Phone Number++ + ++
+
diff --git a/www/assets/js/loyalty.js b/www/assets/js/loyalty.js new file mode 100644 index 0000000..7b3c64c --- /dev/null +++ b/www/assets/js/loyalty.js @@ -0,0 +1,52 @@ +/* + * 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 displayLoyaltyPoints() { + $("#loyalty-balance-box").addClass("display-none"); + $("#loyalty-error").html(""); + if (inStorage("phonenumber")) { + var phone = getStorage("phonenumber"); + } else { + $("#loyalty-error").text("Error: No phone number saved."); + } + app.dialog.preloader("Checking points balance..."); + apirequest(SETTINGS.apis.loyalty, {phone: phone}, function (success) { + app.dialog.close(); + if (success.status == "OK") { + $("#loyalty-credit-balance").text(success.credits + " points"); + $("#loyalty-balance-box").removeClass("display-none"); + + var canvas = document.createElement('canvas'); + + bwipjs.toCanvas(canvas, { + bcid: 'code128', // Barcode type + text: success.phone, // Text to encode + scaleX: 5, + scaleY: 1, + includetext: false, // Show human-readable text + textxalign: 'center', // Always good to set this + eclevel: 'M' + }); + document.getElementById("loyalty-barcode").src = canvas.toDataURL('image/png'); + } else { + $("#loyalty-balance-box").addClass("display-none"); + $("#loyalty-error").text("Error: " + success.message); + } + }, function (error) { + $("#loyalty-error").text("Error: Couldn't check your points balance. Try again later."); + }, "GET"); +} + +function savePhoneNumber() { + var phone = $("#phonenumber").val().replace(/\D/g, ''); + if (phone.length < 10) { + app.dialog.alert("Please enter a full 10-digit phone number.", "Oops!"); + return; + } + setStorage("phonenumber", phone); + router.refreshPage(); +} \ No newline at end of file diff --git a/www/index.html b/www/index.html index 90537f3..da06ebe 100644 --- a/www/index.html +++ b/www/index.html @@ -53,6 +53,7 @@ + \ No newline at end of file diff --git a/www/pages/loyalty.html b/www/pages/loyalty.html new file mode 100644 index 0000000..9a1f5c4 --- /dev/null +++ b/www/pages/loyalty.html @@ -0,0 +1,135 @@ + + +