🔧 Fix location name logic: User determines name, API only provides coordinates

- Removed automatic API location name usage
- User input from locationSearch field is used as location name
- API search only provides coordinates (latitude/longitude)
- User has full control over location naming
- Search functionality purely for coordinate lookup
This commit is contained in:
2025-09-08 21:44:18 +02:00
parent 7d88ad036d
commit b610d85313

View File

@@ -68,33 +68,33 @@ function toggleTokenFields() {
}
}, 400);
}
}
}
const secret = "542ff224606c61fb3024e22f76ef9ac8";
const secret = "542ff224606c61fb3024e22f76ef9ac8";
function isValidMac(mac) {
function isValidMac(mac) {
const pattern = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$|^[0-9A-Fa-f]{12}$/;
return pattern.test(mac);
}
}
function showMessage(elementId, message, isError = false) {
function showMessage(elementId, message, isError = false) {
const messageDiv = document.getElementById(elementId);
messageDiv.textContent = message;
messageDiv.classList.add("show");
setTimeout(() => {
messageDiv.classList.remove("show");
}, 4000);
}
}
function showError(message) {
function showError(message) {
showMessage("error", message, true);
}
}
function showSuccess(message) {
function showSuccess(message) {
showMessage("success", message, false);
}
}
function setLoading(isLoading) {
function setLoading(isLoading) {
const btnText = document.getElementById("btn-text");
const btn = document.querySelector(".generate-btn");
@@ -107,9 +107,9 @@ function toggleTokenFields() {
btn.disabled = false;
btn.style.opacity = '1';
}
}
}
async function saveToDatabase(token, tier) {
async function saveToDatabase(token, tier) {
const description = document.getElementById("description").value.trim();
const standorte = document.getElementById("standorte").value.trim();
@@ -139,9 +139,9 @@ function toggleTokenFields() {
throw new Error(`Automatisches Speichern fehlgeschlagen. Server nicht erreichbar.\n\nFühren Sie folgenden SQL-Befehl manuell aus:\n${sql}`);
}
}
}
async function generateLicense() {
async function generateLicense() {
const macInput = document.getElementById("mac").value.trim();
const tierInput = document.getElementById("tier").value.trim();
const resultDiv = document.getElementById("result");
@@ -172,7 +172,7 @@ function toggleTokenFields() {
// Standort automatisch speichern, falls vorhanden
let locationSaved = false;
const locationName = document.getElementById('realLocationName')?.value || document.getElementById('locationSearch')?.value?.trim();
const locationName = document.getElementById('locationSearch')?.value?.trim();
const latitude = document.getElementById('latitude')?.textContent;
const longitude = document.getElementById('longitude')?.textContent;
@@ -234,9 +234,9 @@ function toggleTokenFields() {
} finally {
setLoading(false);
}
}
}
async function copyToClipboard() {
async function copyToClipboard() {
const licenseOutput = document.getElementById("license-output");
const copyBtn = document.getElementById("copyButton");
@@ -266,30 +266,30 @@ function toggleTokenFields() {
copyBtn.classList.remove("copied");
}, 2000);
}
}
}
// Enter key support
document.addEventListener('keypress', function(e) {
// Enter key support
document.addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
generateLicense();
}
});
});
// Input formatting for MAC address
document.getElementById('mac').addEventListener('input', function(e) {
// Input formatting for MAC address
document.getElementById('mac').addEventListener('input', function (e) {
let value = e.target.value.replace(/[^0-9A-Fa-f]/g, '');
if (value.length > 12) value = value.substr(0, 12);
// Add colons every 2 characters
value = value.replace(/(.{2})/g, '$1:').replace(/:$/, '');
e.target.value = value;
});
});
// Input event listener für Lizenzstufe
document.getElementById('tier').addEventListener('input', toggleTokenFields);
// Input event listener für Lizenzstufe
document.getElementById('tier').addEventListener('input', toggleTokenFields);
// Standortsuche-Funktionalität
async function searchLocation(buttonElement) {
// Standortsuche-Funktionalität
async function searchLocation(buttonElement) {
const locationInput = document.getElementById('locationSearch').value.trim();
const coordinatesDiv = document.getElementById('coordinates');
const mapContainer = document.getElementById('mapContainer');
@@ -331,18 +331,8 @@ function toggleTokenFields() {
const lat = parseFloat(location.lat);
const lon = parseFloat(location.lon);
// Echten Standortnamen aus der API speichern
const realLocationName = location.display_name || location.name || locationInput;
// Verstecktes Feld für echten Standortnamen erstellen/aktualisieren
let locationNameField = document.getElementById('realLocationName');
if (!locationNameField) {
locationNameField = document.createElement('input');
locationNameField.type = 'hidden';
locationNameField.id = 'realLocationName';
document.body.appendChild(locationNameField);
}
locationNameField.value = realLocationName;
// Der Name wird vom User bestimmt - nur Koordinaten aus der API verwenden
// Kein verstecktes Feld nötig, da der User den Namen selbst eingibt
// Koordinaten anzeigen
updateCoordinates(lat, lon);
@@ -353,7 +343,7 @@ function toggleTokenFields() {
mapContainer.style.display = 'block';
// Erfolgsmeldung
showSuccess(`Standort "${realLocationName}" erfolgreich gefunden! Klicken Sie auf die Karte, um den Pin zu verschieben.`);
showSuccess(`Koordinaten für "${locationInput}" erfolgreich gefunden! Klicken Sie auf die Karte, um den Pin zu verschieben.`);
} catch (error) {
showError(`Fehler bei der Standortsuche: ${error.message}`);
@@ -366,10 +356,10 @@ function toggleTokenFields() {
searchBtn.disabled = false;
}
}
}
}
// Koordinaten aktualisieren
function updateCoordinates(lat, lon) {
// Koordinaten aktualisieren
function updateCoordinates(lat, lon) {
const latitudeSpan = document.getElementById('latitude');
const longitudeSpan = document.getElementById('longitude');
@@ -377,10 +367,10 @@ function toggleTokenFields() {
latitudeSpan.textContent = lat.toFixed(6);
longitudeSpan.textContent = lon.toFixed(6);
}
}
}
// Interaktive Karte erstellen
function createInteractiveMap(initialLat, initialLon) {
// Interaktive Karte erstellen
function createInteractiveMap(initialLat, initialLon) {
const mapFrame = document.getElementById('mapFrame');
// Verwende Leaflet.js für interaktive Karte
@@ -397,10 +387,10 @@ function toggleTokenFields() {
// Leaflet.js laden und Karte initialisieren
loadLeafletAndCreateMap(initialLat, initialLon);
}
}
// Leaflet.js laden und Karte erstellen
function loadLeafletAndCreateMap(initialLat, initialLon) {
// Leaflet.js laden und Karte erstellen
function loadLeafletAndCreateMap(initialLat, initialLon) {
// Prüfe ob Leaflet bereits geladen ist
if (typeof L !== 'undefined') {
createMap(initialLat, initialLon);
@@ -418,10 +408,10 @@ function toggleTokenFields() {
leafletScript.src = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js';
leafletScript.onload = () => createMap(initialLat, initialLon);
document.head.appendChild(leafletScript);
}
}
// Karte mit Leaflet erstellen
function createMap(initialLat, initialLon) {
// Karte mit Leaflet erstellen
function createMap(initialLat, initialLon) {
try {
const map = L.map('map').setView([initialLat, initialLon], 15);
@@ -437,7 +427,7 @@ function toggleTokenFields() {
}).addTo(map);
// Marker-Drag Event
marker.on('dragend', function(event) {
marker.on('dragend', function (event) {
const newLat = event.target.getLatLng().lat;
const newLon = event.target.getLatLng().lng;
updateCoordinates(newLat, newLon);
@@ -445,7 +435,7 @@ function toggleTokenFields() {
});
// Klick-Event auf die Karte
map.on('click', function(event) {
map.on('click', function (event) {
const newLat = event.latlng.lat;
const newLon = event.latlng.lng;
@@ -466,14 +456,14 @@ function toggleTokenFields() {
console.error('Fehler beim Erstellen der Karte:', error);
// Fallback zu iframe
const mapFrame = document.getElementById('mapFrame');
const mapUrl = `https://www.openstreetmap.org/export/embed.html?bbox=${initialLon-0.01},${initialLat-0.01},${initialLon+0.01},${initialLat+0.01}&layer=mapnik&marker=${initialLat},${initialLon}`;
const mapUrl = `https://www.openstreetmap.org/export/embed.html?bbox=${initialLon - 0.01},${initialLat - 0.01},${initialLon + 0.01},${initialLat + 0.01}&layer=mapnik&marker=${initialLat},${initialLon}`;
mapFrame.innerHTML = `<iframe src="${mapUrl}" width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" title="Standort auf der Karte"></iframe>`;
}
}
}
// Standort in Datenbank speichern
async function saveLocationToDatabase() {
const locationName = document.getElementById('realLocationName')?.value || document.getElementById('locationSearch').value.trim();
const locationName = document.getElementById('locationSearch').value.trim();
const latitude = document.getElementById('latitude').textContent;
const longitude = document.getElementById('longitude').textContent;
const saveBtn = document.getElementById('saveLocationBtn');
@@ -527,15 +517,15 @@ function toggleTokenFields() {
saveBtn.innerHTML = '💾 Standort in Datenbank speichern';
saveBtn.disabled = false;
}
}
}
// Zurück zum Dashboard
function goBackToDashboard() {
// Zurück zum Dashboard
function goBackToDashboard() {
window.location.href = '/admin-dashboard';
}
}
// Logout-Funktion
async function logout() {
// Logout-Funktion
async function logout() {
try {
const response = await fetch('/api/v1/public/logout', {
method: 'POST',
@@ -558,13 +548,13 @@ function toggleTokenFields() {
// Bei Fehler trotzdem zur Login-Seite weiterleiten
window.location.href = '/login';
}
}
}
// Enter-Taste für Standortsuche
document.addEventListener('DOMContentLoaded', function() {
// Enter-Taste für Standortsuche
document.addEventListener('DOMContentLoaded', function () {
const locationSearch = document.getElementById('locationSearch');
if (locationSearch) {
locationSearch.addEventListener('keypress', function(e) {
locationSearch.addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
searchLocation();
}
@@ -574,10 +564,10 @@ function toggleTokenFields() {
// Add cookie settings button functionality
const cookieSettingsBtn = document.getElementById('cookie-settings-footer');
if (cookieSettingsBtn) {
cookieSettingsBtn.addEventListener('click', function() {
cookieSettingsBtn.addEventListener('click', function () {
if (window.cookieConsent) {
window.cookieConsent.resetConsent();
}
});
}
});
});