Erweiterungen

This commit is contained in:
2026-02-13 12:11:49 +01:00
parent 09bd168c74
commit 2af9c9a99a
4 changed files with 205 additions and 90 deletions

View File

@@ -76,7 +76,8 @@ window.initProfileInvoiceGenerator = function() {
el.fontSize || 14,
el.color || '#333333',
el.width || 100,
el.height || 30
el.height || 30,
el.isStatic || false
);
}
}
@@ -140,36 +141,51 @@ window.initProfileInvoiceGenerator = function() {
function drawElement(el) {
ctx.save();
var x = pageX + el.x;
var y = pageY + el.y;
var w = el.width || 100;
var h = el.height || 30;
if (el.type === 'line') {
ctx.strokeStyle = el.color || '#333333';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(pageX + el.x, pageY + el.y);
ctx.lineTo(pageX + el.x + el.width, pageY + el.y);
ctx.moveTo(x, y);
ctx.lineTo(x + w, y);
ctx.stroke();
} else if (el.type === 'image') {
ctx.fillStyle = '#f0f0f0';
ctx.fillRect(pageX + el.x, pageY + el.y, el.width, el.height);
ctx.fillRect(x, y, w, h);
ctx.strokeStyle = '#999999';
ctx.strokeRect(pageX + el.x, pageY + el.y, el.width, el.height);
ctx.strokeRect(x, y, w, h);
ctx.fillStyle = '#666666';
ctx.font = '12px Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText('Bild', pageX + el.x + el.width / 2, pageY + el.y + el.height / 2);
ctx.fillText('Bild', x + w / 2, y + h / 2);
} else {
// Text elements
ctx.font = (el.fontStyle || '') + ' ' + (el.fontSize || 14) + 'px Arial';
ctx.fillStyle = el.color || '#333333';
ctx.textBaseline = 'top';
// Draw background highlight for static elements
if (el.isStatic) {
var textWidth = ctx.measureText(el.text || '').width + 10;
ctx.fillStyle = 'rgba(25, 118, 210, 0.1)'; // Light blue background
ctx.fillRect(x - 3, y - 2, Math.max(w, textWidth), h);
}
ctx.fillStyle = el.color || '#333333';
ctx.font = (el.fontStyle || '') + ' ' + (el.fontSize || 14) + 'px Arial';
var lines = (el.text || '').split('\n');
var lineHeight = (el.fontSize || 14) * 1.2;
var y = pageY + el.y;
var ty = y;
lines.forEach(function(line) {
ctx.fillText(line, pageX + el.x, y);
y += lineHeight;
ctx.fillText(line, x, ty);
ty += lineHeight;
});
}
@@ -342,7 +358,7 @@ window.initProfileInvoiceGenerator = function() {
});
// Add element function
window.addProfileElement = function(type, label, dropX, dropY) {
window.addProfileElement = function(type, label, dropX, dropY, isStatic, staticText) {
elementCounter++;
var id = 'element-' + elementCounter;
@@ -362,57 +378,66 @@ window.initProfileInvoiceGenerator = function() {
width: 150,
height: 30,
fontSize: 14,
color: '#333333'
color: '#333333',
isStatic: isStatic || false
};
switch (type) {
case 'text':
el.text = 'Text eingeben...';
el.height = 20;
break;
case 'header':
el.text = 'Überschrift';
el.fontSize = 24;
el.fontStyle = 'bold';
el.color = '#000000';
el.width = 200;
el.height = 30;
break;
case 'date':
el.text = 'Datum: ' + new Date().toLocaleDateString('de-DE');
el.fontSize = 12;
el.color = '#666666';
el.height = 16;
break;
case 'customer':
el.text = 'Kundenname\nStraße Nr.\nPLZ Ort';
el.height = 50;
el.fontSize = 12;
break;
case 'company':
el.text = 'Ihr Unternehmen\nIhre Straße\nIhre PLZ Ort';
el.height = 50;
el.fontSize = 12;
break;
case 'amount':
el.text = 'Gesamtbetrag: 0,00 €';
el.fontStyle = 'bold';
el.width = 180;
el.height = 20;
break;
case 'line':
el.text = '';
el.width = 200;
el.height = 2;
break;
case 'image':
el.text = 'Bild';
el.width = 100;
el.height = 100;
break;
default:
el.text = label || 'Neues Element';
el.height = 20;
// Handle static elements (user data)
if (isStatic && staticText) {
el.text = staticText;
el.color = '#1976d2'; // Blue color for static elements
el.fontStyle = 'bold';
el.height = 20;
} else {
switch (type) {
case 'text':
el.text = 'Text eingeben...';
el.height = 20;
break;
case 'header':
el.text = 'Überschrift';
el.fontSize = 24;
el.fontStyle = 'bold';
el.color = '#000000';
el.width = 200;
el.height = 30;
break;
case 'date':
el.text = 'Datum: ' + new Date().toLocaleDateString('de-DE');
el.fontSize = 12;
el.color = '#666666';
el.height = 16;
break;
case 'customer':
el.text = 'Kundenname\nStraße Nr.\nPLZ Ort';
el.height = 50;
el.fontSize = 12;
break;
case 'company':
el.text = 'Ihr Unternehmen\nIhre Straße\nIhre PLZ Ort';
el.height = 50;
el.fontSize = 12;
break;
case 'amount':
el.text = 'Gesamtbetrag: 0,00 €';
el.fontStyle = 'bold';
el.width = 180;
el.height = 20;
break;
case 'line':
el.text = '';
el.width = 200;
el.height = 2;
break;
case 'image':
el.text = 'Bild';
el.width = 100;
el.height = 100;
break;
default:
el.text = label || 'Neues Element';
el.height = 20;
}
}
elements.push(el);
@@ -538,12 +563,14 @@ window.initProfileInvoiceGenerator = function() {
var templateType = e.dataTransfer.getData('template-type');
var templateLabel = e.dataTransfer.getData('template-label');
var isStatic = e.dataTransfer.getData('is-static') === 'true';
var staticText = e.dataTransfer.getData('static-text');
if (templateType && window.addProfileElement) {
var rect = container.getBoundingClientRect();
var x = e.clientX - rect.left;
var y = e.clientY - rect.top;
window.addProfileElement(templateType, templateLabel, x, y);
window.addProfileElement(templateType, templateLabel, x, y, isStatic, staticText);
}
});
}