This commit is contained in:
oliver
2026-06-14 20:30:11 -03:00
parent 677cf54d60
commit 412e93ad83
2 changed files with 107 additions and 6 deletions
+72 -4
View File
@@ -1523,13 +1523,22 @@ function crmToggleSort(key) {
/* ─── CRM — Checkbox helpers ────────────────────────────────────── */ /* ─── CRM — Checkbox helpers ────────────────────────────────────── */
function crmUpdateDeleteBtn() { function crmUpdateDeleteBtn() {
const checked = document.querySelectorAll(".crm-select:checked").length; const checked = document.querySelectorAll(".crm-select:checked").length;
const btn = document.getElementById("crm-delete-selected-btn"); const hasSel = checked > 0;
btn.disabled = checked === 0; document.getElementById("crm-delete-selected-btn").disabled = !hasSel;
const label = checked > 0 ? `Delete Checked (${checked})` : "Delete Checked"; document.getElementById("crm-hold-btn").disabled = !hasSel;
btn.innerHTML = `<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="margin-right:4px;vertical-align:middle"> document.getElementById("crm-cold-btn").disabled = !hasSel;
const label = hasSel ? `Delete Checked (${checked})` : "Delete Checked";
document.getElementById("crm-delete-selected-btn").innerHTML =
`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="margin-right:4px;vertical-align:middle">
<polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/> <polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>
<path d="M10 11v6M14 11v6"/><path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/> <path d="M10 11v6M14 11v6"/><path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/>
</svg> ${label}`; </svg> ${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() { function crmToggleAll() {
@@ -1606,6 +1615,65 @@ async function crmDeleteSelected() {
await crmLoadRecords(); 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 ──────────────────────────────────────────── */ /* ─── CRM — Edit modal ──────────────────────────────────────────── */
function crmOpenEdit(id) { function crmOpenEdit(id) {
const r = crmRecords.find((c) => c.id === id); const r = crmRecords.find((c) => c.id === id);
+35 -2
View File
@@ -722,10 +722,10 @@
<!-- ─── CRM Section ─────────────────────────── --> <!-- ─── CRM Section ─────────────────────────── -->
<div class="section" id="section-crm"> <div class="section" id="section-crm">
<!-- Search bar --> <!-- Action bar -->
<div <div
class="card" class="card"
style="padding: 14px 20px; margin-bottom: 16px" style="padding: 10px 20px; margin-bottom: 16px"
> >
<div <div
class="form-row" class="form-row"
@@ -735,6 +735,38 @@
align-items: center; align-items: center;
" "
> >
<div class="form-group" style="flex: 0 0 auto">
<button
class="btn btn-sm"
id="crm-hold-btn"
onclick="crmSetStageSelected('Hold')"
disabled
style="
white-space: nowrap;
background: var(--accent-dim);
color: var(--accent);
border: 1px solid var(--border-hi);
"
>
Set Hold
</button>
</div>
<div class="form-group" style="flex: 0 0 auto">
<button
class="btn btn-sm"
id="crm-cold-btn"
onclick="crmSetStageSelected('Cold')"
disabled
style="
white-space: nowrap;
background: var(--accent-dim);
color: var(--accent);
border: 1px solid var(--border-hi);
"
>
Set Cold
</button>
</div>
<div class="form-group" style="flex: 0 0 auto"> <div class="form-group" style="flex: 0 0 auto">
<button <button
class="btn btn-danger btn-sm" class="btn btn-danger btn-sm"
@@ -765,6 +797,7 @@
Delete Checked Delete Checked
</button> </button>
</div> </div>
<span style="flex: 1; min-width: 0"></span>
<div <div
class="form-group" class="form-group"
style="flex: 1; min-width: 120px" style="flex: 1; min-width: 120px"