OfficeServer/create-brief-fixed.js
dgsoft 5371d5e479 Add WebDAV integration and template improvements
 Frontend-Verbesserungen:
- WebDAV-Integration für direktes Template-Bearbeiten
- 'In Word öffnen' Button für ms-word: URLs
- Verbesserte Template-Karten mit Tag-Informationen
- WebDAV-Info-Sektion mit Anleitungen
- Korrigierte API-Endpunkte für docxtemplater

🔧 Template-Updates:
- Alle Templates auf docxtemplater-Syntax aktualisiert
- create-*-fixed.js Scripts für korrekte {tag} Syntax
- Entfernt alte ++tag++ und ++INS++ Syntax
- Neue create-new-table-template.js für echte Loops

🌐 WebDAV-Features:
- Direkter Template-Download über /webdav/templates/
- Template-Bearbeitung in Word möglich
- Automatische Speicherung über WebDAV
- Fallback auf Download bei Word-Problemen

📊 Template-Syntax-Migration:
- {variable} statt ++variable++
- {#array}{field}{/array} statt ++INS array++
- Echte dynamische Tabellen ohne fixe Indizes
- Verbesserte Tag-Erkennung und Analyse
2025-10-01 22:27:29 +02:00

91 lines
3.0 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const AdmZip = require('adm-zip');
function createBriefTemplate() {
const zip = new AdmZip();
// [Content_Types].xml
const contentTypes = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
</Types>`;
// _rels/.rels
const rels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
</Relationships>`;
// word/document.xml - Brief Template
const document = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:pPr><w:jc w:val="right"/></w:pPr>
<w:r><w:t>{firma}</w:t></w:r>
</w:p>
<w:p>
<w:pPr><w:jc w:val="right"/></w:pPr>
<w:r><w:t>{strasse}</w:t></w:r>
</w:p>
<w:p>
<w:pPr><w:jc w:val="right"/></w:pPr>
<w:r><w:t>{plz} {stadt}</w:t></w:r>
</w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t>{empfaenger_name}</w:t></w:r></w:p>
<w:p><w:r><w:t>{empfaenger_strasse}</w:t></w:r></w:p>
<w:p><w:r><w:t>{empfaenger_plz} {empfaenger_stadt}</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p>
<w:pPr><w:jc w:val="right"/></w:pPr>
<w:r><w:t>{datum}</w:t></w:r>
</w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Betreff: {betreff}</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t>{anrede},</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t>{nachricht}</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t>Mit freundlichen Grüßen</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t>{absender_name}</w:t></w:r></w:p>
<w:p><w:r><w:t>{position}</w:t></w:r></w:p>
</w:body>
</w:document>`;
// Füge Dateien zum ZIP hinzu
zip.addFile('[Content_Types].xml', Buffer.from(contentTypes, 'utf8'));
zip.addFile('_rels/.rels', Buffer.from(rels, 'utf8'));
zip.addFile('word/document.xml', Buffer.from(document, 'utf8'));
// Speichere die Datei
const outputPath = path.join(__dirname, 'templates', 'brief-template.docx');
zip.writeZip(outputPath);
console.log('✅ Brief-Template mit docxtemplater-Syntax erstellt:', outputPath);
}
createBriefTemplate();