/* ---------------- campaigns ----------------
Clean UI rule like everywhere: the section opens on its
List tab only - one card per campaign with its progress
bar and Start/Pause. Creating a campaign lives in the
Create tab; saving returns to the List. While any campaign
is running the list refreshes itself every ~15 seconds. */
let CAMP_TAB = "list";
async function renderCampaigns(c) {
c.innerHTML = "";
c.appendChild(tabBar([
{id: "list", label: "List"},
{id: "create", label: "Create campaign"}
], CAMP_TAB, t => {
CAMP_TAB = t;
renderCampaigns(c);
}));
const holder = document.createElement("div");
c.appendChild(holder);
if (CAMP_TAB === "create") await paintCampCreate(holder);
else await paintCampList(holder);
}
function campPill(st) {
if (st === "running") return 'running';
if (st === "paused") return 'paused';
if (st === "done") return 'done';
return 'draft';
}
async function paintCampList(holder) {
const d = await api("/api/campaigns");
const camps = d.campaigns || [];
if (PAGE_TIMER) { clearInterval(PAGE_TIMER); PAGE_TIMER = null; }
if (camps.some(x => x.status === "running")) {
PAGE_TIMER = setInterval(() => {
if (VIEW === "campaigns" && CAMP_TAB === "list")
renderCampaigns($("#content"));
}, 15000);
}
if (!camps.length) {
holder.innerHTML =
'
Campaigns
' +
'
No campaigns yet. Use ' +
"the Create campaign tab to make the first one - it " +
"takes a snapshot of the send queue, one message and one " +
"sender (an account, or an SMTP group).
A campaign takes a snapshot of the send ' +
"queue, sends it one chosen message, through one sender. " +
"Nothing goes out until you press Start on the List " +
"tab.
Audience: ' +
"send queue now holds " + fmt(av.queue) + " contacts. " +
"This campaign will take a snapshot of " +
fmt(av.available) + " of them - anyone already waiting " +
"in another open campaign is left out.