home · contact · privacy
Minor refactoring.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 23 Mar 2025 12:48:23 +0000 (13:48 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 23 Mar 2025 12:48:23 +0000 (13:48 +0100)
src/templates/edit_structured.tmpl

index dad2e0ad9429bb9c2775c6c8fc07e2839832e74d..919370faf40866978332247aaca2c789e163b479 100644 (file)
@@ -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)) {