503 lines
13 KiB
JavaScript
503 lines
13 KiB
JavaScript
function distinctlyInput(input) {
|
|
// Wenn das aktuell gewählte Feld gefüllt wird
|
|
if ($('#distinctlyInput' + input).val().length >= 1) {
|
|
input++; // Fahre fort mit dem nächsten Feld
|
|
if ($('#distinctlyInput' + input).length) {
|
|
$('#distinctlyInput' + input).focus().select(); // Fokus auf das nächste Feld setzen
|
|
}
|
|
}
|
|
// Wenn das aktuell gewählte Feld geleert wird
|
|
else if ($('#distinctlyInput' + input).val().length === 0 && input > 1) {
|
|
input--; // Gehe zum vorherigen Feld
|
|
$('#distinctlyInput' + input).focus().select(); // Fokus auf das vorherige Feld setzen
|
|
}
|
|
}
|
|
|
|
|
|
function pageload(view, meta) { // Funktion zum Laden des Inhalts
|
|
|
|
secondaryNavigation("close"); // Schließe das Stecker-Menü
|
|
page = window.location.hash.substr(1); // Hole die aufzurufende Seite über den URL-Hash (#xy)
|
|
|
|
if(page.length === 0) {
|
|
|
|
page = "index";
|
|
|
|
}
|
|
|
|
var loadingTimer = setTimeout(function() {
|
|
$("#content").addClass("loading");
|
|
message("Die Seite befindet sich im Aufbau...");
|
|
}, 2000); // 2 Sekunden warten
|
|
|
|
|
|
$.ajax({
|
|
url: "/pagecontent/" + page + ".php?view=" + view + "&meta=" + meta, // Pfad der zu ladenden Seite aufbauen
|
|
error: function(jqXHR, textStatus, errorThrown) { // Wenn ein Fehler bei der Anfrage auftritt (z.B. Netzwerkprobleme)
|
|
|
|
message("Es ist ein unerwarteter Fehler aufgetreten. Der Seiteninhalt konnte nicht geladen werden!");
|
|
|
|
|
|
},
|
|
success: function(result){ // Abfrage erfolgreich
|
|
clearTimeout(loadingTimer);
|
|
$("#content").removeClass("loading");
|
|
$("#content").html(result);
|
|
$("div.navigation>div").removeClass("active"); // Alle Buttons inaktiv
|
|
$("#" + page).addClass("active"); // Button mit Klasse "page" wird aktiv geschaltet (im Menü)
|
|
}});
|
|
}
|
|
|
|
function checkForReload(page) {
|
|
|
|
page_hash = window.location.hash.substr(1);
|
|
|
|
if(page_hash == page) {
|
|
pageload();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function checkConnection(last) { // Verbindunsstatus überwachen // Last ist der letzte gemessene Netzwerkzustand
|
|
$.ajax({
|
|
url: "/actions/connection-test.php?a=" + Date.now(), // verändere idr URL leicht, damit der Server nicht cached
|
|
timeout: 5000, // maximale Wartezeit sind 5 Sekunden; alles darüber wird als zu unzuverlässig angesehen
|
|
error: function(jqXHR, textStatus, errorThrown) { // Wenn ein Fehler bei der Anfrage auftritt (z.B. Netzwerkprobleme)
|
|
|
|
$(".navigation-footer").html('<div class="connection-indicator false"></div>Keine Verbindung<img class="infrago-logo" src="/vendor/DB_InfraGo_logo_red_black_100px_rgb.svg" width="100%" />');
|
|
console.error("Fehler bei der Anfrage:", textStatus, errorThrown);
|
|
|
|
if (last != 1) { // letzter Zustand war "online" // Vermeiden von ständigen Nachrichten
|
|
message("Keine Verbindung"); // Werfe eine Nachricht
|
|
}
|
|
|
|
setTimeout(function() { // nächste Prüfung in 5 Sekunden
|
|
checkConnection(1); // der Status offline wird mit übertragen
|
|
}, 5000);
|
|
},
|
|
success: function(data) { // Verbindung iO
|
|
setTimeout(function() { // nächste Prüfung in 5 Sekunden
|
|
checkConnection();
|
|
}, 5000);
|
|
|
|
if (data == 'true') { // der Rückgabewert ist true, alles IO
|
|
$(".navigation-footer").html('<div class="connection-indicator true"></div>Verbunden<img class="infrago-logo" src="/vendor/DB_InfraGo_logo_red_black_100px_rgb.svg" width="100%" />');
|
|
if (last == 1) { // war der letzte Status noch "offline", wird der Nutzer benachrichtigt
|
|
message("Verbindung wiederhergestellt!");
|
|
}
|
|
} else { // außergewöhnlicher Fehler, aber möglich
|
|
message("Keine Verbindung"); // Verbindung dennoch unbrauchbar, wenn keine Daten geladen werden
|
|
$(".navigation-footer").html('<div class="connection-indicator false"></div>Keine Verbindung<img class="infrago-logo" src="/vendor/DB_InfraGo_logo_red_black_100px_rgb.svg" width="100%" />');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
var pinRowNumber = 0;
|
|
|
|
|
|
function connectPins(startPoint, endPoint, origin) {
|
|
|
|
|
|
const encoded = $('#bridge-editor-img').attr("meta");
|
|
const decoded = decodeURIComponent(encoded);
|
|
let myArray = JSON.parse(decoded);
|
|
|
|
|
|
console.log(myArray);
|
|
|
|
length = myArray.length;
|
|
lengthNext = length + 1;
|
|
lengthPrev = length -1 ;
|
|
|
|
|
|
myArray[length] = [];
|
|
myArray[length][0] = startPoint;
|
|
myArray[length][1] = endPoint;
|
|
$(".pin-table").append('<div class="row" id="pinRow_' + length + '"><span>' + startPoint + '</span><img src="/vendor/icons/data-transfer-both.svg" height="30px"/><span>' + endPoint + '</span><img style="transform: rotate(0deg); padding-top: 17.5px;" src="/vendor/icons/trash.svg" onclick="removePin(' + length + ')" height="30px"/></div>');
|
|
|
|
|
|
|
|
var myJsonStringURL = encodeURI(JSON.stringify(myArray));
|
|
|
|
|
|
$('#bridge-editor-img').attr("meta", myJsonStringURL);
|
|
|
|
|
|
$('#bridge-editor-img').attr("style", "background-image: url('../stecker.php?data=" + myJsonStringURL + "')");
|
|
|
|
|
|
$('#bridge-editor-edit').attr("value", pinRowNumber);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
function removePin(row) {
|
|
const encoded = $('#bridge-editor-img').attr("meta");
|
|
const decoded = decodeURIComponent(encoded);
|
|
let myArray = JSON.parse(decoded);
|
|
|
|
myArray[row] = [];
|
|
myArray[row][0] = "";
|
|
myArray[row][1] = "";
|
|
|
|
$("#pinRow_" + row).hide();
|
|
|
|
var myJsonStringURL = encodeURI(JSON.stringify(myArray));
|
|
|
|
|
|
$('#bridge-editor-img').attr("meta", myJsonStringURL);
|
|
|
|
|
|
$('#bridge-editor-img').attr("style", "background-image: url('../stecker.php?data=" + myJsonStringURL + "')");
|
|
|
|
|
|
$('#bridge-editor-edit').attr("value", pinRowNumber);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function programBridge(number) { // Checkboxen für die Auswahl der Brücken im Programm-Editor
|
|
|
|
let myArray = []; // initialisiere Array
|
|
|
|
index = 0;
|
|
|
|
for (i = 0; i <= number; i++) { // iteriere durch alle Checkboxen
|
|
if ($('#programSelect_' + i).is(":checked")) { // wenn gesetzt
|
|
myArray[index] = $('#programSelect_' + i).val(); // Hänge die Brücken-ID dem Programm an
|
|
index++;
|
|
}
|
|
}
|
|
var myJsonString = JSON.stringify(myArray); // kreiere URL
|
|
|
|
$('#program-editor-img').attr("src", "stecker.php?translate=true&data=" + myJsonString); // aktualisiere das Bild
|
|
console.log("OK");
|
|
|
|
}
|
|
|
|
function excludeBridge(number) { // Checkboxen für die Auswahl der Brücken im Programm-Editor
|
|
|
|
let myArray = []; // initialisiere Array
|
|
let myArraySubtrahend = []; // initialisiere Array
|
|
|
|
index = 0;
|
|
indexSubtrahend = 0;
|
|
|
|
for (i = 0; i < number; i++) { // iteriere durch alle Checkboxen
|
|
if ($('#programSelect_' + i).is(":checked")) { // wenn gesetzt
|
|
myArray[index] = JSON.parse($('#programSelect_' + i).val());
|
|
index++;
|
|
}
|
|
else {
|
|
myArraySubtrahend[indexSubtrahend] = JSON.parse($('#programSelect_' + i).val());
|
|
indexSubtrahend++;
|
|
}
|
|
}
|
|
var myJsonString = JSON.stringify(myArray); // kreiere URL
|
|
var myJsonStringSubtrahend = JSON.stringify(myArraySubtrahend); // kreiere URL
|
|
|
|
|
|
$('#result-editor-result').attr("src", "stecker.php?data=" + myJsonString); // aktualisiere das Bild
|
|
|
|
|
|
$('#database-bridges-hidden').attr("value", encodeURI(myJsonStringSubtrahend));
|
|
|
|
|
|
console.log("OK");
|
|
|
|
}
|
|
|
|
|
|
function search(page,special) { // Datenbanksuche
|
|
|
|
value = $('#database-search-term').val(); // Suchbegriff, wenn die Datenbank durchsucht wird
|
|
|
|
if(page == 'results') {
|
|
if (special == "x") { // die Vorschläge werden ignoriert
|
|
value = ""; // Lösche Eingabe virtuell
|
|
}
|
|
}
|
|
|
|
$.get("/pagecontent/database-search.php", {
|
|
meta: value, // Suchbegriff
|
|
view: page // je nachdem, von wo aus die Suche ausgelöst wurde
|
|
},
|
|
function(data, status) {
|
|
if (status == "success") {
|
|
if(page == 'results') { // je nachdem, von wo aus die Suche ausgelöst wurde, anderen Container verändern
|
|
$("div.search-container div.results").html(data);
|
|
}
|
|
if(page == 'program') {
|
|
$("div.inventory-table").html(data);
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
function save(page, action, meta) { // prinzipiell gleiche Funktion wie getcontent, jedoch mit Abfragen von JS-Werten
|
|
|
|
suppress_page_reload = 0;
|
|
|
|
if (page == "bridge-editor") {
|
|
|
|
if (action == "edit" || action == "add") {
|
|
|
|
number_entry = $('#bridge-editor-edit').val(); // von PHP fixierter Wert (Anzahl der zu Beginn vorhandenen Felder)
|
|
|
|
let myArray = {}; // Initialisiere myArray als Objekt
|
|
|
|
|
|
const encoded = $('#bridge-editor-img').attr("meta");
|
|
const decoded = decodeURIComponent(encoded);
|
|
myArray["pins"] = JSON.parse(decoded);
|
|
|
|
if (action == "add") { // wird die Brücke neu angelegt, muss ein Name gewählt werden
|
|
myArray["name"] = prompt("Bitte noch einen Namen festlegen (nur Zahlen):");
|
|
}
|
|
|
|
|
|
var myJsonString = JSON.stringify(myArray); // verpacke alle Pin-Brücken als JSON
|
|
|
|
|
|
meta = myJsonString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (page == "program-editor") {
|
|
|
|
if (action == "edit" || action == "add") {
|
|
|
|
|
|
|
|
let myArray = {}; // Initialisiere als leeres, multidimensionales, indexiertes Array
|
|
myArray["bridges"] = []; // Initialisiere als leeres Array
|
|
|
|
index = 0;
|
|
|
|
for (i = 0; i <= meta; i++) {
|
|
if ($('#programSelect_' + i).is(":checked")) {
|
|
myArray["bridges"][index] = $('#programSelect_' + i).val();
|
|
index++;
|
|
}
|
|
}
|
|
|
|
|
|
if (action == "add") {
|
|
myArray["programID"] = [];
|
|
for (i = 0; i <= 4; i++) {
|
|
j = i + 1;
|
|
myArray["programID"][i] = $('#distinctlyInput' + j).val().toUpperCase();
|
|
}
|
|
}
|
|
|
|
myArray["programDescription"] = $('#program-description').val();
|
|
|
|
|
|
|
|
console.log(myArray);
|
|
|
|
var myJsonString = JSON.stringify(myArray);
|
|
console.log(myJsonString); // Zeigt die JSON-Ausgabe in der Konsole an
|
|
|
|
meta = myJsonString;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
if (page == "inventory" && action == "add") {
|
|
|
|
|
|
let myArray = {};
|
|
myArray["name"] = $('#database-search-term').val();
|
|
|
|
myArray["bridges-hidden"] = $('#database-bridges-hidden').val();
|
|
myArray["special"] = $('#database-special').val();
|
|
|
|
|
|
myArray["programCache"] = [];
|
|
for (i = 0; i <= 4; i++) {
|
|
j = i + 1;
|
|
myArray["programCache"][i] = $('#distinctlyInput' + j).val().toUpperCase();
|
|
}
|
|
|
|
console.log(myArray);
|
|
|
|
var myJsonString = JSON.stringify(myArray);
|
|
console.log(myJsonString); // Zeigt die JSON-Ausgabe in der Konsole an
|
|
|
|
meta = myJsonString;
|
|
|
|
suppress_page_reload = 1;
|
|
|
|
|
|
}
|
|
|
|
console.log("/actions/" + page + ".php?action=" + action + "&meta=" + meta);
|
|
|
|
$.get("/actions/" + page + ".php", {
|
|
action: action,
|
|
meta: meta
|
|
|
|
},
|
|
function(data, status) {
|
|
if (status == "success") {
|
|
data = JSON.parse(data);
|
|
if (data[0] == true) {
|
|
if (suppress_page_reload != 1) {
|
|
window.location.href = "#" + page;
|
|
pageload();
|
|
}
|
|
|
|
message(data[1]);
|
|
} else {
|
|
message(data[1]);
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
function secondaryNavigation(animation, content) {
|
|
|
|
|
|
|
|
|
|
if (animation == "open") {
|
|
|
|
|
|
$.get("/pagecontent/plug-select.php", {
|
|
|
|
|
|
},
|
|
function(data, status) {
|
|
if (status == "success") {
|
|
if (data != 'false') {
|
|
$("#navigation-secondary").css("left", "250px");
|
|
$(".navigation-header").attr("onclick", "secondaryNavigation('close','plug-select')");
|
|
setTimeout(function() {
|
|
$("#navigation-secondary").html(data);
|
|
console.log(data);
|
|
}, 200);
|
|
} else {
|
|
window.location.href = "#";
|
|
|
|
alert("Die Inhalte konnten nicht abgerufen werden. Vergewissern Sie sich, dass Sie mit dem WLAN-Netzwerk verbunden sind und laden Sie bei Bedarf die Seite neu.");
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
$("#navigation-secondary").css("left", "-250px");
|
|
$(".navigation-header").attr("onclick", "secondaryNavigation('open','plug-select')");
|
|
}
|
|
|
|
}
|
|
|
|
function changeSettings(type, value, meta) {
|
|
|
|
$.get("/actions/save-settings.php", {
|
|
type: type,
|
|
value: value,
|
|
meta: meta
|
|
},
|
|
function(data, status) {
|
|
if (status == "success") {
|
|
if (data == 'true') {
|
|
applySettings(type);
|
|
pageload();
|
|
} else {
|
|
window.location.href = '#index';
|
|
pageload();
|
|
|
|
alert("Die Inhalte konnten nicht abgerufen werden. Vergewissern Sie sich, dass Sie mit dem WLAN-Netzwerk verbunden sind und laden Sie bei Bedarf die Seite neu.");
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function applySettings(type) {
|
|
|
|
secondaryNavigation('close');
|
|
|
|
$.get("/actions/apply-settings.php", {
|
|
type: type
|
|
},
|
|
function(data, status) {
|
|
if (status == "success") {
|
|
if (data != 'false') {
|
|
|
|
if (type == "plug") {
|
|
|
|
$(".navigation-header>div").html(data);
|
|
}
|
|
} else {
|
|
window.location.href = "#";
|
|
|
|
alert("Die Inhalte konnten nicht abgerufen werden. Vergewissern Sie sich, dass Sie mit dem WLAN-Netzwerk verbunden sind und laden Sie bei Bedarf die Seite neu.");
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
function message(content) {
|
|
$("#message-box").html(content);
|
|
$("#message-box").css("display", "block");
|
|
setTimeout(function() {
|
|
$("#message-box").css("transform", "translateY(0)");
|
|
}, 50);
|
|
setTimeout(function() {
|
|
setTimeout(function() {
|
|
$("#message-box").css("display", "none");
|
|
}, 500);
|
|
$("#message-box").css("transform", "translateY(calc(100% + 5px))");
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(window).bind('beforeunload', function() {
|
|
$("#warning").css("display", "block");
|
|
return 'Are you sure you want to leave?';
|
|
|
|
});
|
|
|
|
|
|
|
|
|