home · contact · privacy
Add string replacement button to structured edit view. master
authorChristian Heller <c.heller@plomlompom.de>
Fri, 14 Feb 2025 21:38:23 +0000 (22:38 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 14 Feb 2025 21:38:23 +0000 (22:38 +0100)
src/templates/edit_structured.tmpl

index ad7450ebbd074dba65384208562cf5de121273ef..298510c663d3a1273dc963d263f8dbd2feb56d41 100644 (file)
@@ -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>