/*
* 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: '',
text: '
Account Set Up!
',
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: '',
text: 'Account Linked!
',
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();
}