home · contact · privacy
In /edit_structured, add "add line" buttons for all lines.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 3 Mar 2025 01:26:52 +0000 (02:26 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 3 Mar 2025 01:26:52 +0000 (02:26 +0100)
src/templates/edit_structured.tmpl

index 70df62408106dfd72f9215b02f704f33ea02d7d9..959574c381823803705038d5cf165f79b4d32620 100644 (file)
@@ -132,10 +132,16 @@ function update_form() {
     }
     add_td_input('comment', dat_line.comment, 40);
 
-    // delete button
-    td_del = add_td(tr);
+    // line deletion and addition buttons
+    td_add_del = add_td(tr);
+    add_button(td_add_del, 'add new',  false, function() {
+        new_line = {error: '', comment: '', booking_line: {account: '', amount: '', currency: ''}};
+        dat_lines.splice(i + 1, 0, new_line);
+    });
     if (i > 0) {
-        add_button(td_del, 'delete',  i > 0 ? false : true, function() { dat_lines.splice(i, 1); });
+        add_button(td_add_del, 'delete',  i > 0 ? false : true, function() {
+            dat_lines.splice(i, 1);
+        });
     }
 
     // add error explanation row if necessary
@@ -149,15 +155,6 @@ function update_form() {
     }
   }
 
-  // add "add line" row
-  const tr = document.createElement("tr");
-  table.appendChild(tr);
-  const td = add_td(tr, 5);
-  add_button(td, 'add line', false, function() {
-    new_line = {error: '', comment: '', booking_line: {account: '', amount: '', currency: ''}};
-    dat_lines.push(new_line);
-  });
-
   // make all rows alternate background color for better readability
   Array.from(table.rows).forEach((tr) => {
       tr.classList.add('alternating');