+
diff --git a/open_workshop_employee_imagegenerator/static/src/css/badge_template.css b/open_workshop_employee_imagegenerator/static/src/css/badge_template.css index 86f11d8..f9456a5 100644 --- a/open_workshop_employee_imagegenerator/static/src/css/badge_template.css +++ b/open_workshop_employee_imagegenerator/static/src/css/badge_template.css @@ -70,6 +70,7 @@ margin: 0 auto; padding: 5mm 0 0 0; object-fit: cover; + object-position: center; } .badge-template .your-name { @@ -87,8 +88,9 @@ } .badge-template .warnung { - font-size: 10mm; + font-size: 9mm; color: red; flex: 1; + text-align: center; font-weight: bold; } diff --git a/open_workshop_employee_imagegenerator/static/src/js/employee_image_widget.js b/open_workshop_employee_imagegenerator/static/src/js/employee_image_widget.js index ed863ec..d0fd838 100644 --- a/open_workshop_employee_imagegenerator/static/src/js/employee_image_widget.js +++ b/open_workshop_employee_imagegenerator/static/src/js/employee_image_widget.js @@ -41,11 +41,14 @@ class EmployeeImageGenerator extends Component { this.badgeTemplate = useRef("badgeTemplate"); this.cropper = null; - // A4-Format wie Original: 794×1123px (wie thekenheld) - this.targetWidth = 794; - this.targetHeight = 1123; - // Umrechnungsfaktor: 793px / 210mm = 3.776 px/mm - this.pxPerMm = this.targetWidth / 210; + // Zielgröße für das zugeschnittene Foto + this.cropWidth = 369; + this.cropHeight = 492; + // Zielgröße für das finale Badge (A4-Format) + this.badgeWidth = 794; + this.badgeHeight = 1123; + // Umrechnungsfaktor für mm (falls benötigt) + this.pxPerMm = this.badgeWidth / 210; // Lade Company-Logo beim Start this.loadCompanyLogo(); @@ -107,20 +110,29 @@ class EmployeeImageGenerator extends Component { return; } - const aspectRatio = this.targetWidth / this.targetHeight; + const aspectRatio = this.cropWidth / this.cropHeight; this.cropper = new window.Cropper(imageElement, { aspectRatio: aspectRatio, - viewMode: 3, - dragMode: 'move', - autoCropArea: 1, + viewMode: 1, // Erlaubt unbegrenztes Zoomen + dragMode: 'move', // Bild verschieben + autoCropArea: 0.7, // Crop-Rahmen ist 70% des Containers - besser sichtbar restore: false, guides: true, center: true, highlight: false, - cropBoxMovable: true, - cropBoxResizable: true, + cropBoxMovable: false, // Crop-Rahmen NICHT verschiebbar + cropBoxResizable: false, // Crop-Rahmen NICHT in Größe veränderbar toggleDragModeOnDblclick: false, + zoomable: true, + zoomOnWheel: true, // Zoom mit Mausrad + zoomOnTouch: true, // Zoom mit Touch-Gesten + minContainerWidth: 200, + minContainerHeight: 200, + ready: function() { + // Setze initiales Zoom-Level auf "fit in container" + this.cropper.zoomTo(0); + }, }); } @@ -131,8 +143,8 @@ class EmployeeImageGenerator extends Component { } const canvas = this.cropper.getCroppedCanvas({ - width: this.targetWidth, - height: this.targetHeight, + width: this.cropWidth, + height: this.cropHeight, }); if (canvas) { @@ -163,16 +175,30 @@ class EmployeeImageGenerator extends Component { return; } - // Konvertiere HTML-Element zu Canvas mit html2canvas (exakt wie thekenheld) + // Entferne temporär die Skalierung vom Wrapper (nicht vom Badge selbst) + const wrapper = badgeElement.parentElement; + const originalTransform = wrapper ? wrapper.style.transform : ''; + if (wrapper) { + wrapper.style.transform = 'none'; + } + + // Konvertiere HTML-Element zu Canvas mit html2canvas in voller A4-Größe const canvas = await window.html2canvas(badgeElement, { - width: this.targetWidth, - height: this.targetHeight, + width: this.badgeWidth, + height: this.badgeHeight, + scale: 1, // Wichtig: keine zusätzliche Skalierung + backgroundColor: '#ffffff', }); - // Konvertiere Canvas zu Base64 PNG (wie Original thekenheld) + // Stelle die Skalierung für die Vorschau wieder her + if (wrapper) { + wrapper.style.transform = originalTransform; + } + + // Konvertiere Canvas zu Base64 PNG const finalImageBase64 = canvas.toDataURL('image/png'); - // Speichere in Odoo (entferne data:image/jpeg;base64, prefix) + // Speichere in Odoo (entferne data:image/png;base64, prefix) const imageData = finalImageBase64.split(',')[1]; await this.orm.write('hr.employee', [this.state.employeeId], { diff --git a/open_workshop_employee_imagegenerator/static/src/xml/employee_image_widget.xml b/open_workshop_employee_imagegenerator/static/src/xml/employee_image_widget.xml index dbc35f8..a2fd5e7 100644 --- a/open_workshop_employee_imagegenerator/static/src/xml/employee_image_widget.xml +++ b/open_workshop_employee_imagegenerator/static/src/xml/employee_image_widget.xml @@ -54,10 +54,10 @@ Bewege und zoome das Bild, um den gewünschten Ausschnitt zu wählen -
@@ -103,32 +103,37 @@