-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-manager.html
More file actions
508 lines (448 loc) · 26.7 KB
/
Copy pathtemplate-manager.html
File metadata and controls
508 lines (448 loc) · 26.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
<!DOCTYPE html>
<html lang="ro">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gestionare Template-uri - Generator Documente</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8">
<div class="max-w-4xl mx-auto">
<!-- Header -->
<div class="flex items-center justify-between mb-8">
<div>
<h1 class="text-3xl font-bold text-gray-900 mb-2">Gestionare Template-uri</h1>
<p class="text-gray-600">Încarcă și gestionează template-urile tale personalizate</p>
</div>
<button onclick="goHome()" class="bg-gray-600 text-white px-4 py-2 rounded-md hover:bg-gray-700 transition-colors">
← Înapoi
</button>
</div>
<!-- Upload Section -->
<div class="bg-white rounded-lg shadow-md p-6 mb-8">
<h2 class="text-xl font-semibold text-gray-900 mb-4">Încarcă Template Nou</h2>
<div class="border-2 border-dashed border-gray-300 rounded-lg p-8 text-center">
<div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-4">
<svg class="w-6 h-6 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<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"></path>
</svg>
</div>
<p class="text-gray-600 mb-4">Selectează un fișier .docx pentru a încărca un template nou</p>
<input type="file" id="templateFile" accept=".docx" class="hidden" onchange="handleFileUpload(event)">
<button onclick="document.getElementById('templateFile').click()" class="bg-purple-600 text-white px-6 py-2 rounded-md hover:bg-purple-700 transition-colors">
Selectează Fișier
</button>
<p class="text-sm text-gray-500 mt-2">Fișierul trebuie să fie în format .docx cu placeholder-uri în format [NUME_PLACEHOLDER]</p>
</div>
</div>
<!-- Template List -->
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-900 mb-4">Template-uri Disponibile</h2>
<div id="templateList" class="space-y-4">
<!-- Templates will be loaded here -->
<div class="text-center py-8 text-gray-500">
<svg class="w-12 h-12 mx-auto mb-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 13h6m-3-3v6m5 5H7a2 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"></path>
</svg>
<p>Nu ai încă template-uri personalizate</p>
<p class="text-sm">Încarcă primul tău template pentru a începe</p>
</div>
</div>
</div>
</div>
</div>
<!-- Template Upload Modal -->
<div id="uploadModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden">
<div class="relative top-10 mx-auto p-5 border max-w-4xl shadow-lg rounded-md bg-white">
<div class="mt-3">
<h3 class="text-lg font-medium text-gray-900 mb-4 text-center">Configurează Template-ul</h3>
<!-- Template Name -->
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-2">Nume Template</label>
<input type="text" id="templateName" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-purple-500" placeholder="ex: Cerere concediu">
</div>
<!-- Placeholder Configuration -->
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-2">Configurează Placeholder-urile:</label>
<div id="detectedPlaceholders" class="max-h-96 overflow-y-auto bg-gray-50 p-4 rounded border">
<!-- Placeholders configuration will be listed here -->
</div>
</div>
<div class="flex justify-center space-x-3">
<button onclick="cancelUpload()" class="bg-gray-300 text-gray-700 px-4 py-2 rounded-md hover:bg-gray-400 transition-colors">
Anulează
</button>
<button onclick="confirmUpload()" class="bg-purple-600 text-white px-4 py-2 rounded-md hover:bg-purple-700 transition-colors">
Salvează Template
</button>
</div>
</div>
</div>
</div>
<script>
const { ipcRenderer } = require('electron');
let currentFile = null;
let currentPlaceholders = [];
function goHome() {
window.location.href = 'index.html';
}
async function handleFileUpload(event) {
const file = event.target.files[0];
if (!file) return;
if (!file.name.endsWith('.docx')) {
alert('Te rog selectează un fișier .docx valid');
return;
}
currentFile = file;
// Show loading
const modal = document.getElementById('uploadModal');
const placeholdersDiv = document.getElementById('detectedPlaceholders');
placeholdersDiv.innerHTML = '<div class="text-center"><div class="inline-block animate-spin rounded-full h-6 w-6 border-b-2 border-purple-600"></div><p class="mt-2">Analizez template-ul...</p></div>';
modal.classList.remove('hidden');
try {
// Read file and detect placeholders
const arrayBuffer = await file.arrayBuffer();
const placeholders = await ipcRenderer.invoke('detect-placeholders', arrayBuffer);
currentPlaceholders = placeholders;
displayPlaceholders(placeholders);
// Pre-fill template name
document.getElementById('templateName').value = file.name.replace('.docx', '');
} catch (error) {
console.error('Error analyzing template:', error);
placeholdersDiv.innerHTML = '<div class="text-red-600">Eroare la analizarea template-ului. Te rog încearcă din nou.</div>';
}
}
function displayPlaceholders(placeholders) {
const placeholdersDiv = document.getElementById('detectedPlaceholders');
if (placeholders.length === 0) {
placeholdersDiv.innerHTML = '<div class="text-yellow-600">Nu s-au găsit placeholder-uri în format [NUME]. Asigură-te că template-ul conține placeholder-uri în format [NUME_PLACEHOLDER].</div>';
return;
}
const placeholderConfigs = placeholders.map((placeholder, index) => {
const fieldId = placeholder.replace(/[\[\]]/g, '');
const defaultLabel = formatFieldLabel(fieldId.toLowerCase());
return `
<div class="border border-gray-200 rounded-lg p-4 mb-4 bg-white">
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
<!-- Placeholder Name -->
<div class="col-span-1 md:col-span-2 lg:col-span-1">
<label class="block text-xs font-medium text-gray-700 mb-1">Placeholder</label>
<div class="font-mono text-sm bg-gray-100 px-3 py-2 rounded border">${placeholder}</div>
</div>
<!-- Order -->
<div>
<label class="block text-xs font-medium text-gray-700 mb-1">Ordine</label>
<input type="number"
id="order_${fieldId}"
class="w-full px-3 py-2 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-purple-500"
value="${index + 1}"
min="1"
max="${placeholders.length}">
</div>
<!-- Field Type -->
<div>
<label class="block text-xs font-medium text-gray-700 mb-1">Tip Câmp</label>
<select id="type_${fieldId}"
class="w-full px-3 py-2 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-purple-500"
onchange="handleTypeChange('${fieldId}')">
<option value="text">Text scurt</option>
<option value="textarea">Text lung (mai multe linii)</option>
<option value="dropdown">Dropdown (listă opțiuni)</option>
<option value="checkbox">Checkbox (da/nu)</option>
<option value="gender">Gen (masculin/feminin)</option>
</select>
</div>
<!-- Custom Label -->
<div>
<label class="block text-xs font-medium text-gray-700 mb-1">Etichetă Personalizată</label>
<input type="text"
id="label_${fieldId}"
class="w-full px-3 py-2 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-purple-500"
value="${defaultLabel}"
placeholder="ex: Numele complet">
</div>
</div>
<!-- Additional Configuration Area -->
<div id="extraConfig_${fieldId}" class="mt-4 hidden">
<!-- Dynamic configuration based on field type will appear here -->
</div>
</div>
`;
}).join('');
placeholdersDiv.innerHTML = `
<div class="space-y-2">
<div class="text-sm text-gray-600 mb-4">
Configurează fiecare placeholder pentru a controla cum va apărea în formularul generat:
</div>
${placeholderConfigs}
<div class="mt-4 p-3 bg-blue-50 border border-blue-200 rounded-lg">
<div class="flex items-start">
<svg class="w-5 h-5 text-blue-600 mt-0.5 mr-2 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<div class="text-sm text-blue-800">
<strong>Tip:</strong> Ordinea determină cum vor apărea câmpurile în formular. Poți folosi tipul "Gen" pentru placeholder-uri care trebuie să se adapteze masculin/feminin (ex: "Subsemnatul/Subsemnata").
</div>
</div>
</div>
</div>
`;
}
function handleTypeChange(fieldId) {
const typeSelect = document.getElementById(`type_${fieldId}`);
const extraConfigDiv = document.getElementById(`extraConfig_${fieldId}`);
const selectedType = typeSelect.value;
extraConfigDiv.classList.remove('hidden');
switch(selectedType) {
case 'dropdown':
extraConfigDiv.innerHTML = `
<label class="block text-xs font-medium text-gray-700 mb-2">Opțiuni Dropdown (o opțiune pe linie)</label>
<textarea id="options_${fieldId}"
class="w-full px-3 py-2 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-purple-500"
rows="4"
placeholder="Opțiunea 1 Opțiunea 2 Opțiunea 3"></textarea>
`;
break;
case 'checkbox':
extraConfigDiv.innerHTML = `
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-medium text-gray-700 mb-2">Text când e bifat</label>
<input type="text"
id="checkedText_${fieldId}"
class="w-full px-3 py-2 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-purple-500"
value="Da"
placeholder="ex: Da, Acceptă">
</div>
<div>
<label class="block text-xs font-medium text-gray-700 mb-2">Text când nu e bifat</label>
<input type="text"
id="uncheckedText_${fieldId}"
class="w-full px-3 py-2 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-purple-500"
value="Nu"
placeholder="ex: Nu, Refuză">
</div>
</div>
`;
break;
case 'gender':
extraConfigDiv.innerHTML = `
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-medium text-gray-700 mb-2">Text pentru masculin</label>
<input type="text"
id="maleText_${fieldId}"
class="w-full px-3 py-2 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-purple-500"
placeholder="ex: Subsemnatul"
value="${inferMaleText(fieldId)}">
</div>
<div>
<label class="block text-xs font-medium text-gray-700 mb-2">Text pentru feminin</label>
<input type="text"
id="femaleText_${fieldId}"
class="w-full px-3 py-2 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-purple-500"
placeholder="ex: Subsemnata"
value="${inferFemaleText(fieldId)}">
</div>
</div>
<div class="mt-2 text-xs text-gray-600">
Utilizatorul va putea alege între masculin și feminin într-un dropdown.
</div>
`;
break;
case 'textarea':
extraConfigDiv.innerHTML = `
<label class="block text-xs font-medium text-gray-700 mb-2">Numărul de rânduri pentru textarea</label>
<input type="number"
id="rows_${fieldId}"
class="w-32 px-3 py-2 text-sm border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-purple-500"
value="4"
min="2"
max="10">
`;
break;
default:
extraConfigDiv.classList.add('hidden');
break;
}
}
function inferMaleText(fieldId) {
const placeholder = fieldId.toLowerCase();
if (placeholder.includes('subsemnat')) return 'Subsemnatul';
if (placeholder.includes('solicit')) return 'Solicitantul';
if (placeholder.includes('nume')) return 'Domnul';
return '';
}
function inferFemaleText(fieldId) {
const placeholder = fieldId.toLowerCase();
if (placeholder.includes('subsemnat')) return 'Subsemnata';
if (placeholder.includes('solicit')) return 'Solicitanta';
if (placeholder.includes('nume')) return 'Doamna';
return '';
}
async function confirmUpload() {
const templateName = document.getElementById('templateName').value.trim();
if (!templateName) {
alert('Te rog introdu un nume pentru template');
return;
}
if (!currentFile) {
alert('Eroare: Fișierul nu a fost găsit');
return;
}
try {
// Collect field configurations
const fieldConfigs = [];
currentPlaceholders.forEach(placeholder => {
const fieldId = placeholder.replace(/[\[\]]/g, '');
const order = parseInt(document.getElementById(`order_${fieldId}`)?.value || 1);
const type = document.getElementById(`type_${fieldId}`)?.value || 'text';
const label = document.getElementById(`label_${fieldId}`)?.value || placeholder;
const config = {
placeholder,
fieldId,
order,
type,
label
};
// Add type-specific configurations
switch(type) {
case 'dropdown':
const optionsText = document.getElementById(`options_${fieldId}`)?.value || '';
config.options = optionsText.split('\n').filter(opt => opt.trim()).map(opt => opt.trim());
break;
case 'checkbox':
config.checkedText = document.getElementById(`checkedText_${fieldId}`)?.value || 'Da';
config.uncheckedText = document.getElementById(`uncheckedText_${fieldId}`)?.value || 'Nu';
break;
case 'gender':
config.maleText = document.getElementById(`maleText_${fieldId}`)?.value || '';
config.femaleText = document.getElementById(`femaleText_${fieldId}`)?.value || '';
break;
case 'textarea':
config.rows = parseInt(document.getElementById(`rows_${fieldId}`)?.value || 4);
break;
}
fieldConfigs.push(config);
});
// Sort by order
fieldConfigs.sort((a, b) => a.order - b.order);
const arrayBuffer = await currentFile.arrayBuffer();
const result = await ipcRenderer.invoke('save-custom-template', {
name: templateName,
file: arrayBuffer,
originalName: currentFile.name,
placeholders: currentPlaceholders,
fieldConfigs: fieldConfigs
});
if (result.success) {
alert('Template-ul a fost salvat cu succes!');
cancelUpload();
loadTemplates();
} else {
alert('Eroare la salvarea template-ului: ' + result.error);
}
} catch (error) {
console.error('Error saving template:', error);
alert('Eroare la salvarea template-ului');
}
}
function formatFieldLabel(fieldName) {
return fieldName
.replace(/_/g, ' ')
.replace(/\b\w/g, l => l.toUpperCase());
}
function cancelUpload() {
document.getElementById('uploadModal').classList.add('hidden');
document.getElementById('templateFile').value = '';
document.getElementById('templateName').value = '';
currentFile = null;
currentPlaceholders = [];
}
async function loadTemplates() {
try {
const templates = await ipcRenderer.invoke('get-custom-templates');
displayTemplates(templates);
} catch (error) {
console.error('Error loading templates:', error);
}
}
function displayTemplates(templates) {
const templateList = document.getElementById('templateList');
if (templates.length === 0) {
templateList.innerHTML = `
<div class="text-center py-8 text-gray-500">
<svg class="w-12 h-12 mx-auto mb-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 13h6m-3-3v6m5 5H7a2 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"></path>
</svg>
<p>Nu ai încă template-uri personalizate</p>
<p class="text-sm">Încarcă primul tău template pentru a începe</p>
</div>
`;
return;
}
const templateCards = templates.map(template => `
<div class="border border-gray-200 rounded-lg p-4">
<div class="flex justify-between items-start">
<div class="flex-1">
<h3 class="text-lg font-semibold text-gray-900 mb-2">${template.name}</h3>
<p class="text-sm text-gray-600 mb-2">
<span class="inline-flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"></path>
</svg>
${template.placeholders.length} câmp${template.placeholders.length !== 1 ? 'uri' : ''}
</span>
${template.fieldConfigs && template.fieldConfigs.length > 0 ?
'<span class="ml-2 text-green-600 text-xs">✓ Configurat</span>' :
'<span class="ml-2 text-yellow-600 text-xs">Basic</span>'
}
</p>
<div class="text-xs text-gray-500">
${template.fieldConfigs && template.fieldConfigs.length > 0 ?
template.fieldConfigs.slice(0, 3).map(config =>
`<span class="bg-blue-100 text-blue-800 px-2 py-1 rounded mr-1" title="${config.placeholder}">${config.label || config.fieldId}</span>`
).join('') :
template.placeholders.slice(0, 3).map(p => `<span class="bg-gray-100 px-2 py-1 rounded mr-1">${p}</span>`).join('')
}
${template.placeholders.length > 3 ? '<span>...</span>' : ''}
</div>
</div>
<div class="flex space-x-2 ml-4">
<button onclick="useTemplate('${template.id}')" class="bg-blue-600 text-white px-3 py-1 text-sm rounded hover:bg-blue-700 transition-colors">
Folosește
</button>
<button onclick="deleteTemplate('${template.id}')" class="bg-red-600 text-white px-3 py-1 text-sm rounded hover:bg-red-700 transition-colors">
Șterge
</button>
</div>
</div>
</div>
`).join('');
templateList.innerHTML = templateCards;
}
async function useTemplate(templateId) {
window.location.href = `form-custom.html?template=${templateId}`;
}
async function deleteTemplate(templateId) {
if (!confirm('Ești sigur că vrei să ștergi acest template?')) {
return;
}
try {
const result = await ipcRenderer.invoke('delete-custom-template', templateId);
if (result.success) {
loadTemplates();
} else {
alert('Eroare la ștergerea template-ului: ' + result.error);
}
} catch (error) {
console.error('Error deleting template:', error);
alert('Eroare la ștergerea template-ului');
}
}
// Load templates when page loads
document.addEventListener('DOMContentLoaded', loadTemplates);
</script>
</body>
</html>