Der Backup-Export/Import (Phase 7) war bislang nur ueber den zweiten Tab
im "KI-Ausflugsziele importieren"-Fenster erreichbar - der Toolbar-Button
nannte an keiner Stelle "Export" oder "Backup", weshalb die Funktion
praktisch nicht auffindbar war.
Neuer eigener Toolbar-Button "Daten sichern/wiederherstellen" oeffnet
das bestehende Import-Fenster jetzt direkt auf dem Backup-Tab
(openImport('backup')). Der bisherige Button bleibt fuer den
KI-JSON-Import zustaendig (openImport('ai')), keine Funktionsaenderung
an der eigentlichen Export-/Import-Logik.
192 lines
5.3 KiB
JavaScript
192 lines
5.3 KiB
JavaScript
// Einstiegspunkt der Anwendung: initialisiert Store, Karte und Liste.
|
|
|
|
(function () {
|
|
const { initStore } = EventMap.store;
|
|
const {
|
|
initMap,
|
|
centerOnCoords,
|
|
requestUserLocation,
|
|
startLocationPicking,
|
|
stopLocationPicking,
|
|
isPickingLocation,
|
|
} = EventMap.map;
|
|
const {
|
|
initList,
|
|
initDetail,
|
|
initForm,
|
|
initManualLocationForm,
|
|
initFilterPanel,
|
|
initPromptGenerator,
|
|
initImport,
|
|
} = 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 setupPickLocationButton() {
|
|
const button = document.getElementById('pick-location-btn');
|
|
const hint = document.getElementById('map-picking-hint');
|
|
const cancelBtn = document.getElementById('map-picking-cancel-btn');
|
|
if (!button || !hint || !cancelBtn) return;
|
|
|
|
const defaultLabel = button.textContent;
|
|
|
|
function endPicking() {
|
|
button.textContent = defaultLabel;
|
|
button.classList.remove('btn--active');
|
|
hint.hidden = true;
|
|
}
|
|
|
|
function beginPicking() {
|
|
button.textContent = 'Klicke auf die Karte …';
|
|
button.classList.add('btn--active');
|
|
hint.hidden = false;
|
|
|
|
startLocationPicking({
|
|
onPick: ({ lat, lng }) => {
|
|
EventMap.store.setState({ userLocation: { lat, lng } });
|
|
EventMap.store.updateSettings({ userConsentGeo: true });
|
|
endPicking();
|
|
},
|
|
onCancel: endPicking,
|
|
});
|
|
}
|
|
|
|
button.addEventListener('click', () => {
|
|
if (isPickingLocation()) {
|
|
stopLocationPicking();
|
|
endPicking();
|
|
} else {
|
|
beginPicking();
|
|
}
|
|
});
|
|
|
|
cancelBtn.addEventListener('click', () => {
|
|
stopLocationPicking();
|
|
endPicking();
|
|
});
|
|
}
|
|
|
|
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();
|
|
});
|
|
}
|
|
|
|
function setupImportButton() {
|
|
const button = document.getElementById('open-import-btn');
|
|
if (!button) return;
|
|
|
|
button.addEventListener('click', () => {
|
|
EventMap.ui.openImport('ai');
|
|
});
|
|
}
|
|
|
|
function setupBackupButton() {
|
|
const button = document.getElementById('open-backup-btn');
|
|
if (!button) return;
|
|
|
|
button.addEventListener('click', () => {
|
|
EventMap.ui.openImport('backup');
|
|
});
|
|
}
|
|
|
|
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');
|
|
initImport('import-modal');
|
|
setupGeolocationButton();
|
|
setupManualLocationButton();
|
|
setupPickLocationButton();
|
|
setupAddPlaceButton();
|
|
setupPromptGeneratorButton();
|
|
setupImportButton();
|
|
setupBackupButton();
|
|
}
|
|
|
|
setupStatusClose();
|
|
|
|
bootstrap().catch((err) => {
|
|
console.error('EventMap: Initialisierung fehlgeschlagen.', err);
|
|
showFatalError('Die Anwendung konnte nicht geladen werden. Bitte Seite neu laden.');
|
|
});
|
|
})();
|