From 8ce0dfce1e181d33417850286f00bf02e94c9421 Mon Sep 17 00:00:00 2001 From: macniel Date: Sun, 3 May 2026 12:04:47 +0200 Subject: [PATCH] index.js aktualisiert --- index.js | 107 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 46 deletions(-) diff --git a/index.js b/index.js index cc0e35a..6ce6b11 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ var gui = require('gui'); var fs = require('fs'); -var ui = require('intuition'); var rh = 14; var sp = 4; @@ -21,7 +20,7 @@ function toListViewEntries(entries, visibleCols) { const subject = ("" + e.subject).substr(0, cols - 20).padEnd(cols - 20, ' '); const sum = ((amount >= 0 ? "+" : "") + amount.toFixed(2)).substr(0, 10).padStart(10, ' '); const d = new Date(e.date); - const date = d.getDay().toString().padStart(2, '0') + "-" + (d.getMonth() + 1).toString().padStart(2, '0') + "-" + d.getFullYear(); + const date = d.getDate().toString().padStart(2, '0') + "-" + (d.getMonth() + 1).toString().padStart(2, '0') + "-" + d.getFullYear(); let s = (date.substr(0, 10)) + " " + subject + " " + sum; return s; }); @@ -44,18 +43,24 @@ function toDateByComponents(s) { function closeAccount(data, selectedAccount) { let gadgets = []; - gadgets.push({ kind: 'text', id: 301, label: "Account:", left: sp+128, top: y, width: 200, height: rh, value: selectedAccount.name}); + const accountNameId = 301; + const remainingId = 302; + const transferCheckboxId = 303; + const targetAccountId = 304; + const executeButtonId = 305; + + gadgets.push({ kind: 'text', id: accountNameId, label: "Account:", left: sp+128, top: y, width: 200, height: rh, value: selectedAccount.name}); const openStanding = getSummation(selectedAccount.entries); - gadgets.push({ kind: 'text', id: 302, label: "Remaining " + (openStanding>0? "funds": "debt"), left: sp+128, top: y+rh+sp, width: 100, height: rh}) - gadgets.push({ kind: 'checkbox', id: 303, label: "Transfer to:", left: sp, top: y+rh+sp+rh+sp, height: rh, value: 0}); + gadgets.push({ kind: 'text', id: remainingId, label: "Remaining " + (openStanding>0? "funds": "debt"), left: sp+128, top: y+rh+sp, width: 100, height: rh}) + gadgets.push({ kind: 'checkbox', id: transferCheckboxId, label: "Transfer to:", left: sp, top: y+rh+sp+rh+sp, height: rh, value: 0}); let accounts = []; for (let i = 0; i < data.length; ++i) { if (data[i].name != selectedAccount.name) { accounts.push(data[i].name); } } - gadgets.push({ kind: 'cycle', id: 304, left: sp+128, top: y+rh+sp+rh+sp, width: 120, height: rh, items: accounts, value: 0 }); - gadgets.push({ kind: 'button', id: 305, left: sp+128, top: y+rh+sp+rh+sp+rh+sp, height: rh, width: 120, label: "Close Account"}) + gadgets.push({ kind: 'cycle', id: targetAccountId, left: sp+128, top: y+rh+sp+rh+sp, width: 120, height: rh, items: accounts, value: 0 }); + gadgets.push({ kind: 'button', id: executeButtonId, left: sp+128, top: y+rh+sp+rh+sp+rh+sp, height: rh, width: 120, label: "Close Account"}) let win = gui.createWindow({ title: "Close Account '" + selectedAccount.name + "'", @@ -66,8 +71,8 @@ function closeAccount(data, selectedAccount) { gadgets: gadgets }); - gui.setDisabled(win, 304, true); - gui.set(win, 302, openStanding.toFixed(2)); + gui.setDisabled(win, targetAccountId, true); + gui.set(win, remainingId, openStanding.toFixed(2)); while (true) { var evt = gui.waitEvent(win); @@ -78,13 +83,13 @@ function closeAccount(data, selectedAccount) { return null; } if (evt.type === 'gadgetup') { - if (evt.id === 303) { - gui.setDisabled(win, 304, !gui.get(win, 303)); + if (evt.id === transferCheckboxId) { + gui.setDisabled(win, targetAccountId, !gui.get(win, transferCheckboxId)); } - if (evt.id === 305) { - if (gui.get(win, 303)) { + if (evt.id === executeButtonId) { + if (gui.get(win, transferCheckboxId)) { let otherAccount; - let target = accounts[gui.get(win, 304)]; + let target = accounts[gui.get(win, targetAccountId)]; for (let i = 0; data.length;++i) { if (data[i].name === target) { otherAccount = data[i]; @@ -153,6 +158,14 @@ function subWindow(data) { let gadgets = []; let removable = false; + const subjectInputId = 401; + const amountInputId = 402; + const dateInputId = 403; + const transferCheckboxId = 404; + const transferAccountInputId = 405; + const executeButtonId = 406; + const deleteButtonId = 407; + const innerData = { date: Date.now(), subject: '', @@ -169,31 +182,31 @@ function subWindow(data) { } let d = new Date(innerData.date); - let formattedDate = (""+d.getDay()).padStart(2, "0") + "-" + (""+(d.getMonth() + 1)).padStart(2, "0") + "-" + d.getFullYear(); + let formattedDate = (""+d.getDate()).padStart(2, "0") + "-" + (""+(d.getMonth() + 1)).padStart(2, "0") + "-" + d.getFullYear(); gadgets.push({ - kind: 'string', id: 1, label: 'Subject:', + kind: 'string', id: subjectInputId, label: 'Subject:', left: sp + 80, top: y, width: 400 - sp - 80 - sp, height: rh, value: innerData.subject }); gadgets.push({ - kind: 'string', id: 2, label: 'Amount:', + kind: 'string', id: amountInputId, label: 'Amount:', left: sp + 80, top: sp + rh + sp, width: 100, height: rh, value: innerData.amount.toFixed(2) }); gadgets.push({ - kind: 'string', id: 3, label: 'Date:', + kind: 'string', id: dateInputId, label: 'Date:', left: sp + 80, top: sp + rh + sp + rh + sp, width: 150, height: rh, value: formattedDate }); - gadgets.push({ kind: 'checkbox', id: 6, label: "Account:", left: sp + 80, top: sp + rh + sp + rh + sp + rh + sp + 2, width: rh, height: rh, value: 0 }); + gadgets.push({ kind: 'checkbox', id: transferCheckboxId, label: "Account:", left: sp + 80, top: sp + rh + sp + rh + sp + rh + sp + 2, width: rh, height: rh, value: 0 }); const accounts = getAccounts(projectData); - gadgets.push({ kind: 'cycle', id: 7, left: sp + 160 + rh + sp, top: sp + rh + sp + rh + sp + rh + sp, width: 120, height: rh, items: accounts, value: 0 }); + gadgets.push({ kind: 'cycle', id: transferAccountInputId, left: sp + 160 + rh + sp, top: sp + rh + sp + rh + sp + rh + sp, width: 120, height: rh, items: accounts, value: 0 }); - gadgets.push({ kind: 'button', id: 4, left: sp + 80, top: sp + rh + sp + rh + sp + rh + sp + rh + sp, width: 80, label: "Save", height: rh }); - gadgets.push({ kind: 'button', id: 5, left: sp + 80 + sp + 80, top: sp + rh + sp + rh + sp + rh + sp + rh + sp, width: 80, label: "Remove", height: rh }); + gadgets.push({ kind: 'button', id: executeButtonId, left: sp + 80, top: sp + rh + sp + rh + sp + rh + sp + rh + sp, width: 80, label: "Save", height: rh }); + gadgets.push({ kind: 'button', id: deleteButtonId, left: sp + 80 + sp + 80, top: sp + rh + sp + rh + sp + rh + sp + rh + sp, width: 80, label: "Remove", height: rh }); let win = gui.createWindow({ title: 'Entry Details', @@ -205,7 +218,7 @@ function subWindow(data) { }); if (innerData.targetAccount) { - gui.set(win, 6, 1); + gui.set(win, transferCheckboxId, 1); let i = -1; for (i = 0; i < accounts.length; i++) { if (accounts[i] === innerData.targetAccount) { @@ -213,12 +226,12 @@ function subWindow(data) { } } gui.set(win, 7, i); - gui.setDisabled(win, 7, false); + gui.setDisabled(win, transferAccountInputId, false); } else { - gui.setDisabled(win, 7, true); + gui.setDisabled(win, transferAccountInputId, true); } - gui.setDisabled(win, 5, !removable); + gui.setDisabled(win, deleteButtonId, !removable); while (true) { var evt = gui.waitEvent(win); @@ -229,16 +242,16 @@ function subWindow(data) { return null; } if (evt.type === 'gadgetup') { - if (evt.id === 6) { - gui.setDisabled(win, 7, !gui.get(win, 6)); + if (evt.id === transferCheckboxId) { + gui.setDisabled(win, transferAccountInputId, !gui.get(win, transferAccountInputId)); } - if (evt.id === 4) { - innerData.subject = gui.get(win, 1); - innerData.amount = parseFloat(gui.get(win, 2)); - innerData.date = toDateByComponents(gui.get(win, 3)); + if (evt.id === executeButtonId) { + innerData.subject = gui.get(win, subjectInputId); + innerData.amount = parseFloat(gui.get(win, amountInputId)); + innerData.date = toDateByComponents(gui.get(win, dateInputId)); - if (gui.get(win, 6)) { - const targetAccountIndex = gui.get(win, 7); + if (gui.get(win, transferCheckboxId)) { + const targetAccountIndex = gui.get(win, transferAccountInputId); if (targetAccountIndex !== null && targetAccountIndex !== undefined) { innerData.targetAccount = data[targetAccountIndex].name; } @@ -247,7 +260,7 @@ function subWindow(data) { gui.closeWindow(win); return innerData; } - if (evt.id === 5) { + if (evt.id === deleteButtonId) { gui.closeWindow(win); return -1; } @@ -324,9 +337,9 @@ function mainWindow(projectData) { let currentAccountIndex = 0; - let updateView = (g, w, accountIndex, data) => { - g.set(w, 2, toListViewEntries(data[accountIndex].entries, cols)); - g.set(w, 3, getSummation(data[accountIndex].entries).toFixed(2)); + let updateView = (accountIndex, data) => { + gui.set(win, 2, toListViewEntries(data[accountIndex].entries, cols)); + gui.set(win, 3, getSummation(data[accountIndex].entries).toFixed(2)); } let doNew = () => { @@ -347,13 +360,14 @@ function mainWindow(projectData) { invalidate = false; } - let doSave = (g, data) => { - var r = g.fileRequest({ title: 'Save File', pattern: '#?.json', save: true }); + let doSave = () => { + var r = gui.fileRequest({ title: 'Save File', pattern: '#?.json', save: true }); if (r) { - fs.writeFileSync(r.file, JSON.stringify(data)); + fs.writeFileSync(r.file, JSON.stringify(internalProjectData)); } } + gui.setMenuItem(win, 105, {disabled: internalProjectData.length<=1}); while (!invalidate) { @@ -375,7 +389,7 @@ function mainWindow(projectData) { break; } else if (evt.id === 103) { - doSave(gui, internalProjectData); + doSave(); } else if (evt.id === 104) { addAccount(internalProjectData); @@ -389,8 +403,9 @@ function mainWindow(projectData) { invalidate = true; } } else { - ui.alert("Cannot close last remaining Account"); + gui.alert("Cannot close last remaining Account"); } + } else if (evt.id === 199) { invalidate = true; @@ -402,7 +417,7 @@ function mainWindow(projectData) { if (evt.id === cycleId) { currentAccountIndex = evt.code; - updateView(gui, win, currentAccountIndex, internalProjectData); + updateView(currentAccountIndex, internalProjectData); } else if (evt.id === listViewId) { const entry = subWindow(internalProjectData[currentAccountIndex].entries[evt.code]); if (entry != null) { @@ -421,7 +436,7 @@ function mainWindow(projectData) { }); } } - updateView(gui, win, currentAccountIndex, internalProjectData); + updateView(currentAccountIndex, internalProjectData); } } else if (evt.id === addButtonId) { const entry = subWindow(); @@ -438,7 +453,7 @@ function mainWindow(projectData) { }); } } - updateView(gui, win, currentAccountIndex, internalProjectData); + updateView(currentAccountIndex, internalProjectData); } } }