Location Speichern geht? abrufen der gespeicherten location aus properties muss noch gemacht werden

This commit is contained in:
Carsten Graf
2025-06-11 22:52:30 +02:00
parent 22cc4fe99c
commit b6fa2d69e7
8 changed files with 319 additions and 14 deletions

View File

@@ -103,7 +103,7 @@
</div>
</form>
</div>
<!-- Times Management Section -->
<div class="section">
<h2>🏆 Zeiten verwalten</h2>
@@ -174,6 +174,26 @@
</form>
</div>
<div class="section">
<h2>📍 Standort</h2>
<div id="locationRestrictionNotice" class="restriction-notice" style="display: none;">
🔒 Standort-Konfiguration ist nur mit Lizenz Level 3 oder höher verfügbar. Aktuelle Lizenz: Level <span id="currentLocationLicenseLevel">0</span>
</div>
<form id="locationForm">
<div class="form-group">
<label for="locationSelect">Standort auswählen:</label>
<select id="locationSelect" name="location" required>
<option value="">Bitte wählen...</option>
</select>
</div>
<div class="button-group">
<button type="submit" id="locationSubmitBtn" class="btn btn-primary">
💾 Standort speichern
</button>
</div>
</form>
</div>
<!-- OTA Update Section -->
<div class="section">
<h2>🔄 OTA Update</h2>
@@ -251,6 +271,7 @@
updateCurrentTimeDisplay();
loadLicence();
loadWifiSettings();
loadLocations();
};
// Aktuelle Zeit anzeigen (Live-Update)
@@ -429,6 +450,7 @@
// Check license level and update OTA button accordingly
updateOTAButtonAccess(data.tier || 0);
updateWifiButtonAccess(data.tier || 0)
updateLocationAccess(data.tier || 0);
})
.catch((error) => console.log("Info konnte nicht geladen werden"));
}
@@ -494,6 +516,9 @@
showMessage("Bitte WLAN-Namen eingeben", "error");
return;
}
if (!confirm("Der Server wird nach dem setzten neu gestartet. Fortsetzten?")) {
return;
}
fetch("/api/set-wifi", {
method: "POST",
@@ -762,6 +787,113 @@
);
}
//location functions
// Locations laden und Dropdown befüllen
function loadLocations() {
fetch("/api/location/")
.then((response) => response.json())
.then((data) => {
const select = document.getElementById("locationSelect");
// Vorhandene Optionen löschen (außer der ersten "Bitte wählen...")
while (select.children.length > 1) {
select.removeChild(select.lastChild);
}
// Neue Optionen aus Backend-Response hinzufügen
data.forEach((location) => {
const option = document.createElement("option");
option.value = location.id;
option.textContent = location.name;
select.appendChild(option);
});
// Aktuell gespeicherten Standort laden
loadCurrentLocation();
})
.catch((error) => {
console.log("Locations konnten nicht geladen werden:", error);
showMessage("Fehler beim Laden der Standorte", "error");
});
}
// Aktuell gespeicherten Standort laden
function loadCurrentLocation() {
fetch("/api/get-location")
.then((response) => response.json())
.then((data) => {
if (data.locationId) {
document.getElementById("locationSelect").value = data.locationId;
}
})
.catch((error) => {
console.log("Aktueller Standort konnte nicht geladen werden:", error);
});
}
// Location-Zugriff basierend auf Lizenz-Level kontrollieren
function updateLocationAccess(licenseLevel) {
const locationSubmitBtn = document.getElementById("locationSubmitBtn");
const locationRestrictionNotice = document.getElementById("locationRestrictionNotice");
const locationCurrentLevelSpan = document.getElementById("currentLocationLicenseLevel");
const locationSelect = document.getElementById("locationSelect");
const level = parseInt(licenseLevel) || 0;
if (level >= 3) {
// Lizenz Level 3 oder höher - Form aktivieren
locationSubmitBtn.classList.remove("btn-disabled");
locationSubmitBtn.disabled = false;
locationSelect.disabled = false;
locationRestrictionNotice.style.display = "none";
} else {
// Lizenz Level unter 3 - Form deaktivieren
locationSubmitBtn.classList.add("btn-disabled");
locationSubmitBtn.disabled = true;
locationSelect.disabled = true;
locationRestrictionNotice.style.display = "block";
locationCurrentLevelSpan.textContent = level;
}
}
// Location Form Handler
document.getElementById("locationForm").addEventListener("submit", function(e) {
e.preventDefault();
const locationSubmitBtn = document.getElementById("locationSubmitBtn");
// Lizenz-Level prüfen
if (locationSubmitBtn.disabled || locationSubmitBtn.classList.contains("btn-disabled")) {
showMessage("Standort-Konfiguration erfordert Lizenz Level 3 oder höher", "error");
return;
}
const locationId = document.getElementById("locationSelect").value;
if (!locationId) {
showMessage("Bitte einen Standort auswählen", "error");
return;
}
// Standort an Backend senden
fetch("/api/set-location", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: "locationId=" + encodeURIComponent(locationId),
})
.then((response) => response.json())
.then((data) => {
if (data.success) {
showMessage("Standort erfolgreich gespeichert!", "success");
} else {
showMessage("Fehler beim Speichern des Standorts", "error");
}
})
.catch((error) => showMessage("Verbindungsfehler", "error"));
});
// Status-Nachricht anzeigen
function showMessage(message, type) {
const statusDiv = document.getElementById("statusMessage");