Add new categories/envelopes from the Budget page and the loader's categorize card
build-container / build (push) Successful in 35s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Sonnet 5.5 committed 2026-10-21 14:37:23 -04:00
1 parent 690316e541
commit 5068021b09
4 files changed
+33 -1

No files matched your search

+6
View File
@@ -36,6 +36,7 @@ input.amt{width:110px;text-align:right}
<div class="spacer"></div>
<button id="copy" title="Use last month's amounts">Copy last month</button>
<button id="suggest" title="Average of the last 3 months of spending">Suggest from spending</button>
<button id="addenv" title="Add a new category / envelope">Add envelope</button>
<button id="movebtn">Move money</button>
<button class="primary" id="save" disabled>Save budget</button>
</div>
@@ -105,6 +106,11 @@ $("#showall").onchange=render;
$("#copy").onclick=async()=>{const p=await (await fetch("/api/budget?month="+add(month,-1))).json();p.envelopes.forEach(e=>{const r=rows.find(x=>x.envelope==e.envelope);if(r)r.edit=e.budgeted});dirty=true;render()};
$("#suggest").onclick=()=>{rows.forEach(r=>{if(r.suggest)r.edit=r.suggest});dirty=true;render()};
$("#movebtn").onclick=()=>{const o=rows.map(r=>`<option>${esc(r.envelope)}</option>`).join("");$("#mfrom").innerHTML=o;$("#mto").innerHTML=o;$("#movepanel").style.display="block"};
$("#addenv").onclick=async()=>{
const name=(prompt("Name for the new envelope (category):")||"").trim();if(!name)return;
try{const r=await fetch("/api/add_category",{method:"POST",headers:{"X-Token":TOKEN},body:JSON.stringify({name})});const j=await r.json();if(!r.ok)throw new Error(j.error);
rows.push({envelope:j.name,budgeted:0,spent:0,prior:0,available:0,suggest:0,edit:0});$("#showall").checked=true;render();$("#msg").innerHTML=`<div class="alert">${esc(j.message)}</div>`}
catch(e){$("#msg").innerHTML=`<div class="alert bad">${esc(e.message)}</div>`}};
$("#mcancel").onclick=()=>$("#movepanel").style.display="none";
$("#mgo").onclick=()=>{const f=rows.find(r=>r.envelope==$("#mfrom").value),t=rows.find(r=>r.envelope==$("#mto").value),a=+$("#mamt").value;
if(!f||!t||f===t||!(a>0))return;f.edit=Math.max(0,(+f.edit||0)-a);t.edit=(+t.edit||0)+a;dirty=true;$("#movepanel").style.display="none";$("#mamt").value="";$("#showall").checked||(0);render()};