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.

85 lines
2.3 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 inCordova = false;
var inNwjs = false;
var setupMode = false;
var serverUrl = "";
var apiKey = "";
function loadSetupMode() {
$("#setupbtn").click(function () {
var url = $("#serverurl").val();
if (url == "") {
url = "https://pcinfo.netsyms.com/api";
}
var key = $("#apikey").val();
if (key == "") {
alert("Please enter a valid API key.");
return;
}
$.getJSON(url, {
key: key,
action: 'ping'
}, function (resp) {
if (typeof resp['status'] != 'undefined') {
if (resp['status'] == 'ERROR') {
alert("Error: " + resp['message']);
return;
} else if (resp['status'] == 'OK') {
localStorage.setItem('server', url);
localStorage.setItem('apikey', key);
alert("Setup complete.");
document.location.href = "index.html";
} else {
alert("Invalid reply from server.");
}
} else {
alert("Invalid reply from server.");
}
}).fail(function (xhr) {
try {
var resp = JSON.parse(xhr.responseText);
if (typeof resp['status'] != 'undefined' && resp['status'] == 'ERROR') {
alert("Error: " + resp['message']);
} else {
alert("Error connecting to server.");
}
} catch (ex) {
alert("Error connecting to server.");
}
});
});
$("#setupmode").removeClass("d-none");
}
function loadUserMode() {
$("#usermode").removeClass("d-none");
}
document.addEventListener("deviceready", function () {
inCordova = true;
});
$(document).ready(function () {
if (typeof nw !== 'undefined') {
inNwjs = true;
}
if (localStorage.getItem('server') === null || localStorage.getItem('apikey') === null) {
setupMode = true;
}
if (setupMode) {
loadSetupMode();
} else {
loadUserMode();
}
});