Skip to content

Commit 3379041

Browse files
committed
v1.22.2: combine contribution/payment/forgive into single tabbed panel with shared amount input
1 parent fb625eb commit 3379041

1 file changed

Lines changed: 58 additions & 47 deletions

File tree

index.html

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,13 +2188,24 @@ <h4>App Info</h4>
21882188
`).join("");
21892189
})() : `<div class="empty">No entries yet.</div>`;
21902190

2191-
const forgiveBlock = `<div class="panel" style="margin-top:12px;">
2192-
<h4>Forgive debt</h4>
2193-
<div class="inline">
2194-
<div class="field"><label>Amount</label><input id="forgiveAmt" placeholder="0" value="${bal>0?bal:''}"></div>
2195-
<div class="field"><label>Note</label><input id="forgiveNote" placeholder="optional"></div>
2191+
const actionPanel = `<div class="panel">
2192+
<div class="seg" id="actionModeSeg" style="margin-bottom:14px">
2193+
<button type="button" data-mode="charge" class="active">Contribution</button>
2194+
<button type="button" data-mode="payment">Payment</button>
2195+
<button type="button" data-mode="forgive">Forgive</button>
2196+
</div>
2197+
<div class="field"><label id="actAmtLabel">Amount (${CURRENCY})</label><input id="actAmt" inputmode="decimal" placeholder="0"></div>
2198+
<div class="inline" id="actNoteDateRow">
2199+
<div class="field"><label id="actNoteLabel">For</label><input id="actNote" value="${esc(monthLabel())}"></div>
2200+
<div class="field" id="actDateField"><label>Date</label><input id="actDate" type="date" value="${todayISO()}"></div>
2201+
</div>
2202+
<label id="actDeferRow" style="display:flex;align-items:center;gap:6px;font-size:13px;color:var(--muted);margin-top:10px">
2203+
<input id="actDeferred" type="checkbox"> <span>Mark as deferred</span>
2204+
</label>
2205+
<button class="btn block small" id="actSubmit" style="margin-top:10px">Add contribution</button>
2206+
<div id="markPaidWrap" class="hidden" style="margin-top:8px">
2207+
<button class="btn small ghost block" id="markPaid">Mark fully paid (${fmt(bal)})</button>
21962208
</div>
2197-
<button class="btn small" id="forgiveBtn" ${bal<=0?'disabled':''}>Forgive</button>
21982209
</div>`;
21992210

22002211
$("cDetail").outerHTML = `<div id="cDetail">
@@ -2204,33 +2215,7 @@ <h4>Forgive debt</h4>
22042215
<div class="meta">${esc(c.jobCard||id)}${c.phone?" · "+esc(c.phone):""}</div>
22052216
</div>
22062217
2207-
<div class="panel">
2208-
<h4>Add this month's contribution</h4>
2209-
<div class="field"><label>Amount (${CURRENCY})</label><input id="chAmt" inputmode="decimal" placeholder="0"></div>
2210-
<div class="inline">
2211-
<div class="field"><label>For</label><input id="chNote" value="${esc(monthLabel())}"></div>
2212-
<div class="field"><label>Date</label><input id="chDate" type="date" value="${todayISO()}"></div>
2213-
</div>
2214-
<label style="display:flex;align-items:center;gap:6px;font-size:13px;color:var(--muted);margin-top:10px">
2215-
<input id="chDeferred" type="checkbox"> <span>Mark as deferred</span>
2216-
</label>
2217-
<button class="btn block small" id="addCharge" style="margin-top:10px">Add contribution</button>
2218-
</div>
2219-
2220-
<div class="panel">
2221-
<h4>Record a payment</h4>
2222-
<div class="field"><label>Amount paid (${CURRENCY})</label><input id="pyAmt" inputmode="decimal" placeholder="0"></div>
2223-
<div class="inline">
2224-
<div class="field"><label>Note</label><input id="pyNote" placeholder="optional (e.g. cash)"></div>
2225-
<div class="field"><label>Date</label><input id="pyDate" type="date" value="${todayISO()}"></div>
2226-
</div>
2227-
<div class="inline-buttons" style="margin-top:10px;">
2228-
<button class="btn small ghost" id="addPayment" style="flex:1">Record this amount</button>
2229-
${bal>0 ? `<button class="btn small" id="markPaid" style="flex:1">Mark fully paid (${fmt(bal)})</button>` : ``}
2230-
</div>
2231-
</div>
2232-
2233-
${forgiveBlock}
2218+
${actionPanel}
22342219
22352220
<div class="clist" style="box-shadow:none">
22362221
<button id="historyToggle" style="width:100%;text-align:left;background:none;border:none;padding:14px 0 4px;font-size:12.5px;text-transform:uppercase;letter-spacing:1px;color:var(--muted);margin:0;cursor:pointer;display:flex;justify-content:space-between;align-items:center;font-weight:600">
@@ -2246,11 +2231,40 @@ <h4>Record a payment</h4>
22462231
</div>`;
22472232

