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.
116 lines
3.4 KiB
JavaScript
116 lines
3.4 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 accountBalance = 0.0;
|
|
|
|
$(".view-main").on("ptr:refresh", ".ptr-content", function () {
|
|
loadHomePage(function () {
|
|
setTimeout(app.ptr.done, 500);
|
|
});
|
|
});
|
|
|
|
|
|
$(".view-main").on("card:open", ".card-expandable", function () {
|
|
$(".ptr-preloader").addClass("display-none");
|
|
});
|
|
|
|
$("#map-card").on("card:closed card:opened", function () {
|
|
leafletmap.invalidateSize();
|
|
});
|
|
|
|
$("#map-card").on("card:open", function () {
|
|
leafletgllayer._glMap.setPitch(20);
|
|
});
|
|
$("#map-card").on("card:close", function () {
|
|
leafletgllayer._glMap.setPitch(0);
|
|
});
|
|
|
|
$(".view-main").on("card:closed", ".card-expandable", function () {
|
|
$(".ptr-preloader").removeClass("display-none");
|
|
});
|
|
|
|
function loadBalance(callback) {
|
|
$("#balance-error-icon").addClass("display-none");
|
|
$("#balance-loading").removeClass("display-none");
|
|
callAPI("checkbalance", {
|
|
key: localStorage.getItem("key")
|
|
}, function (data) {
|
|
accountBalance = data.balance;
|
|
$("#balance-amount").text(data.balance);
|
|
$("#balance-loading").addClass("display-none");
|
|
$("#balance-error").text("");
|
|
callback(true);
|
|
}, function (msg) {
|
|
$("#balance-loading").addClass("display-none");
|
|
$("#balance-error-icon").css("display", "");
|
|
$("#balance-error").text(msg);
|
|
callback(false, msg);
|
|
});
|
|
}
|
|
|
|
function loadQrCode(callback) {
|
|
$("#receive-loading").removeClass("display-none");
|
|
callAPI("getprofile", {
|
|
key: localStorage.getItem("key"),
|
|
}, function (data) {
|
|
app.preloader.hide();
|
|
//if (data.profile.type * 1 > 1) {
|
|
var typeNumber = 4;
|
|
var errorCorrectionLevel = 'L';
|
|
var qr = qrcode(typeNumber, errorCorrectionLevel);
|
|
qr.addData(SETTINGS['webapp_url'] + '?sendto=' + data.profile.publicid);
|
|
qr.make();
|
|
var svg = qr.createSvgTag({
|
|
margin: 6,
|
|
scalable: true
|
|
});
|
|
var base64 = window.btoa(svg);
|
|
$("#qrcode").attr("src", 'data:image/svg+xml;base64,' + base64);
|
|
$("#qrcode-label").text(data.profile.publicid);
|
|
$("#receive-loading").addClass("display-none");
|
|
callback(true);
|
|
//}
|
|
}, function (msg) {
|
|
$("#receive-loading").addClass("display-none");
|
|
callback(false, msg);
|
|
});
|
|
}
|
|
|
|
function broadcastLocation() {
|
|
getLocation(function (position) {
|
|
callAPI("broadcast", {
|
|
key: localStorage.getItem("key"),
|
|
latitude: position.coords.latitude,
|
|
longitude: position.coords.longitude
|
|
}, function (success) {
|
|
app.toast.create({
|
|
text: "<i class=\"fas fa-check\"></i> Location sent!",
|
|
closeTimeout: 2000
|
|
}).open();
|
|
}, function (error) {
|
|
app.dialog.alert(error, "Error");
|
|
});
|
|
}, function (error) {
|
|
app.dialog.alert(error, "Location Error");
|
|
});
|
|
}
|
|
|
|
function loadHomePage(callback) {
|
|
var done = 0;
|
|
var total = 2;
|
|
loadBalance(function () {
|
|
done++;
|
|
if (done >= total) {
|
|
callback();
|
|
}
|
|
});
|
|
loadQrCode(function () {
|
|
done++;
|
|
if (done >= total) {
|
|
callback();
|
|
}
|
|
});
|
|
} |