Files
projektuebersicht/public/js/init.js
T

73 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// -----------------------------
// Projektübersicht — Init / Start
// -----------------------------
// Einstiegsmodul der Hauptseite: wird als letztes Skript ausschließlich von
// Test.html geladen und startet direkt beim Laden den Initialisierungsablauf
// (automatische Ausführung unten in der Datei, nur wenn ein 'board'-Element
// existiert – auf project-plan.html fehlt es). Es stellt renderAll(),
// initUiState() und syncRangeDisplay() bereit und nutzt loadUiState()/
// loadTheme()/loadHeaderState() aus js/ui.js, switchDepartment() aus
// js/store.js, showTab() aus js/tabs-auth.js sowie die Render-Funktionen
// renderBoard()/renderLoad()/renderProjects()/renderPeople() aus js/board/board.js,
// js/load/load.js, js/projects/projects.js, js/people/people.js.
// renderAll: Convenience um UI-Elemente zu initialisieren
function renderAll(){
refreshWeekSelect();
updateWeekDate();
renderBoard();
const activeTab = document.querySelector('.tab.active')?.dataset.tab || currentTab;
if(activeTab === 'load') renderLoad();
else if(activeTab === 'projects') renderProjects();
else if(activeTab === 'people') renderPeople();
}
// initUiState: stellt beim Start den UI-Zustand her (LocalStorage-UI-State,
// Theme, Header-Status), setzt Titel und aktive Abteilungs-Schaltfläche und
// zeigt den ersten Tab an. Eine Deep-Link-URL (z. B. "/HLS/Auslastung") aus
// applyUrlRoute() übersteuert dabei Abteilung und Tab; passwortgeschützte Tabs
// öffnen das Passwort-Modal (showTab ohne skipAuth). Kein Rückgabewert.
function initUiState(){
loadUiState();
const route = applyUrlRoute();
if(route && DEPARTMENTS[route.department]){
currentDepartment = route.department;
currentTab = route.tab;
}
loadTheme();
loadHeaderState();
document.querySelectorAll('.dept-tab').forEach(btn => {
btn.classList.toggle('active', btn.dataset.dept === currentDepartment);
});
const info = DEPARTMENTS[currentDepartment];
document.title = 'Projektübersicht ' + info.label;
const titleEl = document.getElementById('pageTitle');
if(titleEl) titleEl.textContent = info.icon + ' Projektübersicht ' + info.label;
const tab = ['board','load','projects','people'].includes(currentTab) ? currentTab : DEFAULT_TAB;
// Geschützte Tabs ('projects'/'people') verlangen hier ihr Passwort.
showTab(tab);
}
// syncRangeDisplay: schreibt den aus zwei Datumsfeldern (startId/endId)
// berechneten Zeitraum als deutschen Text (z. B. "05.04.2026 – 11.04.2026")
// in das Anzeigefeld displayId. Parameter: die drei Element-IDs; kein Rückgabewert.
function syncRangeDisplay(displayId, startId, endId){
const disp = document.getElementById(displayId);
if(!disp) return;
const sEl = document.getElementById(startId);
const eEl = document.getElementById(endId);
const s = sEl ? parseDateISO(sEl.value) : null;
const e = eEl ? parseDateISO(eEl.value) : null;
const from = s ? formatDateDE(s) : '';
const to = e ? formatDateDE(e) : from;
disp.value = from ? (from + ' – ' + to) : '';
}
// Automatische Initialisierung nur auf der Hauptseite (Projektboard).
// Andere Seiten (z.B. Projektplan) laden diese Module nicht oder nur als
// Hilfsfunktionen und haben ihre eigene Seitenlogik (js/plan/*).
if(document.getElementById('board')){
initUiState();
switchDepartment(currentDepartment);
}