/* ============================================================================= GOALS/OKR MODULE - Objectives & Key Results ============================================================================= */ (function () { "use strict"; // ============================================================================= // STATE // ============================================================================= const state = { currentView: "dashboard", objectives: [], selectedObjective: null, filters: { status: "all", owner: "all", period: "current", }, }; // ============================================================================= // INITIALIZATION // ============================================================================= function init() { loadObjectives(); bindEvents(); console.log("Goals module initialized"); } function bindEvents() { // View toggle buttons document.querySelectorAll(".view-btn").forEach((btn) => { btn.addEventListener("click", function () { const view = this.dataset.view; if (view) { switchGoalsView(view); } }); }); // Objective cards document.addEventListener("click", (e) => { const card = e.target.closest(".objective-card"); if (card) { const objectiveId = card.dataset.id; if (objectiveId) { selectObjective(objectiveId); } } }); } // ============================================================================= // VIEW SWITCHING // ============================================================================= function switchGoalsView(view) { state.currentView = view; // Update button states document.querySelectorAll(".view-btn").forEach((btn) => { btn.classList.toggle("active", btn.dataset.view === view); }); // Update view panels document.querySelectorAll(".goals-view").forEach((panel) => { panel.classList.toggle("active", panel.id === `${view}-view`); }); // Load view-specific data if using HTMX if (typeof htmx !== "undefined") { const viewContainer = document.getElementById("goals-content"); if (viewContainer) { htmx.ajax("GET", `/api/ui/goals/${view}`, { target: viewContainer }); } } } // ============================================================================= // DETAILS PANEL // ============================================================================= function toggleGoalsPanel() { const panel = document.getElementById("details-panel"); if (panel) { panel.classList.toggle("collapsed"); } } function openGoalsPanel() { const panel = document.getElementById("details-panel"); if (panel) { panel.classList.remove("collapsed"); } } function closeGoalsPanel() { const panel = document.getElementById("details-panel"); if (panel) { panel.classList.add("collapsed"); } } // ============================================================================= // OBJECTIVES // ============================================================================= async function loadObjectives() { try { const response = await fetch("/api/goals/objectives"); if (response.ok) { const data = await response.json(); state.objectives = data.objectives || []; renderObjectives(); } } catch (e) { console.error("Failed to load objectives:", e); } } function renderObjectives() { const container = document.getElementById("objectives-list"); if (!container) return; if (state.objectives.length === 0) { container.innerHTML = `
Create your first objective to start tracking goals
${escapeHtml(objective.description || "No description")}
${escapeHtml(objective.owner_name || "Unassigned")}
${formatDate(objective.start_date)} - ${formatDate(objective.end_date)}