Behebt Gitea Issue #1 "Eigenen Standort verwenden" (zwei Teilprobleme): 1. Die Fehlermeldung bei fehlgeschlagener Geolocation-Abfrage (#app-status) liess sich bisher nicht schliessen und blockierte dauerhaft die UI. Neuer Schliessen-Button (#app-status-close), unabhaengig vom restlichen Bootstrap-Ablauf verdrahtet, damit er auch bei einem fruehen Init-Fehler funktioniert. 2. Es gab keine Moeglichkeit, den Standort manuell zu setzen, wenn die Browser-Geolocation fehlschlaegt oder nicht verfuegbar ist. Neues Modal (js/ui/manualLocation.js) mit Breiten-/Laengengrad-Eingabe, Validierung (aria-invalid/Inline-Fehler analog zum Ausflugsziel-Formular), setzt bei gueltiger Eingabe state.userLocation direkt - Karte, Liste und Entfernungsfilter reagieren automatisch darauf.
118 lines
3.4 KiB
JavaScript
118 lines
3.4 KiB
JavaScript
// Einstiegspunkt der Anwendung: initialisiert Store, Karte und Liste.
|
|
|
|
(function () {
|
|
const { initStore } = EventMap.store;
|
|
const { initMap, centerOnCoords, requestUserLocation } = EventMap.map;
|
|
const {
|
|
initList,
|
|
initDetail,
|
|
initForm,
|
|
initManualLocationForm,
|
|
initFilterPanel,
|
|
initPromptGenerator,
|
|
} = EventMap.ui;
|
|
|
|
function showFatalError(message) {
|
|
const status = document.getElementById('app-status');
|
|
const statusText = document.getElementById('app-status-text');
|
|
if (!status || !statusText) return;
|
|
statusText.textContent = message;
|
|
status.hidden = false;
|
|
}
|
|
|
|
function hideStatus() {
|
|
const status = document.getElementById('app-status');
|
|
const statusText = document.getElementById('app-status-text');
|
|
if (!status || !statusText) return;
|
|
status.hidden = true;
|
|
statusText.textContent = '';
|
|
}
|
|
|
|
// Verdrahtet den Schließen-Button der Statusmeldung unabhängig vom
|
|
// restlichen Bootstrap-Ablauf, damit er auch dann funktioniert, wenn
|
|
// bootstrap() selbst fehlschlägt und showFatalError() aus dem
|
|
// catch-Handler heraus aufgerufen wird (siehe Gitea Issue #1: die
|
|
// Fehlermeldung war bisher dauerhaft nicht schließbar).
|
|
function setupStatusClose() {
|
|
const closeBtn = document.getElementById('app-status-close');
|
|
if (!closeBtn) return;
|
|
closeBtn.addEventListener('click', hideStatus);
|
|
}
|
|
|
|
function setupGeolocationButton() {
|
|
const button = document.getElementById('locate-btn');
|
|
if (!button) return;
|
|
|
|
const defaultLabel = button.textContent;
|
|
|
|
button.addEventListener('click', () => {
|
|
button.disabled = true;
|
|
button.textContent = 'Standort wird ermittelt…';
|
|
|
|
requestUserLocation({
|
|
onSuccess: ({ lat, lng }) => {
|
|
centerOnCoords(lat, lng, 13);
|
|
button.disabled = false;
|
|
button.textContent = defaultLabel;
|
|
},
|
|
onError: () => {
|
|
button.disabled = false;
|
|
button.textContent = defaultLabel;
|
|
showFatalError(
|
|
'Standort konnte nicht ermittelt werden. Bitte Standortfreigabe im Browser prüfen.'
|
|
);
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
function setupManualLocationButton() {
|
|
const button = document.getElementById('manual-location-btn');
|
|
if (!button) return;
|
|
|
|
button.addEventListener('click', () => {
|
|
EventMap.ui.openManualLocationForm();
|
|
});
|
|
}
|
|
|
|
function setupAddPlaceButton() {
|
|
const button = document.getElementById('add-place-btn');
|
|
if (!button) return;
|
|
|
|
button.addEventListener('click', () => {
|
|
EventMap.ui.openPlaceForm();
|
|
});
|
|
}
|
|
|
|
function setupPromptGeneratorButton() {
|
|
const button = document.getElementById('open-prompt-generator-btn');
|
|
if (!button) return;
|
|
|
|
button.addEventListener('click', () => {
|
|
EventMap.ui.openPromptGenerator();
|
|
});
|
|
}
|
|
|
|
async function bootstrap() {
|
|
await initStore();
|
|
initMap('map');
|
|
initFilterPanel('filter-panel');
|
|
initList('place-list');
|
|
initDetail('detail-modal');
|
|
initForm('place-form-modal');
|
|
initManualLocationForm('manual-location-modal');
|
|
initPromptGenerator('prompt-generator-modal');
|
|
setupGeolocationButton();
|
|
setupManualLocationButton();
|
|
setupAddPlaceButton();
|
|
setupPromptGeneratorButton();
|
|
}
|
|
|
|
setupStatusClose();
|
|
|
|
bootstrap().catch((err) => {
|
|
console.error('EventMap: Initialisierung fehlgeschlagen.', err);
|
|
showFatalError('Die Anwendung konnte nicht geladen werden. Bitte Seite neu laden.');
|
|
});
|
|
})();
|