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.
HelenaExpressApp/www/assets/js/linkaccount.js

96 lines
3.6 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 setupNewAccount(name) {
app.dialog.preloader("Finishing up...");
apirequest(
SETTINGS.apis.registernew,
{
name: name
},
function (resp) {
app.dialog.close();
if (resp.status == "ERROR") {
app.dialog.alert(resp.msg, "Error");
return;
}
setStorage("client_uuid", resp.client_uuid);
setStorage("device_uuid", resp.device_uuid);
app.toast.create({
icon: '<i class="far fa-user-check fa-3x margin"></i>',
text: '<h3 class="no-margin-top">Account Set Up!</h3>',
position: 'center',
closeTimeout: 3000
}).open();
router.navigate("/home", {
transition: "f7-dive"
});
},
function (xhr) {
app.dialog.close();
try {
var error = $.parseJSON(xhr.responseText);
if (error && typeof error.msg != 'undefined') {
app.dialog.alert(error.msg + " (NEWAC_XHR)", "Error");
} else {
app.dialog.alert("A server or network error occurred. Try again later. (NEWAC_XHRNOMSG)", "Error");
}
} catch (ex) {
app.dialog.alert("A server error occurred. Try again later. (NEWAC_XHRBADJSON)", "Error");
}
}, "POST");
}
function setupExistingAccount(email, phone, invoiceid) {
app.dialog.preloader("Finding your account...");
apirequest(
SETTINGS.apis.registerexisting,
{
email: email,
phone: phone,
invoiceid: invoiceid
},
function (resp) {
app.dialog.close();
if (resp.status == "ERROR") {
app.dialog.alert(resp.msg, "Error");
return;
}
setStorage("client_uuid", resp.client_uuid);
setStorage("device_uuid", resp.device_uuid);
app.toast.create({
icon: '<i class="far fa-user-check fa-3x margin"></i>',
text: '<h3 class="no-margin-top">Account Linked!</h3>',
position: 'center',
closeTimeout: 3000
}).open();
router.navigate("/home", {
transition: "f7-dive"
});
},
function (xhr) {
app.dialog.close();
try {
var error = $.parseJSON(xhr.responseText);
if (error && typeof error.msg != 'undefined') {
app.dialog.alert(error.msg + " (LINKAC_XHR)", "Error");
} else {
app.dialog.alert("A server or network error occurred. Try again later. (LINKAC_XHRNOMSG)", "Error");
}
} catch (ex) {
app.dialog.alert("A server error occurred. Try again later. (LINKAC_XHRBADJSON)", "Error");
}
}, "POST");
}
function unlinkAccount() {
localStorage.removeItem("client_uuid");
localStorage.removeItem("device_uuid");
restartApplication();
}