From: Christian Heller <c.heller@plomlompom.de>
Date: Sun, 23 Mar 2025 12:48:23 +0000 (+0100)
Subject: Minor refactoring.
X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/test?a=commitdiff_plain;h=4095a29c206f0ed0885287c5b323ca1b8ef907a9;p=ledgplom

Minor refactoring.
---

diff --git a/src/templates/edit_structured.tmpl b/src/templates/edit_structured.tmpl
index dad2e0a..919370f 100644
--- a/src/templates/edit_structured.tmpl
+++ b/src/templates/edit_structured.tmpl
@@ -17,6 +17,18 @@ var dat_lines = {{dat_lines|tojson|safe}};
 
 {{ macros.taint_js() }}
 
+function new_dat_line(account='', amount='None', currency='') {
+    return {
+        error: '',
+        comment: '',
+        booked: {
+            account: account,
+            amount: amount,
+            currency: currency,
+        }
+    };
+}
+
 function update_form() {
     // catch and empty table
     const table = document.getElementById("dat_lines");
@@ -135,8 +147,7 @@ function update_form() {
         // line deletion and addition buttons
         td_add_del = add_td(tr);
         add_button(td_add_del, 'add new',  false, function() {
-            new_line = {error: '', comment: '', booked: {account: '', amount: 'None', currency: ''}};
-            dat_lines.splice(i + 1, 0, new_line);
+            dat_lines.splice(i + 1, 0, new_dat_line());
         });
         if (i > 0) {
             add_button(td_add_del, 'delete',  i > 0 ? false : true, function() {
@@ -188,15 +199,7 @@ function mirror() {
                 inverted_amount = inverted_amount.slice(2);
             }
         }
-        dat_lines.push({
-            error: '',
-            comment: '',
-            booked: {
-                account: '?',
-                amount: inverted_amount,
-                currency: dat_line.booked.currency
-            }
-        });
+        dat_lines.push(new_dat_line('?', inverted_amount, dat_line.booked.currency));
     })
     taint();
     update_form();
@@ -236,8 +239,7 @@ function fill_sink() {
     }
     for (i = 0; i < Object.keys(sink_amounts_per_currency).length - sink_indices.length; i++) {
         sink_indices.push(dat_lines.length);
-        new_line = {error: '', comment: '', booked: {account: sink_account, amount: 'None', currency: ''}};
-        dat_lines.push(new_line);
+        dat_lines.push(new_dat_line(sink_account));
     }
     let sink_indices_index = 0;
     for (const [currency, amount] of Object.entries(sink_amounts_per_currency)) {