From b3ecd628e2ad3f3134f6df04c9601faa111c49bd Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 26 Feb 2025 17:25:58 +0100
Subject: [PATCH] In /edit_structured disable replace button if un-applied
 changes.

---
 src/templates/_macros.tmpl         | 26 +++++++++++++++-----------
 src/templates/edit_structured.tmpl |  6 +++---
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/src/templates/_macros.tmpl b/src/templates/_macros.tmpl
index a3187c9..35a4173 100644
--- a/src/templates/_macros.tmpl
+++ b/src/templates/_macros.tmpl
@@ -101,23 +101,27 @@ table.ledger tr > td:first-child { background-color: white; }
 function taint() {
   // activate buttons "apply", "revert"
   Array.from(document.getElementsByClassName("enable_on_change")).forEach((el) => {
-    el.disabled = false;
+      el.disabled = false;
   });
   // deactivate Booking links
-  Array.from(document.getElementsByClassName("disable_on_change")).forEach((span) => {
-    let links_text = '';
-    Array.from(span.childNodes).forEach((node) => {
-      links_text += node.textContent + ' ';
-    });
-    span.innerHTML = '';
-    const del = document.createElement("del");
-    span.appendChild(del);
-    del.textContent = links_text;
+  Array.from(document.getElementsByClassName("disable_on_change")).forEach((el) => {
+      if (el.tagName == 'span') {
+          let links_text = '';
+          Array.from(el.childNodes).forEach((node) => {
+            links_text += node.textContent + ' ';
+          });
+          el.innerHTML = '';
+          const del = document.createElement("del");
+          el.appendChild(del);
+          del.textContent = links_text;
+      } else if (el.type == "button") {
+          el.disabled = true;
+      }
   });
   // remove oninput handlers no longer needed (since we only ever go one way)
   ['input', 'textarea'].forEach((tag_name) => {
       Array.from(document.getElementsByTagName(tag_name)).forEach((el) => {
-        el.oninput = null;
+          el.oninput = null;
       });
   });
 }
diff --git a/src/templates/edit_structured.tmpl b/src/templates/edit_structured.tmpl
index 298510c..de2a226 100644
--- a/src/templates/edit_structured.tmpl
+++ b/src/templates/edit_structured.tmpl
@@ -147,8 +147,8 @@ function update_form() {
   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);
+    new_line = {error: '', comment: '', booking_line: {account: '', amount: '', currency: ''}};
+    dat_lines.push(new_line);
   });
 
   // make all rows alternate background color for better readability
@@ -182,7 +182,7 @@ window.onload = update_form;
 {% block content %}
 <form action="/edit_structured/{{id}}" method="POST">
 {{ macros.edit_bar("raw", id) }}
-<input type="button" onclick="replace()" value="replace string">
+<input type="button" onclick="replace()" value="replace string" class="disable_on_change">
 from
 <input id="replace_from" />
 to
-- 
2.30.2