22482233
// Attach event listeners
2249-
$("addCharge").addEventListener("click", ()=>addEntry(id,"charge"));
2250-
$("addPayment").addEventListener("click", ()=>addEntry(id,"payment"));
2234+
let actionMode = "charge";
2235+
function updateActionMode(){
2236+
const amtLabel=$("actAmtLabel"), noteLabel=$("actNoteLabel"), noteInput=$("actNote"),
2237+
amtInput=$("actAmt"), dateField=$("actDateField"), deferRow=$("actDeferRow"),
2238+
submitBtn=$("actSubmit"), markPaidWrap=$("markPaidWrap");
2239+
document.querySelectorAll("#actionModeSeg button").forEach(b=>b.classList.toggle("active", b.dataset.mode===actionMode));
2240+
if(actionMode==="charge"){
2241+
amtLabel.textContent=`Amount (${CURRENCY})`; noteLabel.textContent="For";
2242+
noteInput.value=monthLabel(); amtInput.value="";
2243+
dateField.classList.remove("hidden"); deferRow.classList.remove("hidden");
2244+
submitBtn.textContent="Add contribution"; markPaidWrap.classList.add("hidden");
2245+
} else if(actionMode==="payment"){
2246+
amtLabel.textContent=`Amount paid (${CURRENCY})`; noteLabel.textContent="Note";
2247+
noteInput.value=""; amtInput.value="";
2248+
dateField.classList.remove("hidden"); deferRow.classList.add("hidden");
2249+
submitBtn.textContent="Record payment"; markPaidWrap.classList.toggle("hidden", !(bal>0));
2250+
} else {
2251+
amtLabel.textContent="Amount"; noteLabel.textContent="Note";
2252+
noteInput.value=""; amtInput.value=bal>0?bal:"";
2253+
dateField.classList.add("hidden"); deferRow.classList.add("hidden");
2254+
submitBtn.textContent="Forgive debt"; markPaidWrap.classList.add("hidden");
2255+
}
2256+
submitBtn.disabled = actionMode==="forgive" && !(bal>0);
2257+
}
2258+
document.querySelectorAll("#actionModeSeg button").forEach(btn=>{
2259+
btn.addEventListener("click", ()=>{ actionMode=btn.dataset.mode; updateActionMode(); });
2260+
});
2261+
$("actSubmit").addEventListener("click", ()=>{
2262+
if(actionMode==="charge") addEntry(id,"charge");
2263+
else if(actionMode==="payment") addEntry(id,"payment");
2264+
else forgiveDebt(id);
2265+
});
22512266
if($("markPaid")) $("markPaid").addEventListener("click", ()=>markFullyPaid(id, bal));
22522267
$("delCitizen").addEventListener("click", ()=>deleteCitizen(id));
2253-
$("forgiveBtn").addEventListener("click", ()=>forgiveDebt(id));
22542268

22552269
// History toggle
22562270
$("historyToggle").addEventListener("click", ()=>{
@@ -2316,27 +2330,24 @@ <h4>Record a payment</h4>
23162330
}
23172331

23182332
async function addEntry(id, type){
2319-
const amtEl = type==="charge" ? $("chAmt") : $("pyAmt");
2320-
const noteEl = type==="charge" ? $("chNote") : $("pyNote");
2321-
const dateEl = type==="charge" ? $("chDate") : $("pyDate");
2322-
const amount = parseFloat(amtEl.value);
2333+
const amount = parseFloat($("actAmt").value);
23232334
if(!(amount>0)){ toast("Enter a valid amount"); return; }
2324-
const btn = type==="charge" ? $("addCharge") : $("addPayment");
2335+
const btn = $("actSubmit");
23252336
btn.disabled=true;
23262337
try{
2327-
const deferred = type==="charge" && $("chDeferred") && $("chDeferred").checked;
2328-
await store.addEntry(id, type, amount, noteEl.value.trim(), dateEl.value||todayISO(), deferred);
2338+
const note = $("actNote").value.trim();
2339+
const date = $("actDate").value || todayISO();
2340+
const deferred = type==="charge" && $("actDeferred").checked;
2341+
await store.addEntry(id, type, amount, note, date, deferred);
23292342
toast(type==="charge" ? (deferred ? "Deferred contribution added" : "Contribution added") : "Payment recorded");
23302343
await renderCitizenDetail(id);
23312344
}catch(err){ toast("Couldn't save. Try again."); console.error(err); btn.disabled=false; }
23322345
}
23332346

23342347
async function forgiveDebt(id){
2335-
const amtInput = $("forgiveAmt");
2336-
const noteInput = $("forgiveNote");
2337-
const amount = parseFloat(amtInput.value);
2348+
const amount = parseFloat($("actAmt").value);
23382349
if(!(amount>0)){ toast("Enter a valid amount"); return; }
2339-
const note = noteInput.value.trim() || "Forgiven";
2350+
const note = $("actNote").value.trim() || "Forgiven";
23402351
if(!(await confirmAction(`Forgive ${fmt(amount)} for this citizen?`))) return;
23412352
try{
23422353
await store.forgiveDebt(id, amount, note);

0 commit comments

Comments
 (0)