Spaces:
Running
Running
Add 2 files
Browse files- README.md +6 -4
- index.html +782 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: test
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: gray
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,782 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="fr">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Générateur de document de synthèse ANAH</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf-lib/1.17.1/pdf-lib.min.js"></script>
|
| 9 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
.dropzone {
|
| 12 |
+
border: 2px dashed #cbd5e0;
|
| 13 |
+
transition: all 0.3s ease;
|
| 14 |
+
}
|
| 15 |
+
.dropzone.active {
|
| 16 |
+
border-color: #4299e1;
|
| 17 |
+
background-color: #ebf8ff;
|
| 18 |
+
}
|
| 19 |
+
.pdf-preview {
|
| 20 |
+
height: 500px;
|
| 21 |
+
border: 1px solid #e2e8f0;
|
| 22 |
+
overflow: hidden;
|
| 23 |
+
}
|
| 24 |
+
.loading-spinner {
|
| 25 |
+
display: none;
|
| 26 |
+
}
|
| 27 |
+
.loading-spinner.active {
|
| 28 |
+
display: inline-block;
|
| 29 |
+
}
|
| 30 |
+
.progress-bar {
|
| 31 |
+
height: 6px;
|
| 32 |
+
background-color: #e2e8f0;
|
| 33 |
+
border-radius: 3px;
|
| 34 |
+
overflow: hidden;
|
| 35 |
+
}
|
| 36 |
+
.progress-bar-fill {
|
| 37 |
+
height: 100%;
|
| 38 |
+
background-color: #4299e1;
|
| 39 |
+
transition: width 0.3s ease;
|
| 40 |
+
}
|
| 41 |
+
.field-tag {
|
| 42 |
+
display: inline-flex;
|
| 43 |
+
align-items: center;
|
| 44 |
+
background-color: #EFF6FF;
|
| 45 |
+
border-radius: 9999px;
|
| 46 |
+
padding: 0.25rem 0.75rem;
|
| 47 |
+
font-size: 0.875rem;
|
| 48 |
+
color: #1E40AF;
|
| 49 |
+
}
|
| 50 |
+
.match-success {
|
| 51 |
+
background-color: #ECFDF5;
|
| 52 |
+
border-left: 4px solid #10B981;
|
| 53 |
+
}
|
| 54 |
+
.match-warning {
|
| 55 |
+
background-color: #FFFBEB;
|
| 56 |
+
border-left: 4px solid #F59E0B;
|
| 57 |
+
}
|
| 58 |
+
#pdf-preview {
|
| 59 |
+
width: 100%;
|
| 60 |
+
height: 500px;
|
| 61 |
+
border: 1px solid #e2e8f0;
|
| 62 |
+
}
|
| 63 |
+
</style>
|
| 64 |
+
</head>
|
| 65 |
+
<body class="bg-gray-50 min-h-screen">
|
| 66 |
+
<div class="container mx-auto px-4 py-8">
|
| 67 |
+
<header class="mb-10 text-center">
|
| 68 |
+
<h1 class="text-3xl font-bold text-blue-800 mb-2">Générateur de document de synthèse ANAH</h1>
|
| 69 |
+
<p class="text-gray-600">Chargez votre audit et votre modèle PDF éditable pour remplir automatiquement le document</p>
|
| 70 |
+
</header>
|
| 71 |
+
|
| 72 |
+
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8">
|
| 73 |
+
<!-- Section Audit Énergétique -->
|
| 74 |
+
<div class="bg-white rounded-lg shadow-md p-6">
|
| 75 |
+
<h2 class="text-xl font-semibold text-blue-700 mb-4 flex items-center">
|
| 76 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 77 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 17v-2m3 2v-4m3 4v-6m2 10H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
| 78 |
+
</svg>
|
| 79 |
+
Audit Énergétique (Source de données)
|
| 80 |
+
</h2>
|
| 81 |
+
<div class="mb-4">
|
| 82 |
+
<p class="text-sm text-gray-600 mb-2">Le fichier PDF contenant les données à extraire pour remplir le modèle</p>
|
| 83 |
+
<div id="audit-dropzone" class="dropzone rounded-lg p-8 text-center cursor-pointer">
|
| 84 |
+
<div class="flex flex-col items-center justify-center">
|
| 85 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-blue-500 mb-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 86 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
|
| 87 |
+
</svg>
|
| 88 |
+
<p class="text-gray-600 mb-1">Glissez-déposez votre audit énergétique ici</p>
|
| 89 |
+
<p class="text-sm text-gray-500">ou</p>
|
| 90 |
+
<button id="audit-select-btn" class="mt-2 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
|
| 91 |
+
Sélectionner un fichier
|
| 92 |
+
</button>
|
| 93 |
+
</div>
|
| 94 |
+
<input type="file" id="audit-file" accept=".pdf" class="hidden">
|
| 95 |
+
</div>
|
| 96 |
+
<div id="audit-info" class="hidden bg-blue-50 border border-blue-200 rounded-md p-4 mt-4">
|
| 97 |
+
<div class="flex justify-between items-center">
|
| 98 |
+
<div>
|
| 99 |
+
<h3 class="font-medium text-blue-800" id="audit-filename"></h3>
|
| 100 |
+
<p class="text-sm text-blue-600" id="audit-filesize"></p>
|
| 101 |
+
</div>
|
| 102 |
+
<button id="audit-remove-btn" class="text-red-500 hover:text-red-700">
|
| 103 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
| 104 |
+
<path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
|
| 105 |
+
</svg>
|
| 106 |
+
</button>
|
| 107 |
+
</div>
|
| 108 |
+
<div class="mt-3">
|
| 109 |
+
<label class="block text-sm font-medium text-gray-700 mb-1">Données extraites de l'audit</label>
|
| 110 |
+
<div id="audit-data" class="space-y-2">
|
| 111 |
+
<!-- Les données extraites seront ajoutées ici dynamiquement -->
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
</div>
|
| 116 |
+
</div>
|
| 117 |
+
|
| 118 |
+
<!-- Section Modèle PDF -->
|
| 119 |
+
<div class="bg-white rounded-lg shadow-md p-6">
|
| 120 |
+
<h2 class="text-xl font-semibold text-blue-700 mb-4 flex items-center">
|
| 121 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 122 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
|
| 123 |
+
</svg>
|
| 124 |
+
Modèle PDF Éditable (À remplir)
|
| 125 |
+
</h2>
|
| 126 |
+
<div class="mb-4">
|
| 127 |
+
<p class="text-sm text-gray-600 mb-2">Le fichier PDF modèle contenant les champs de formulaire à remplir</p>
|
| 128 |
+
<div id="template-dropzone" class="dropzone rounded-lg p-8 text-center cursor-pointer">
|
| 129 |
+
<div class="flex flex-col items-center justify-center">
|
| 130 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-blue-500 mb-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 131 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
|
| 132 |
+
</svg>
|
| 133 |
+
<p class="text-gray-600 mb-1">Glissez-déposez votre modèle PDF éditable ici</p>
|
| 134 |
+
<p class="text-sm text-gray-500">ou</p>
|
| 135 |
+
<button id="template-select-btn" class="mt-2 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
|
| 136 |
+
Sélectionner un fichier
|
| 137 |
+
</button>
|
| 138 |
+
</div>
|
| 139 |
+
<input type="file" id="template-file" accept=".pdf" class="hidden">
|
| 140 |
+
</div>
|
| 141 |
+
<div id="template-info" class="hidden bg-blue-50 border border-blue-200 rounded-md p-4 mt-4">
|
| 142 |
+
<div class="flex justify-between items-center">
|
| 143 |
+
<div>
|
| 144 |
+
<h3 class="font-medium text-blue-800" id="template-filename"></h3>
|
| 145 |
+
<p class="text-sm text-blue-600" id="template-filesize"></p>
|
| 146 |
+
</div>
|
| 147 |
+
<button id="template-remove-btn" class="text-red-500 hover:text-red-700">
|
| 148 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
| 149 |
+
<path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
|
| 150 |
+
</svg>
|
| 151 |
+
</button>
|
| 152 |
+
</div>
|
| 153 |
+
<div class="mt-3">
|
| 154 |
+
<div id="auto-match-results" class="space-y-3 mb-4">
|
| 155 |
+
<!-- Les résultats de la correspondance automatique seront affichés ici -->
|
| 156 |
+
</div>
|
| 157 |
+
<label class="block text-sm font-medium text-gray-700 mb-1">Correspondance des champs</label>
|
| 158 |
+
<div id="field-mapping" class="space-y-3">
|
| 159 |
+
<!-- Les champs du modèle avec leur correspondance seront ajoutés ici dynamiquement -->
|
| 160 |
+
</div>
|
| 161 |
+
</div>
|
| 162 |
+
</div>
|
| 163 |
+
</div>
|
| 164 |
+
</div>
|
| 165 |
+
</div>
|
| 166 |
+
|
| 167 |
+
<!-- Bouton Générer et Aperçu -->
|
| 168 |
+
<div class="text-center mb-8">
|
| 169 |
+
<button id="generate-btn" class="px-6 py-3 bg-green-600 text-white font-medium rounded-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed" disabled>
|
| 170 |
+
<span id="generate-text">Remplir le Modèle</span>
|
| 171 |
+
<span id="loading-spinner" class="loading-spinner ml-2">
|
| 172 |
+
<svg class="animate-spin h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
| 173 |
+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
| 174 |
+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
| 175 |
+
</svg>
|
| 176 |
+
</span>
|
| 177 |
+
</button>
|
| 178 |
+
<div id="progress-container" class="hidden mt-4 max-w-md mx-auto">
|
| 179 |
+
<div class="flex justify-between text-sm text-gray-600 mb-1">
|
| 180 |
+
<span>Progression</span>
|
| 181 |
+
<span id="progress-percent">0%</span>
|
| 182 |
+
</div>
|
| 183 |
+
<div class="progress-bar">
|
| 184 |
+
<div id="progress-bar-fill" class="progress-bar-fill" style="width: 0%"></div>
|
| 185 |
+
</div>
|
| 186 |
+
</div>
|
| 187 |
+
</div>
|
| 188 |
+
|
| 189 |
+
<!-- Aperçu PDF -->
|
| 190 |
+
<div id="preview-section" class="hidden bg-white rounded-lg shadow-md p-6 mb-8">
|
| 191 |
+
<div class="flex justify-between items-center mb-4">
|
| 192 |
+
<h2 class="text-xl font-semibold text-blue-700 flex items-center">
|
| 193 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 194 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
| 195 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
|
| 196 |
+
</svg>
|
| 197 |
+
Aperçu du Document Rempli
|
| 198 |
+
</h2>
|
| 199 |
+
<button id="download-btn" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 flex items-center">
|
| 200 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 201 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
|
| 202 |
+
</svg>
|
| 203 |
+
Télécharger
|
| 204 |
+
</button>
|
| 205 |
+
</div>
|
| 206 |
+
<div id="pdf-preview" class="w-full h-[500px] border border-gray-200 rounded-lg">
|
| 207 |
+
<iframe id="pdf-iframe" class="w-full h-full" frameborder="0"></iframe>
|
| 208 |
+
</div>
|
| 209 |
+
</div>
|
| 210 |
+
|
| 211 |
+
<!-- Section de correspondance manuelle -->
|
| 212 |
+
<div id="manual-mapping-section" class="hidden bg-white rounded-lg shadow-md p-6 mb-8">
|
| 213 |
+
<h2 class="text-xl font-semibold text-blue-700 mb-4 flex items-center">
|
| 214 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 215 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
|
| 216 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
| 217 |
+
</svg>
|
| 218 |
+
Correspondance Manuelle des Champs
|
| 219 |
+
</h2>
|
| 220 |
+
<div id="manual-mapping-container" class="space-y-4">
|
| 221 |
+
<!-- Les champs pour la correspondance manuelle seront ajoutés ici -->
|
| 222 |
+
</div>
|
| 223 |
+
<div class="mt-6 text-right">
|
| 224 |
+
<button id="save-mapping-btn" class="px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2">
|
| 225 |
+
Enregistrer les correspondances
|
| 226 |
+
</button>
|
| 227 |
+
</div>
|
| 228 |
+
</div>
|
| 229 |
+
</div>
|
| 230 |
+
|
| 231 |
+
<script>
|
| 232 |
+
// Variables globales
|
| 233 |
+
let auditFile = null;
|
| 234 |
+
let templateFile = null;
|
| 235 |
+
let auditData = {};
|
| 236 |
+
let templateFields = [];
|
| 237 |
+
let fieldMappings = {};
|
| 238 |
+
let generatedPdfBlob = null;
|
| 239 |
+
let templatePdfBytes = null;
|
| 240 |
+
|
| 241 |
+
// Éléments DOM
|
| 242 |
+
const auditDropzone = document.getElementById('audit-dropzone');
|
| 243 |
+
const auditSelectBtn = document.getElementById('audit-select-btn');
|
| 244 |
+
const auditFileInput = document.getElementById('audit-file');
|
| 245 |
+
const auditInfo = document.getElementById('audit-info');
|
| 246 |
+
const auditFilename = document.getElementById('audit-filename');
|
| 247 |
+
const auditFilesize = document.getElementById('audit-filesize');
|
| 248 |
+
const auditRemoveBtn = document.getElementById('audit-remove-btn');
|
| 249 |
+
const auditDataContainer = document.getElementById('audit-data');
|
| 250 |
+
|
| 251 |
+
const templateDropzone = document.getElementById('template-dropzone');
|
| 252 |
+
const templateSelectBtn = document.getElementById('template-select-btn');
|
| 253 |
+
const templateFileInput = document.getElementById('template-file');
|
| 254 |
+
const templateInfo = document.getElementById('template-info');
|
| 255 |
+
const templateFilename = document.getElementById('template-filename');
|
| 256 |
+
const templateFilesize = document.getElementById('template-filesize');
|
| 257 |
+
const templateRemoveBtn = document.getElementById('template-remove-btn');
|
| 258 |
+
const fieldMappingContainer = document.getElementById('field-mapping');
|
| 259 |
+
const autoMatchResults = document.getElementById('auto-match-results');
|
| 260 |
+
|
| 261 |
+
const generateBtn = document.getElementById('generate-btn');
|
| 262 |
+
const generateText = document.getElementById('generate-text');
|
| 263 |
+
const loadingSpinner = document.getElementById('loading-spinner');
|
| 264 |
+
const progressContainer = document.getElementById('progress-container');
|
| 265 |
+
const progressPercent = document.getElementById('progress-percent');
|
| 266 |
+
const progressBarFill = document.getElementById('progress-bar-fill');
|
| 267 |
+
|
| 268 |
+
const previewSection = document.getElementById('preview-section');
|
| 269 |
+
const pdfIframe = document.getElementById('pdf-iframe');
|
| 270 |
+
const downloadBtn = document.getElementById('download-btn');
|
| 271 |
+
|
| 272 |
+
const manualMappingSection = document.getElementById('manual-mapping-section');
|
| 273 |
+
const manualMappingContainer = document.getElementById('manual-mapping-container');
|
| 274 |
+
const saveMappingBtn = document.getElementById('save-mapping-btn');
|
| 275 |
+
|
| 276 |
+
// Gestionnaires d'événements pour l'audit
|
| 277 |
+
auditSelectBtn.addEventListener('click', () => auditFileInput.click());
|
| 278 |
+
auditFileInput.addEventListener('change', handleAuditFileSelect);
|
| 279 |
+
auditRemoveBtn.addEventListener('click', removeAuditFile);
|
| 280 |
+
|
| 281 |
+
// Gestionnaires d'événements pour le modèle
|
| 282 |
+
templateSelectBtn.addEventListener('click', () => templateFileInput.click());
|
| 283 |
+
templateFileInput.addEventListener('change', handleTemplateFileSelect);
|
| 284 |
+
templateRemoveBtn.addEventListener('click', removeTemplateFile);
|
| 285 |
+
|
| 286 |
+
// Gestionnaires pour le glisser-déposer
|
| 287 |
+
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
| 288 |
+
auditDropzone.addEventListener(eventName, preventDefaults, false);
|
| 289 |
+
templateDropzone.addEventListener(eventName, preventDefaults, false);
|
| 290 |
+
});
|
| 291 |
+
|
| 292 |
+
['dragenter', 'dragover'].forEach(eventName => {
|
| 293 |
+
auditDropzone.addEventListener(eventName, highlightAudit, false);
|
| 294 |
+
templateDropzone.addEventListener(eventName, highlightTemplate, false);
|
| 295 |
+
});
|
| 296 |
+
|
| 297 |
+
['dragleave', 'drop'].forEach(eventName => {
|
| 298 |
+
auditDropzone.addEventListener(eventName, unhighlightAudit, false);
|
| 299 |
+
templateDropzone.addEventListener(eventName, unhighlightTemplate, false);
|
| 300 |
+
});
|
| 301 |
+
|
| 302 |
+
auditDropzone.addEventListener('drop', handleAuditDrop, false);
|
| 303 |
+
templateDropzone.addEventListener('drop', handleTemplateDrop, false);
|
| 304 |
+
|
| 305 |
+
// Gestionnaire pour le bouton Générer
|
| 306 |
+
generateBtn.addEventListener('click', generateDocument);
|
| 307 |
+
|
| 308 |
+
// Gestionnaire pour le bouton Télécharger
|
| 309 |
+
downloadBtn.addEventListener('click', downloadDocument);
|
| 310 |
+
|
| 311 |
+
// Gestionnaire pour le bouton Enregistrer les correspondances
|
| 312 |
+
saveMappingBtn.addEventListener('click', saveManualMappings);
|
| 313 |
+
|
| 314 |
+
// Fonctions utilitaires
|
| 315 |
+
function preventDefaults(e) {
|
| 316 |
+
e.preventDefault();
|
| 317 |
+
e.stopPropagation();
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
function highlightAudit() {
|
| 321 |
+
auditDropzone.classList.add('active');
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
function unhighlightAudit() {
|
| 325 |
+
auditDropzone.classList.remove('active');
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
function highlightTemplate() {
|
| 329 |
+
templateDropzone.classList.add('active');
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
function unhighlightTemplate() {
|
| 333 |
+
templateDropzone.classList.remove('active');
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
function handleAuditDrop(e) {
|
| 337 |
+
const dt = e.dataTransfer;
|
| 338 |
+
const file = dt.files[0];
|
| 339 |
+
if (file && file.type === 'application/pdf') {
|
| 340 |
+
handleAuditFile(file);
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
function handleTemplateDrop(e) {
|
| 345 |
+
const dt = e.dataTransfer;
|
| 346 |
+
const file = dt.files[0];
|
| 347 |
+
if (file && file.type === 'application/pdf') {
|
| 348 |
+
handleTemplateFile(file);
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
function handleAuditFileSelect(e) {
|
| 353 |
+
const file = e.target.files[0];
|
| 354 |
+
if (file && file.type === 'application/pdf') {
|
| 355 |
+
handleAuditFile(file);
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
async function handleTemplateFileSelect(e) {
|
| 360 |
+
const file = e.target.files[0];
|
| 361 |
+
if (file && file.type === 'application/pdf') {
|
| 362 |
+
await handleTemplateFile(file);
|
| 363 |
+
}
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
function handleAuditFile(file) {
|
| 367 |
+
auditFile = file;
|
| 368 |
+
updateFileInfo(auditFilename, auditFilesize, file);
|
| 369 |
+
auditInfo.classList.remove('hidden');
|
| 370 |
+
|
| 371 |
+
// Simuler l'extraction de données (à remplacer par une vraie extraction)
|
| 372 |
+
simulateDataExtraction();
|
| 373 |
+
|
| 374 |
+
checkGenerateButton();
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
async function handleTemplateFile(file) {
|
| 378 |
+
templateFile = file;
|
| 379 |
+
updateFileInfo(templateFilename, templateFilesize, file);
|
| 380 |
+
templateInfo.classList.remove('hidden');
|
| 381 |
+
|
| 382 |
+
// Lire le contenu du fichier PDF
|
| 383 |
+
const arrayBuffer = await file.arrayBuffer();
|
| 384 |
+
templatePdfBytes = new Uint8Array(arrayBuffer);
|
| 385 |
+
|
| 386 |
+
// Simuler l'extraction des champs du formulaire PDF
|
| 387 |
+
simulateFormFieldsExtraction();
|
| 388 |
+
|
| 389 |
+
checkGenerateButton();
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
function updateFileInfo(nameElement, sizeElement, file) {
|
| 393 |
+
nameElement.textContent = file.name;
|
| 394 |
+
sizeElement.textContent = formatFileSize(file.size);
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
function formatFileSize(bytes) {
|
| 398 |
+
if (bytes === 0) return '0 Bytes';
|
| 399 |
+
const k = 1024;
|
| 400 |
+
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
| 401 |
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
| 402 |
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
function removeAuditFile() {
|
| 406 |
+
auditFile = null;
|
| 407 |
+
auditFileInput.value = '';
|
| 408 |
+
auditInfo.classList.add('hidden');
|
| 409 |
+
auditData = {};
|
| 410 |
+
auditDataContainer.innerHTML = '';
|
| 411 |
+
checkGenerateButton();
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
function removeTemplateFile() {
|
| 415 |
+
templateFile = null;
|
| 416 |
+
templateFileInput.value = '';
|
| 417 |
+
templateInfo.classList.add('hidden');
|
| 418 |
+
templateFields = [];
|
| 419 |
+
templatePdfBytes = null;
|
| 420 |
+
fieldMappingContainer.innerHTML = '';
|
| 421 |
+
autoMatchResults.innerHTML = '';
|
| 422 |
+
checkGenerateButton();
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
function simulateDataExtraction() {
|
| 426 |
+
// Simulation de données extraites d'un audit énergétique
|
| 427 |
+
auditData = {
|
| 428 |
+
'adresse': '12 Rue des Lilas, 75020 Paris',
|
| 429 |
+
'surface': '85 m²',
|
| 430 |
+
'annee_construction': '1985',
|
| 431 |
+
'dpe_etiquette_energie': 'D',
|
| 432 |
+
'dpe_etiquette_ges': 'C',
|
| 433 |
+
'conso_energie': '180 kWh/m².an',
|
| 434 |
+
'ges_emissions': '12 kgCO2/m².an',
|
| 435 |
+
'proprietaire': 'M. Dupont Jean',
|
| 436 |
+
'type_batiment': 'Appartement',
|
| 437 |
+
'nombre_logements': '1',
|
| 438 |
+
'chauffage': 'Chaudière gaz individuelle',
|
| 439 |
+
'eau_chaude': 'Chaudière gaz instantanée',
|
| 440 |
+
'ventilation': 'VMC simple flux',
|
| 441 |
+
'isolation': 'Comble perdu isolé, murs non isolés'
|
| 442 |
+
};
|
| 443 |
+
|
| 444 |
+
// Afficher les données extraites
|
| 445 |
+
auditDataContainer.innerHTML = '';
|
| 446 |
+
for (const [key, value] of Object.entries(auditData)) {
|
| 447 |
+
const div = document.createElement('div');
|
| 448 |
+
div.className = 'flex justify-between items-center p-2 bg-gray-50 rounded';
|
| 449 |
+
div.innerHTML = `
|
| 450 |
+
<span class="font-medium text-gray-700">${key.replace(/_/g, ' ')}</span>
|
| 451 |
+
<span class="text-gray-600">${value}</span>
|
| 452 |
+
`;
|
| 453 |
+
auditDataContainer.appendChild(div);
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
function simulateFormFieldsExtraction() {
|
| 458 |
+
// Simulation de champs de formulaire extraits d'un PDF
|
| 459 |
+
templateFields = [
|
| 460 |
+
{ name: 'adresse_propriete', type: 'text', description: 'Adresse du bien' },
|
| 461 |
+
{ name: 'surface_habitable', type: 'text', description: 'Surface habitable en m²' },
|
| 462 |
+
{ name: 'annee_batiment', type: 'text', description: 'Année de construction' },
|
| 463 |
+
{ name: 'etiquette_energie', type: 'text', description: 'Étiquette énergie DPE' },
|
| 464 |
+
{ name: 'etiquette_climat', type: 'text', description: 'Étiquette GES DPE' },
|
| 465 |
+
{ name: 'type_chauffage', type: 'text', description: 'Système de chauffage principal' },
|
| 466 |
+
{ name: 'isolation_description', type: 'text', description: 'Description de l\'isolation' },
|
| 467 |
+
{ name: 'nom_proprietaire', type: 'text', description: 'Nom du propriétaire' }
|
| 468 |
+
];
|
| 469 |
+
|
| 470 |
+
// Simuler une correspondance automatique
|
| 471 |
+
autoMatchFields();
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
function autoMatchFields() {
|
| 475 |
+
// Simulation de correspondance automatique avec les champs spécifiques demandés
|
| 476 |
+
const matchedFields = [
|
| 477 |
+
{ templateField: 'adresse_propriete', auditField: 'adresse', confidence: 'high' },
|
| 478 |
+
{ templateField: 'surface_habitable', auditField: 'surface', confidence: 'high' },
|
| 479 |
+
{ templateField: 'annee_batiment', auditField: 'annee_construction', confidence: 'high' },
|
| 480 |
+
{ templateField: 'etiquette_energie', auditField: 'dpe_etiquette_energie', confidence: 'high' },
|
| 481 |
+
{ templateField: 'etiquette_climat', auditField: 'dpe_etiquette_ges', confidence: 'high' },
|
| 482 |
+
{ templateField: 'type_chauffage', auditField: 'chauffage', confidence: 'high' }, // Correspondance spécifique demandée
|
| 483 |
+
{ templateField: 'isolation_description', auditField: 'isolation', confidence: 'high' }, // Correspondance spécifique demandée
|
| 484 |
+
{ templateField: 'nom_proprietaire', auditField: 'proprietaire', confidence: 'medium' }
|
| 485 |
+
];
|
| 486 |
+
|
| 487 |
+
// Afficher les résultats de la correspondance automatique
|
| 488 |
+
autoMatchResults.innerHTML = `
|
| 489 |
+
<div class="p-3 rounded-md ${matchedFields.length > 0 ? 'match-success' : 'match-warning'}">
|
| 490 |
+
<div class="flex items-center">
|
| 491 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2 ${matchedFields.length > 0 ? 'text-green-500' : 'text-yellow-500'}" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 492 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="${matchedFields.length > 0 ? 'M5 13l4 4L19 7' : 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z'}" />
|
| 493 |
+
</svg>
|
| 494 |
+
<span class="font-medium">${matchedFields.length > 0 ? 'Correspondances automatiques trouvées' : 'Aucune correspondance automatique trouvée'}</span>
|
| 495 |
+
</div>
|
| 496 |
+
${matchedFields.length > 0 ? `
|
| 497 |
+
<p class="mt-2 text-sm">${matchedFields.length} champs sur ${templateFields.length} ont été automatiquement associés.</p>
|
| 498 |
+
` : `
|
| 499 |
+
<p class="mt-2 text-sm">Veuillez définir manuellement les correspondances entre les champs.</p>
|
| 500 |
+
`}
|
| 501 |
+
</div>
|
| 502 |
+
`;
|
| 503 |
+
|
| 504 |
+
// Initialiser les mappings
|
| 505 |
+
fieldMappings = {};
|
| 506 |
+
|
| 507 |
+
// Afficher les champs pour la correspondance
|
| 508 |
+
fieldMappingContainer.innerHTML = '';
|
| 509 |
+
templateFields.forEach(field => {
|
| 510 |
+
const matched = matchedFields.find(m => m.templateField === field.name);
|
| 511 |
+
|
| 512 |
+
const div = document.createElement('div');
|
| 513 |
+
div.className = 'p-3 bg-gray-50 rounded-md';
|
| 514 |
+
div.innerHTML = `
|
| 515 |
+
<div class="flex justify-between items-center mb-2">
|
| 516 |
+
<span class="font-medium text-gray-700">${field.description}</span>
|
| 517 |
+
${matched ? `
|
| 518 |
+
<span class="text-xs px-2 py-1 bg-green-100 text-green-800 rounded-full">Correspondance automatique</span>
|
| 519 |
+
` : ''}
|
| 520 |
+
</div>
|
| 521 |
+
<div class="flex items-center space-x-2">
|
| 522 |
+
<select class="flex-1 border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" data-template-field="${field.name}">
|
| 523 |
+
<option value="">-- Sélectionner une donnée --</option>
|
| 524 |
+
${Object.keys(auditData).map(key => `
|
| 525 |
+
<option value="${key}" ${matched && matched.auditField === key ? 'selected' : ''}>${key.replace(/_/g, ' ')}</option>
|
| 526 |
+
`).join('')}
|
| 527 |
+
</select>
|
| 528 |
+
<button class="px-3 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 focus:outline-none" data-field="${field.name}" onclick="previewFieldMapping(this)">
|
| 529 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 530 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
| 531 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
|
| 532 |
+
</svg>
|
| 533 |
+
</button>
|
| 534 |
+
</div>
|
| 535 |
+
`;
|
| 536 |
+
fieldMappingContainer.appendChild(div);
|
| 537 |
+
|
| 538 |
+
if (matched) {
|
| 539 |
+
fieldMappings[field.name] = matched.auditField;
|
| 540 |
+
}
|
| 541 |
+
});
|
| 542 |
+
|
| 543 |
+
// Afficher la section de correspondance manuelle si nécessaire
|
| 544 |
+
if (matchedFields.length < templateFields.length / 2) {
|
| 545 |
+
manualMappingSection.classList.remove('hidden');
|
| 546 |
+
setupManualMapping();
|
| 547 |
+
} else {
|
| 548 |
+
manualMappingSection.classList.add('hidden');
|
| 549 |
+
}
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
function setupManualMapping() {
|
| 553 |
+
manualMappingContainer.innerHTML = '';
|
| 554 |
+
|
| 555 |
+
templateFields.forEach(field => {
|
| 556 |
+
const div = document.createElement('div');
|
| 557 |
+
div.className = 'grid grid-cols-1 md:grid-cols-3 gap-4 items-center p-3 bg-gray-50 rounded-md';
|
| 558 |
+
div.innerHTML = `
|
| 559 |
+
<div>
|
| 560 |
+
<p class="font-medium text-gray-700">${field.description}</p>
|
| 561 |
+
<p class="text-sm text-gray-500">${field.name}</p>
|
| 562 |
+
</div>
|
| 563 |
+
<div class="flex items-center">
|
| 564 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mx-2 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 565 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 5l7 7-7 7M5 5l7 7-7 7" />
|
| 566 |
+
</svg>
|
| 567 |
+
</div>
|
| 568 |
+
<div>
|
| 569 |
+
<select class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" data-manual-field="${field.name}">
|
| 570 |
+
<option value="">-- Non mappé --</option>
|
| 571 |
+
${Object.keys(auditData).map(key => `
|
| 572 |
+
<option value="${key}" ${fieldMappings[field.name] === key ? 'selected' : ''}>${key.replace(/_/g, ' ')}</option>
|
| 573 |
+
`).join('')}
|
| 574 |
+
</select>
|
| 575 |
+
</div>
|
| 576 |
+
`;
|
| 577 |
+
manualMappingContainer.appendChild(div);
|
| 578 |
+
});
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
function saveManualMappings() {
|
| 582 |
+
const selects = manualMappingContainer.querySelectorAll('select');
|
| 583 |
+
selects.forEach(select => {
|
| 584 |
+
const fieldName = select.dataset.manualField;
|
| 585 |
+
const selectedValue = select.value;
|
| 586 |
+
|
| 587 |
+
if (selectedValue) {
|
| 588 |
+
fieldMappings[fieldName] = selectedValue;
|
| 589 |
+
} else {
|
| 590 |
+
delete fieldMappings[fieldName];
|
| 591 |
+
}
|
| 592 |
+
});
|
| 593 |
+
|
| 594 |
+
manualMappingSection.classList.add('hidden');
|
| 595 |
+
|
| 596 |
+
// Mettre à jour les sélections dans la section principale
|
| 597 |
+
updateMainFieldMappings();
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
function updateMainFieldMappings() {
|
| 601 |
+
const selects = fieldMappingContainer.querySelectorAll('select');
|
| 602 |
+
selects.forEach(select => {
|
| 603 |
+
const fieldName = select.dataset.templateField;
|
| 604 |
+
if (fieldMappings[fieldName]) {
|
| 605 |
+
select.value = fieldMappings[fieldName];
|
| 606 |
+
} else {
|
| 607 |
+
select.value = '';
|
| 608 |
+
}
|
| 609 |
+
});
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
function previewFieldMapping(button) {
|
| 613 |
+
const fieldName = button.dataset.field;
|
| 614 |
+
const select = document.querySelector(`select[data-template-field="${fieldName}"]`);
|
| 615 |
+
const selectedValue = select.value;
|
| 616 |
+
|
| 617 |
+
if (selectedValue) {
|
| 618 |
+
alert(`Aperçu du mappage:\n\nChamp PDF: ${fieldName}\nDonnée audit: ${selectedValue}\nValeur: ${auditData[selectedValue]}`);
|
| 619 |
+
} else {
|
| 620 |
+
alert('Veuillez sélectionner une donnée à associer à ce champ.');
|
| 621 |
+
}
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
function checkGenerateButton() {
|
| 625 |
+
if (auditFile && templateFile && Object.keys(fieldMappings).length > 0) {
|
| 626 |
+
generateBtn.disabled = false;
|
| 627 |
+
} else {
|
| 628 |
+
generateBtn.disabled = true;
|
| 629 |
+
}
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
async function generateDocument() {
|
| 633 |
+
// Simulation de génération de document avec PDF-lib
|
| 634 |
+
generateBtn.disabled = true;
|
| 635 |
+
generateText.textContent = 'Génération en cours...';
|
| 636 |
+
loadingSpinner.classList.add('active');
|
| 637 |
+
progressContainer.classList.remove('hidden');
|
| 638 |
+
|
| 639 |
+
let progress = 0;
|
| 640 |
+
const interval = setInterval(() => {
|
| 641 |
+
progress += 10;
|
| 642 |
+
progressPercent.textContent = `${progress}%`;
|
| 643 |
+
progressBarFill.style.width = `${progress}%`;
|
| 644 |
+
|
| 645 |
+
if (progress >= 100) {
|
| 646 |
+
clearInterval(interval);
|
| 647 |
+
generateComplete();
|
| 648 |
+
}
|
| 649 |
+
}, 300);
|
| 650 |
+
|
| 651 |
+
try {
|
| 652 |
+
// Charger le modèle PDF
|
| 653 |
+
const { PDFDocument } = PDFLib;
|
| 654 |
+
const pdfDoc = await PDFDocument.load(templatePdfBytes);
|
| 655 |
+
|
| 656 |
+
// Remplir les champs du formulaire
|
| 657 |
+
const form = pdfDoc.getForm();
|
| 658 |
+
|
| 659 |
+
// D'abord, lister tous les champs disponibles dans le PDF
|
| 660 |
+
const fields = form.getFields();
|
| 661 |
+
console.log('Champs disponibles dans le PDF:', fields.map(f => f.getName()));
|
| 662 |
+
|
| 663 |
+
// Ensuite, remplir les champs selon les mappings
|
| 664 |
+
for (const [templateField, auditField] of Object.entries(fieldMappings)) {
|
| 665 |
+
try {
|
| 666 |
+
const field = form.getField(templateField);
|
| 667 |
+
if (field) {
|
| 668 |
+
const value = auditData[auditField] || '';
|
| 669 |
+
console.log(`Remplissage du champ ${templateField} avec:`, value);
|
| 670 |
+
|
| 671 |
+
// Vérifier le type de champ et le remplir en conséquence
|
| 672 |
+
switch (field.constructor.name) {
|
| 673 |
+
case 'PDFTextField':
|
| 674 |
+
field.setText(value.toString());
|
| 675 |
+
break;
|
| 676 |
+
case 'PDFDropdown':
|
| 677 |
+
case 'PDFOptionList':
|
| 678 |
+
// Pour les menus déroulants, on essaie de sélectionner l'option correspondante
|
| 679 |
+
const options = field.getOptions();
|
| 680 |
+
const matchingOption = options.find(opt => opt.toLowerCase().includes(value.toLowerCase()));
|
| 681 |
+
if (matchingOption) {
|
| 682 |
+
field.select(matchingOption);
|
| 683 |
+
} else if (options.length > 0) {
|
| 684 |
+
// Si aucune correspondance exacte, on prend la première option
|
| 685 |
+
field.select(options[0]);
|
| 686 |
+
}
|
| 687 |
+
break;
|
| 688 |
+
case 'PDFRadioGroup':
|
| 689 |
+
// Pour les boutons radio, on essaie de sélectionner l'option correspondante
|
| 690 |
+
const radioOptions = field.getOptions();
|
| 691 |
+
const matchingRadio = radioOptions.find(opt => opt.toLowerCase().includes(value.toLowerCase()));
|
| 692 |
+
if (matchingRadio) {
|
| 693 |
+
field.select(matchingRadio);
|
| 694 |
+
} else if (radioOptions.length > 0) {
|
| 695 |
+
// Si aucune correspondance exacte, on prend la première option
|
| 696 |
+
field.select(radioOptions[0]);
|
| 697 |
+
}
|
| 698 |
+
break;
|
| 699 |
+
case 'PDFCheckBox':
|
| 700 |
+
// Pour les cases à cocher, on coche si la valeur est "true", "oui", etc.
|
| 701 |
+
const checkValue = value.toString().toLowerCase();
|
| 702 |
+
if (checkValue === 'true' || checkValue === 'oui' || checkValue === 'yes' || checkValue === '1') {
|
| 703 |
+
field.check();
|
| 704 |
+
} else {
|
| 705 |
+
field.uncheck();
|
| 706 |
+
}
|
| 707 |
+
break;
|
| 708 |
+
default:
|
| 709 |
+
console.warn(`Type de champ non géré: ${field.constructor.name}`);
|
| 710 |
+
if (typeof field.setText === 'function') {
|
| 711 |
+
field.setText(value.toString());
|
| 712 |
+
}
|
| 713 |
+
}
|
| 714 |
+
} else {
|
| 715 |
+
console.warn(`Champ ${templateField} non trouvé dans le PDF`);
|
| 716 |
+
}
|
| 717 |
+
} catch (error) {
|
| 718 |
+
console.error(`Erreur lors du remplissage du champ ${templateField}:`, error);
|
| 719 |
+
}
|
| 720 |
+
}
|
| 721 |
+
|
| 722 |
+
// Sauvegarder le PDF généré
|
| 723 |
+
const pdfBytes = await pdfDoc.save();
|
| 724 |
+
generatedPdfBlob = new Blob([pdfBytes], { type: 'application/pdf' });
|
| 725 |
+
|
| 726 |
+
// Créer une URL pour l'aperçu
|
| 727 |
+
const pdfUrl = URL.createObjectURL(generatedPdfBlob);
|
| 728 |
+
pdfIframe.src = pdfUrl;
|
| 729 |
+
|
| 730 |
+
} catch (error) {
|
| 731 |
+
console.error('Erreur lors de la génération du PDF:', error);
|
| 732 |
+
alert('Une erreur est survenue lors de la génération du document.');
|
| 733 |
+
} finally {
|
| 734 |
+
clearInterval(interval);
|
| 735 |
+
generateComplete();
|
| 736 |
+
}
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
function generateComplete() {
|
| 740 |
+
generateText.textContent = 'Document généré!';
|
| 741 |
+
loadingSpinner.classList.remove('active');
|
| 742 |
+
|
| 743 |
+
// Afficher l'aperçu
|
| 744 |
+
previewSection.classList.remove('hidden');
|
| 745 |
+
|
| 746 |
+
// Réinitialiser la barre de progression après un délai
|
| 747 |
+
setTimeout(() => {
|
| 748 |
+
progressContainer.classList.add('hidden');
|
| 749 |
+
progressPercent.textContent = '0%';
|
| 750 |
+
progressBarFill.style.width = '0%';
|
| 751 |
+
}, 2000);
|
| 752 |
+
}
|
| 753 |
+
|
| 754 |
+
function downloadDocument() {
|
| 755 |
+
if (generatedPdfBlob) {
|
| 756 |
+
saveAs(generatedPdfBlob, 'document_anah_synthese.pdf');
|
| 757 |
+
} else {
|
| 758 |
+
alert('Aucun document généré à télécharger. Veuillez d\'abord générer le document.');
|
| 759 |
+
}
|
| 760 |
+
}
|
| 761 |
+
|
| 762 |
+
// Gestion des changements de sélection des champs
|
| 763 |
+
document.addEventListener('change', function(e) {
|
| 764 |
+
if (e.target && e.target.matches('select[data-template-field]')) {
|
| 765 |
+
const fieldName = e.target.dataset.templateField;
|
| 766 |
+
const selectedValue = e.target.value;
|
| 767 |
+
|
| 768 |
+
if (selectedValue) {
|
| 769 |
+
fieldMappings[fieldName] = selectedValue;
|
| 770 |
+
} else {
|
| 771 |
+
delete fieldMappings[fieldName];
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
checkGenerateButton();
|
| 775 |
+
}
|
| 776 |
+
});
|
| 777 |
+
|
| 778 |
+
// Exposer la fonction previewFieldMapping au scope global
|
| 779 |
+
window.previewFieldMapping = previewFieldMapping;
|
| 780 |
+
</script>
|
| 781 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Sachoun2002/test" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 782 |
+
</html>
|