UAT/wa_section.js

107 lines
5.1 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.

/* ================= WEB ALIGNMENT TEAM (Mondays 9:00 AM MT) ================= */
const WA_KEY = "sm-webalign-items-v1";
let waItems = [];
try { waItems = JSON.parse(localStorage.getItem(WA_KEY) || "[]"); } catch { waItems = []; }
function waSave() { localStorage.setItem(WA_KEY, JSON.stringify(waItems)); }
function waNextMeeting() {
const now = new Date();
const m = new Date(now); m.setHours(9, 0, 0, 0);
let add = (1 - now.getDay() + 7) % 7; // days until Monday
if (add === 0 && now >= m) add = 7; // Monday but the 9 AM slot is gone → next week
m.setDate(m.getDate() + add);
return m;
}
function renderWa() {
const now = new Date();
const m = waNextMeeting();
const tStr = m.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
const dStr = m.toLocaleDateString(undefined, { weekday: "long", month: "long", day: "numeric" });
const sameDay = m.toDateString() === now.toDateString();
const dayOnly = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const days = Math.round((m - dayOnly) / 86400000);
const when = sameDay
? `TODAY at ${tStr} (in ${Math.max(1, Math.round((m - now) / 60000))} min)`
: `${dStr} at ${tStr} · in ${days} day${days === 1 ? "" : "s"}`;
const el = document.getElementById("waWhen");
if (el) {
el.innerHTML = `🗓 <b>Next sync: ${when}</b> <span class="wa-sub">· Mondays 9:00 AM MT</span>`;
el.classList.toggle("today", sameDay);
}
const wrap = document.getElementById("waList");
const open = waItems.filter(i => !i.done);
const covered = waItems.filter(i => i.done);
const row = i => {
const idx = waItems.indexOf(i);
const subs = i.subs || [];
const subDone = subs.filter(s => s.done).length;
const subsRows = subs.map((s, si) =>
`<label class="item wa-subrow">
<input type="checkbox" ${s.done ? "checked" : ""} onchange="waSubToggle(${idx}, ${si})">
<span class="txt">${esc(s.text)}</span>
<button class="del" onclick="waSubRemove(${idx}, ${si})" onmousedown="event.preventDefault()" title="Remove sub-item">✕</button>
</label>`).join("");
return `
<label class="item${i.done ? " checked" : ""}">
<input type="checkbox" ${i.done ? "checked" : ""} onchange="waToggle(${idx})">
<span class="txt">${esc(i.text)}</span>
${subs.length ? `<span class="wa-subcnt">${subDone}/${subs.length}</span>` : ""}
<span class="wa-added">added ${esc(i.added)}</span>
<button class="wa-addsub" onclick="waShowSubInput(${idx})" onmousedown="event.preventDefault()" title="Add a sub-item / talking point">+ sub</button>
<button class="del" onclick="waRemove(${idx})" onmousedown="event.preventDefault()" title="Remove">✕</button>
</label>
<div class="wa-subs" id="waSubs${idx}">${subsRows}</div>`;
};
let html = open.length
? open.map(row).join("")
: '<div class="empty">Nothing queued for Monday yet — add what you need to raise above 👇</div>';
if (covered.length) html += `<div class="subhead">✅ Covered <span class="count">${covered.length}</span></div>` + covered.map(row).join("");
wrap.innerHTML = html;
const b = document.getElementById("waBadge");
if (b) b.textContent = open.length ? String(open.length) : "—";
}
function addWaItem() {
const inp = document.getElementById("waInput");
const text = inp.value.trim();
if (!text) return;
waItems.push({ text, done: false, added: new Date().toLocaleDateString(undefined, { month: "short", day: "numeric" }) });
inp.value = "";
waSave(); renderWa(); inp.focus();
}
function waToggle(idx) { waItems[idx].done = !waItems[idx].done; waSave(); renderWa(); }
function waSubToggle(idx, si) { waItems[idx].subs[si].done = !waItems[idx].subs[si].done; waSave(); renderWa(); }
function waSubRemove(idx, si) { waItems[idx].subs.splice(si, 1); waSave(); renderWa(); }
function waShowSubInput(idx) {
const wrap = document.getElementById("waSubs" + idx);
if (!wrap || wrap.querySelector(".wa-subadd input")) return;
const d = document.createElement("div");
d.className = "wa-subadd";
const inp = document.createElement("input");
inp.type = "text";
inp.placeholder = "Sub-item / talking point… (Enter to add, Esc to cancel)";
d.appendChild(inp);
wrap.appendChild(d);
inp.focus();
let done = false;
inp.addEventListener("keydown", e => {
if (e.key === "Enter") {
const v = inp.value.trim();
done = true;
if (v) {
if (!waItems[idx].subs) waItems[idx].subs = [];
waItems[idx].subs.push({ text: v, done: false });
waSave(); renderWa(); waShowSubInput(idx); // stay open for the next one
}
} else if (e.key === "Escape") { done = true; d.remove(); }
});
inp.addEventListener("blur", () => { setTimeout(() => { if (!done && d.parentNode) d.remove(); }, 150); });
}
function waRemove(idx) { if (confirm("Remove this item?")) { waItems.splice(idx, 1); waSave(); renderWa(); } }
function waClearCovered() {
const n = waItems.filter(i => i.done).length;
if (!n) return;
if (!confirm(`Remove the ${n} covered item${n === 1 ? "" : "s"}?`)) return;
waItems = waItems.filter(i => !i.done);
waSave(); renderWa();
}
renderWa();