hold
This commit is contained in:
@@ -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 = `<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">
|
||||
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 =
|
||||
`<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"/>
|
||||
<path d="M10 11v6M14 11v6"/><path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/>
|
||||
</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() {
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user