diff --git a/app.js b/app.js index f4fdd35..af22ec1 100644 --- a/app.js +++ b/app.js @@ -1523,13 +1523,22 @@ function crmToggleSort(key) { /* ─── CRM — Checkbox helpers ────────────────────────────────────── */ function crmUpdateDeleteBtn() { const checked = document.querySelectorAll(".crm-select:checked").length; - const btn = document.getElementById("crm-delete-selected-btn"); - btn.disabled = checked === 0; - const label = checked > 0 ? `Delete Checked (${checked})` : "Delete Checked"; - btn.innerHTML = ` + const hasSel = checked > 0; + document.getElementById("crm-delete-selected-btn").disabled = !hasSel; + document.getElementById("crm-hold-btn").disabled = !hasSel; + document.getElementById("crm-cold-btn").disabled = !hasSel; + const label = hasSel ? `Delete Checked (${checked})` : "Delete Checked"; + document.getElementById("crm-delete-selected-btn").innerHTML = + ` ${label}`; + document.getElementById("crm-hold-btn").textContent = hasSel + ? `Set Hold (${checked})` + : "Set Hold"; + document.getElementById("crm-cold-btn").textContent = hasSel + ? `Set Cold (${checked})` + : "Set Cold"; } function crmToggleAll() { @@ -1606,6 +1615,65 @@ async function crmDeleteSelected() { await crmLoadRecords(); } +/* ─── CRM — Set stage for checked contacts ──────────────────────── */ +async function crmSetStageSelected(stage) { + const ids = Array.from(document.querySelectorAll(".crm-select:checked")).map( + (cb) => Number(cb.dataset.id), + ); + if (ids.length === 0) return; + + const ok = await confirmDialog( + `Set Stage to ${stage}`, + `Set stage to “${stage}” for ${ids.length} contact${ids.length !== 1 ? "s" : ""}?`, + ); + if (!ok) return; + + let failed = 0; + for (const id of ids) { + const r = crmRecords.find((c) => c.id === id); + if (!r) { + failed++; + continue; + } + const payload = { + id, + Name: r.Name ?? "", + Company: r.Company ?? "", + email: r.email ?? "", + Stage: stage, + strategy: r.strategy ?? "", + category: r.category ?? "", + affiliate: r.affiliate ?? "", + Number: r.Number ?? "", + date_next_contact: r.date_next_contact ?? null, + History: r.History ?? "", + }; + try { + const res = await apiFetch(apiUrl(ROUTES.crm), { + method: "PUT", + headers: apiHeaders(), + body: JSON.stringify(payload), + }); + if (!res.ok) failed++; + } catch { + failed++; + } + } + + if (failed === 0) { + toast( + `Stage set to “${stage}” for ${ids.length} contact${ids.length !== 1 ? "s" : ""}`, + "success", + ); + } else { + toast( + `Updated ${ids.length - failed} contact${ids.length - failed !== 1 ? "s" : ""} (${failed} failed)`, + "warning", + ); + } + await crmLoadRecords(); +} + /* ─── CRM — Edit modal ──────────────────────────────────────────── */ function crmOpenEdit(id) { const r = crmRecords.find((c) => c.id === id); diff --git a/index.html b/index.html index 8e3e159..913b0bd 100644 --- a/index.html +++ b/index.html @@ -722,10 +722,10 @@
- +
+
+ +
+
+ +
+