From 1c9018c729e6ec8a4a74b5476dca5910e33eba46 Mon Sep 17 00:00:00 2001 From: Sven Carstensen Date: Sun, 31 Aug 2025 09:45:37 +0200 Subject: [PATCH] Erweiterungen --- .../votianlt/pages/view/PDFBuilderView.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/assecutor/votianlt/pages/view/PDFBuilderView.java b/src/main/java/de/assecutor/votianlt/pages/view/PDFBuilderView.java index 1b1cd36..7c99cb1 100644 --- a/src/main/java/de/assecutor/votianlt/pages/view/PDFBuilderView.java +++ b/src/main/java/de/assecutor/votianlt/pages/view/PDFBuilderView.java @@ -39,6 +39,7 @@ import java.util.Objects; import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.component.textfield.NumberField; import com.vaadin.flow.component.KeyPressEvent; +import com.vaadin.flow.component.checkbox.Checkbox; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; @@ -64,6 +65,8 @@ public class PDFBuilderView extends Div { private final Set collapsedItems = new HashSet<>(); // Temporarily store element name from dialog private String currentElementName; + // Temporarily store content inclusion preference from dialog + private boolean currentIncludeContent; public PDFBuilderView(PDFGenerationService pdfService, PdfTemplateService templateService) { this.pdfService = pdfService; @@ -149,13 +152,14 @@ public class PDFBuilderView extends Div { " const height = Math.round(parseFloat(csf.height) || f.getBoundingClientRect().height);\n" + " const z = (function(){ const zc = parseInt(csf.zIndex); return isNaN(zc)? idx : zc; })();\n" + " const name = f.getAttribute('data-name') || '';\n" + + " const includeContent = f.getAttribute('data-include-content') !== 'false';\n" + " const img = f.querySelector('img');\n" + " if(img){\n" + - " return {type:'image', name, x, y, width, height, z, dataUrl: img.src};\n" + + " return {type:'image', name, x, y, width, height, z, dataUrl: includeContent ? img.src : ''};\n" + " } else {\n" + " const editor = f.querySelector('.text-editor');\n" + " const cs = editor ? getComputedStyle(editor) : null;\n" + - " return {type:'text', name, x, y, width, height, z, html: editor?editor.innerHTML:'', editorStyle: cs?{fontSize: cs.fontSize, color: cs.color, lineHeight: cs.lineHeight}:{}};\n" + + " return {type:'text', name, x, y, width, height, z, html: includeContent ? (editor?editor.innerHTML:'') : '', editorStyle: includeContent ? (cs?{fontSize: cs.fontSize, color: cs.color, lineHeight: cs.lineHeight}:{}) : {}};\n" + " }\n" + " });\n" + " return JSON.stringify({canvas:{width: Math.round(rect.width), height: Math.round(rect.height)}, items});\n" + @@ -213,10 +217,18 @@ public class PDFBuilderView extends Div { nameField.setPlaceholder(elementType + " eingeben..."); nameField.focus(); + Checkbox includeContentCheckbox = new Checkbox("Inhalt in Template übernehmen"); + includeContentCheckbox.setValue(true); // Default: content included + includeContentCheckbox.getStyle().set("margin-top", "var(--lumo-space-s)"); + VerticalLayout content = new VerticalLayout(); content.setPadding(false); content.setSpacing(true); - content.add(new Span("Bitte geben Sie einen Namen für das " + elementType + "-Element ein:"), nameField); + content.add( + new Span("Bitte geben Sie einen Namen für das " + elementType + "-Element ein:"), + nameField, + includeContentCheckbox + ); dlg.add(content); Button cancel = new Button("Abbrechen", e -> dlg.close()); @@ -227,8 +239,9 @@ public class PDFBuilderView extends Div { nameField.focus(); return; } - // Store the name temporarily for use in element creation + // Store the name and content inclusion preference temporarily for use in element creation currentElementName = name.trim(); + currentIncludeContent = includeContentCheckbox.getValue(); dlg.close(); onNameProvided.run(); }); @@ -619,6 +632,7 @@ public class PDFBuilderView extends Div { frame.getElement().setAttribute("data-frame-id", id); frame.getElement().setAttribute("data-type", "text"); frame.getElement().setAttribute("data-name", currentElementName != null ? currentElementName : "Text"); + frame.getElement().setAttribute("data-include-content", String.valueOf(currentIncludeContent)); frame.getStyle().set("left", x + "px"); frame.getStyle().set("top", y + "px"); frame.getStyle().set("width", "300px"); @@ -721,6 +735,7 @@ public class PDFBuilderView extends Div { frame.getElement().setAttribute("data-frame-id", id); frame.getElement().setAttribute("data-type", "image"); frame.getElement().setAttribute("data-name", currentElementName != null ? currentElementName : "Bild"); + frame.getElement().setAttribute("data-include-content", String.valueOf(currentIncludeContent)); frame.getStyle().set("left", x + "px"); frame.getStyle().set("top", y + "px"); frame.getStyle().set("width", "260px");