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.
123 lines
3.5 KiB
JavaScript
123 lines
3.5 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 showErrorScreen(message) {
|
|
$("#maindiv").load("parts/error.html", function () {
|
|
$("#errormsg").html(message);
|
|
});
|
|
}
|
|
|
|
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() {
|
|
$("#maindiv").removeClass("d-none");
|
|
getRoles(function (roles) {
|
|
for (var i = 0; i < roles.length; i++) {
|
|
loadRoleContent(roles[i]['id']);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
document.addEventListener("deviceready", function () {
|
|
inCordova = true;
|
|
});
|
|
|
|
$(document).ready(function () {
|
|
|
|
$("body").on("submit", ".apiform", function (event) {
|
|
event.preventDefault();
|
|
console.log($(this).serialize() + "&key=" + apiKey);
|
|
});
|
|
|
|
if (typeof nw !== 'undefined') {
|
|
inNwjs = true;
|
|
}
|
|
|
|
if (localStorage.getItem('server') === null || localStorage.getItem('apikey') === null) {
|
|
setupMode = true;
|
|
}
|
|
|
|
if (setupMode) {
|
|
loadSetupMode();
|
|
} else {
|
|
serverUrl = localStorage.getItem('server');
|
|
apiKey = localStorage.getItem('apikey');
|
|
loadUserMode();
|
|
}
|
|
});
|
|
|
|
|
|
function getAPIData(action, arguments, success) {
|
|
arguments['key'] = apiKey;
|
|
arguments['action'] = action;
|
|
$.get(serverUrl, arguments, function (data) {
|
|
success(data);
|
|
}).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.");
|
|
}
|
|
});
|
|
} |