Files
AviationAssistantLink/js/script.js
T
2022-03-02 11:42:17 -05:00

74 lines
3.0 KiB
JavaScript

function connectToHostname() {
document.querySelector('#toast').MaterialSnackbar.showSnackbar({message: 'Connecting to Host....'});
var xmlhttp = new XMLHttpRequest();
xmlhttp.timeout = 5000;
xmlhttp.onerror = function() { document.querySelector('#toast').MaterialSnackbar.showSnackbar({message: 'Failed to Connect'}); }
xmlhttp.ontimeout = function () { document.querySelector('#toast').MaterialSnackbar.showSnackbar({message: 'Failed to Connect'}); };
xmlhttp.onload = function() {
document.querySelector('#toast').MaterialSnackbar.showSnackbar({message: 'Connected to Host!'});
document.getElementById("login").style.display = "block"
document.getElementById("main").style.display = "none"
}
xmlhttp.open("GET","http://"+document.getElementById("hostname").value+":5000/connection",true);
xmlhttp.send();
}
function login() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://127.0.0.1:5000/authentication", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.response == "OK") {
document.querySelector('#toast').MaterialSnackbar.showSnackbar({message: 'Authentication Success'});
window.location = "connected.html"
} else {
document.querySelector('#toast').MaterialSnackbar.showSnackbar({message: 'Invalid Login'});
}
}
}
xhr.send(JSON.stringify({
username: document.getElementById("username").value,
password: document.getElementById("password").value
}));
}
function logout() {
window.location = "index.html"
}
function mainUI() {
window.location = "sub_pages/ui.html"
// ABOVE IS TESTING, USE BELOW FOR PRODUCTION
// document.getElementById("iframe").setAttribute("src","http://"+document.getElementById("aa_ip").innerHTML+"/dump1090/gmap.html")
}
function pullInformation() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://127.0.0.1:5000/information", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.response)
data = JSON.parse(xhr.response)
document.getElementById("aa_header").innerHTML = data['name']
document.getElementById("aa_version").innerHTML = data['version']
document.getElementById("aa_ip").innerHTML = data['ip']
}
}
xhr.send();
}
function loadIP() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://127.0.0.1:5000/information", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.response)
data = JSON.parse(xhr.response)
document.getElementById("iframe").setAttribute("src","http://"+data['ip']+"/gmap.html")
}
}
xhr.send();
}