From 398eab5cfb46c1b5dd544887b3b8c9bb39227dee Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Fri, 14 Feb 2025 22:38:23 +0100
Subject: [PATCH] Add string replacement button to structured edit view.

---
 src/templates/edit_structured.tmpl | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/templates/edit_structured.tmpl b/src/templates/edit_structured.tmpl
index ad7450e..298510c 100644
--- a/src/templates/edit_structured.tmpl
+++ b/src/templates/edit_structured.tmpl
@@ -157,6 +157,24 @@ function update_form() {
   });
 }
 
+function replace() {
+  const from = document.getElementById("replace_from").value;
+  const to = document.getElementById("replace_to").value;
+  dat_lines.forEach((dat_line) => {
+    dat_line.comment = dat_line.comment.replaceAll(from, to);
+    if ('code' in dat_line) {
+      dat_line.code = dat_line.code.replaceAll(from, to);
+    }
+    ['account', 'amount', 'currency'].forEach((key) => {
+      if (key in dat_line.booking_line) {
+        dat_line.booking_line[key] = dat_line.booking_line[key].replaceAll(from, to);
+      }
+    });
+  });
+  taint();
+  update_form();
+}
+
 window.onload = update_form;
 {% endblock %}
 
@@ -164,6 +182,12 @@ 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">
+from
+<input id="replace_from" />
+to
+<input id="replace_to" />
+<hr />
 <table id="dat_lines">
 </table>
 </form>
-- 
2.30.2