52 lines
1.9 KiB
JavaScript
52 lines
1.9 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 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();
|
|
} |