Docfile commited on
Commit
bb6a9eb
·
verified ·
1 Parent(s): 51c2bef

Create philosophie.html

Browse files
Files changed (1) hide show
  1. templates/philosophie.html +772 -0
templates/philosophie.html ADDED
@@ -0,0 +1,772 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Mariam AI - Assistant Philosophique</title>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
8
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
9
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert2/11.7.3/sweetalert2.all.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.3.0/marked.min.js"></script>
12
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
13
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/locale/fr.js"></script>
14
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert2/11.7.3/sweetalert2.min.css" rel="stylesheet">
15
+ <script src="https://cdn.tailwindcss.com"></script>
16
+ <style>
17
+ /* Styles existants */
18
+ .collapsible {
19
+ cursor: pointer;
20
+ padding: 18px;
21
+ width: 100%;
22
+ border: none;
23
+ text-align: left;
24
+ outline: none;
25
+ font-size: 15px;
26
+ background-color: #f1f1f1;
27
+ display: flex;
28
+ justify-content: space-between;
29
+ align-items: center;
30
+ }
31
+
32
+ /* Nouveaux styles pour le Markdown responsive */
33
+ .prose {
34
+ max-width: 100% !important;
35
+ }
36
+
37
+ .prose p {
38
+ margin-top: 1.25em;
39
+ margin-bottom: 1.25em;
40
+ line-height: 1.75;
41
+ }
42
+
43
+ .prose ul {
44
+ margin-top: 1.25em;
45
+ margin-bottom: 1.25em;
46
+ padding-left: 1.625em;
47
+ }
48
+
49
+ .prose li {
50
+ margin-top: 0.5em;
51
+ margin-bottom: 0.5em;
52
+ padding-left: 0.375em;
53
+ }
54
+
55
+ .prose h1, .prose h2, .prose h3 {
56
+ margin-top: 2em;
57
+ margin-bottom: 1em;
58
+ line-height: 1.3;
59
+ }
60
+
61
+ /* Styles spécifiques pour mobile */
62
+ @media (max-width: 640px) {
63
+ .prose {
64
+ font-size: 0.95rem;
65
+ }
66
+
67
+ .prose p {
68
+ margin-top: 1em;
69
+ margin-bottom: 1em;
70
+ }
71
+
72
+ .prose ul {
73
+ padding-left: 1.25em;
74
+ }
75
+
76
+ .prose li {
77
+ margin-top: 0.375em;
78
+ margin-bottom: 0.375em;
79
+ }
80
+
81
+ .prose h1, .prose h2, .prose h3 {
82
+ margin-top: 1.5em;
83
+ margin-bottom: 0.75em;
84
+ }
85
+ }
86
+
87
+ /* Styles pour améliorer la lisibilité du texte */
88
+ #response .prose {
89
+ color: #374151;
90
+ word-wrap: break-word;
91
+ overflow-wrap: break-word;
92
+ hyphens: auto;
93
+ }
94
+
95
+ #response .prose > * + * {
96
+ margin-top: 1em;
97
+ }
98
+
99
+ #response .prose blockquote {
100
+ margin: 1.5em 0;
101
+ padding-left: 1em;
102
+ border-left: 4px solid #e5e7eb;
103
+ font-style: italic;
104
+ }
105
+
106
+ #response .prose code {
107
+ background-color: #f3f4f6;
108
+ padding: 0.2em 0.4em;
109
+ border-radius: 0.25em;
110
+ font-size: 0.875em;
111
+ }
112
+
113
+
114
+ .active, .collapsible:hover {
115
+ background-color: #ddd;
116
+ }
117
+
118
+ .content {
119
+ padding: 0 18px;
120
+ display: none;
121
+ overflow: hidden;
122
+ background-color: white;
123
+ }
124
+ .animate-fadeIn {
125
+ animation: fadeIn 0.5s ease-out forwards;
126
+ }
127
+ .animate-slideUp {
128
+ animation: slideUp 0.5s ease-out forwards;
129
+ }
130
+ .animate-shake {
131
+ animation: shake 0.5s ease-in-out;
132
+ }
133
+ @keyframes fadeIn {
134
+ from { opacity: 0; transform: translateY(10px); }
135
+ to { opacity: 1; transform: translateY(0); }
136
+ }
137
+ @keyframes slideUp {
138
+ from { opacity: 0; transform: translateY(20px); }
139
+ to { opacity: 1; transform: translateY(0); }
140
+ }
141
+ @keyframes shake {
142
+ 0%, 100% { transform: translateX(0); }
143
+ 25% { transform: translateX(-5px); }
144
+ 75% { transform: translateX(5px); }
145
+ }
146
+
147
+ /* Ajout du style pour Select2 */
148
+ .select2-container--default .select2-selection--single {
149
+ border: 1px solid #e5e7eb;
150
+ border-radius: 0.75rem;
151
+ height: auto;
152
+ padding: 0.625rem 1rem;
153
+ background-color: white;
154
+ box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
155
+ display: flex;
156
+ align-items: center;
157
+ }
158
+ .select2-container--default .select2-selection--single .select2-selection__rendered {
159
+ color: #374151;
160
+ line-height: inherit;
161
+ padding-right: 1.5rem;
162
+ }
163
+
164
+ .select2-container--default .select2-selection--single .select2-selection__arrow {
165
+ top: 50%;
166
+ transform: translateY(-50%);
167
+ right: 0.75rem;
168
+ }
169
+
170
+ .select2-dropdown {
171
+ border: 1px solid #e5e7eb;
172
+ border-radius: 0.75rem;
173
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
174
+ padding: 0.25rem;
175
+ }
176
+ .select2-search--dropdown .select2-search__field {
177
+ border: 1px solid #e5e7eb;
178
+ border-radius: 0.375rem;
179
+ padding: 0.5rem;
180
+ }
181
+
182
+ .select2-results__options {
183
+ padding: 0.25rem;
184
+ }
185
+ .select2-results__option {
186
+ padding: 0.5rem 0.75rem;
187
+ }
188
+
189
+
190
+ .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable{
191
+ background-color: #ede9fe;
192
+ color:#374151;
193
+ }
194
+
195
+ .select2-container--default .select2-results__option--selected {
196
+ background-color: #f3f4f6;
197
+ color:#374151;
198
+ }
199
+ .select2-results__option .course-author {
200
+ font-size: 0.875rem;
201
+ color: #6b7280;
202
+ display: block;
203
+ margin-top: 0.25rem;
204
+ }
205
+ .select2-container--open .select2-selection--single .select2-selection__arrow {
206
+ border-color: transparent transparent #a8a29e;
207
+
208
+ }
209
+
210
+ </style>
211
+ </head>
212
+
213
+ <body class="bg-gradient-to-br from-violet-50 to-indigo-50 min-h-screen">
214
+ <!-- Navbar -->
215
+ <nav class="bg-white/80 backdrop-blur-md border-b border-gray-200 fixed w-full z-50">
216
+ <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
217
+ <div class="flex justify-between items-center h-16">
218
+ <div class="flex items-center">
219
+ <div class="text-2xl font-bold bg-gradient-to-r from-violet-600 to-indigo-600 text-transparent bg-clip-text">
220
+ Mariam AI
221
+ </div>
222
+ </div>
223
+ <div class="flex items-center space-x-4">
224
+ <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-violet-100 text-violet-800">
225
+ <span class="w-2 h-2 bg-violet-400 rounded-full animate-pulse mr-2"></span>
226
+ Assistant Philosophique
227
+ </span>
228
+ </div>
229
+ </div>
230
+ </div>
231
+ </nav>
232
+
233
+ <!-- Main Content -->
234
+ <div class="pt-24 pb-12 px-4 sm:px-6 lg:px-8">
235
+ <div class="max-w-4xl mx-auto">
236
+ <!-- Main Card -->
237
+ <div class="bg-white/80 backdrop-blur-md rounded-2xl shadow-xl border border-gray-100 overflow-hidden">
238
+ <!-- Header Section -->
239
+ <div class="bg-gradient-to-r from-violet-600 to-indigo-600 p-6 text-white">
240
+ <h2 class="text-2xl font-bold">Gen'Dissertation</h2>
241
+ <p class="mt-2 opacity-90">Créez des dissertations philosophiques pertinentes et structurées</p>
242
+ </div>
243
+
244
+ <!-- Content Section -->
245
+ <div class="p-8 space-y-8">
246
+ <!-- Type Selection -->
247
+ <div class="space-y-3">
248
+ <label class="block text-sm font-medium text-gray-700">Type de dissertation</label>
249
+ <div class="relative">
250
+ <select id="type-select" class="w-full rounded-xl border-gray-200 shadow-sm focus:border-violet-500 focus:ring-violet-500 appearance-none bg-white py-3 px-4 pr-10">
251
+ <option value="1">Type 1</option>
252
+ <option value="2">Type 2</option>
253
+ <option value="3">Synthèse</option>
254
+ </select>
255
+ <div class="absolute inset-y-0 right-0 flex items-center px-4 pointer-events-none">
256
+ <svg class="h-5 w-5 text-gray-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
257
+ <path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
258
+ </svg>
259
+ </div>
260
+ </div>
261
+ <div id="current-type-label" class="inline-flex px-4 py-2 rounded-xl text-sm font-medium bg-gradient-to-r from-violet-50 to-indigo-50 text-violet-700 border border-violet-200">
262
+ Sujet de type 1
263
+ </div>
264
+ </div>
265
+
266
+ <!-- Course Selection -->
267
+ <div class="space-y-3">
268
+ <label class="block text-sm font-medium text-gray-700">Sélection du cours</label>
269
+ <select id="course-select" class="w-full">
270
+ <option value="">Choisir un cours...</option>
271
+ </select>
272
+ <div class="course-meta hidden">
273
+ <div class="bg-gradient-to-r from-gray-50 to-white rounded-xl p-4 border border-gray-100">
274
+ <div class="flex justify-between items-center">
275
+ <span id="course-author" class="flex items-center space-x-2">
276
+ <svg class="h-5 w-5 text-violet-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
277
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
278
+ </svg>
279
+ <span class="text-gray-600"></span>
280
+ </span>
281
+ <span id="course-date" class="flex items-center space-x-2">
282
+ <svg class="h-5 w-5 text-violet-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
283
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
284
+ </svg>
285
+ <span class="text-gray-600"></span>
286
+ </span>
287
+ </div>
288
+ </div>
289
+ </div>
290
+ </div>
291
+
292
+
293
+ <!-- Question Input -->
294
+ <div class="space-y-3">
295
+ <label class="block text-sm font-medium text-gray-700">Sujet de dissertation</label>
296
+ <div class="relative">
297
+ <textarea id="question" rows="4"
298
+ class="w-full rounded-xl border-gray-200 shadow-sm focus:border-violet-500 focus:ring-violet-500 resize-none bg-white py-3 px-4"
299
+ placeholder="Saisissez votre sujet de dissertation..."></textarea>
300
+ <div class="absolute bottom-3 right-3 flex items-center space-x-2 text-gray-400">
301
+ <svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
302
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
303
+ </svg>
304
+ </div>
305
+ </div>
306
+ </div>
307
+
308
+ <!-- Submit Button -->
309
+ <button id="submit-btn" class="w-full py-4 px-6 rounded-xl bg-gradient-to-r from-violet-600 to-indigo-600 text-white font-medium shadow-lg shadow-violet-200 hover:shadow-xl hover:shadow-violet-300 transform hover:-translate-y-0.5 transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-violet-500 focus:ring-offset-2">
310
+ <span class="flex items-center justify-center space-x-2">
311
+ <svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
312
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
313
+ </svg>
314
+ <span>Générer la dissertation</span>
315
+ </span>
316
+ </button>
317
+
318
+ <!-- Response Section -->
319
+ <div id="response" class="hidden mt-8 prose prose-violet max-w-none">
320
+ <div class="bg-gradient-to-r from-gray-50 to-white rounded-xl p-6 border border-gray-100">
321
+ <!-- La réponse sera insérée ici -->
322
+ </div>
323
+ </div>
324
+
325
+ <!-- Copy Button -->
326
+ <button id="copy-btn" class="hidden w-full py-3 px-6 rounded-xl bg-gray-50 text-gray-700 font-medium border border-gray-200 hover:bg-gray-100 transform hover:-translate-y-0.5 transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2">
327
+ <span class="flex items-center justify-center space-x-2">
328
+ <svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
329
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
330
+ </svg>
331
+ <span>Copier la dissertation</span>
332
+ </span>
333
+ </button>
334
+
335
+ <!-- Saved Dissertations Section -->
336
+ <div id="saved-dissertations" class="mt-8">
337
+ <h3 class="text-lg font-medium text-gray-700 mb-4">Dissertations Sauvegardées</h3>
338
+ <div id="dissertations-list" class="space-y-4">
339
+ <!-- Les dissertations sauvegardées seront insérées ici -->
340
+ </div>
341
+ </div>
342
+
343
+ </div>
344
+ </div>
345
+ </div>
346
+ </div>
347
+
348
+ <script>
349
+ $(document).ready(function() {
350
+ // Initialisation de Select2
351
+ $('#course-select').select2({
352
+ placeholder: 'Choisir un cours...',
353
+ templateResult: function (course) {
354
+ if (!course.id) {
355
+ return course.text;
356
+ }
357
+ const author = $(course.element).data('author'); // Récupérer l'auteur
358
+ return $(`
359
+ <span>${course.text}</span>
360
+ <span class="course-author">Pr. ${author}</span>
361
+ `);
362
+ },
363
+ templateSelection: function (course) {
364
+ return course.text; // Seul le titre est affiché dans la sélection
365
+ },
366
+
367
+ });
368
+ // Configuration de marked
369
+ marked.setOptions({
370
+ breaks: true,
371
+ gfm: true,
372
+ headerIds: true,
373
+ langPrefix: 'language-',
374
+ smartLists: true,
375
+ smartypants: true
376
+ });
377
+
378
+ moment.locale('fr'); // Configuration de moment.js en français
379
+
380
+ // Configuration des notifications
381
+ const Toast = Swal.mixin({
382
+ toast: true,
383
+ position: 'top-end',
384
+ showConfirmButton: false,
385
+ timer: 3000,
386
+ timerProgressBar: true,
387
+ customClass: {
388
+ popup: 'rounded-lg shadow-xl border border-gray-100'
389
+ }
390
+ });
391
+
392
+
393
+
394
+ // Animation des boutons
395
+ function addButtonAnimation(buttonId) {
396
+ $(`#${buttonId}`).on('mousedown', function() {
397
+ $(this).addClass('scale-95');
398
+ }).on('mouseup mouseleave', function() {
399
+ $(this).removeClass('scale-95');
400
+ });
401
+ }
402
+ addButtonAnimation('submit-btn');
403
+ addButtonAnimation('copy-btn');
404
+
405
+ // Gestion du changement de type
406
+ $('#type-select').change(function() {
407
+ const selectedOption = $(this).find('option:selected');
408
+ const typeLabel = selectedOption.text(); // Utiliser le texte de l'option sélectionnée
409
+ const type = $(this).val();
410
+
411
+
412
+ $('#current-type-label').text(`Type ${type} - ${typeLabel}`);
413
+ });
414
+
415
+
416
+ // Chargement des cours avec animation
417
+ function loadCourses() {
418
+ return $.ajax({
419
+ url: '/api/philosophy/courses',
420
+ method: 'GET',
421
+ beforeSend: function() {
422
+ $('#course-select').prop('disabled', true).addClass('animate-pulse');
423
+
424
+ },
425
+ complete: function() {
426
+ $('#course-select').prop('disabled', false).removeClass('animate-pulse');
427
+
428
+ }
429
+ });
430
+ }
431
+
432
+ loadCourses()
433
+ .done(function(courses) {
434
+ const select = $('#course-select');
435
+ courses.forEach(course => {
436
+ // Créer une nouvelle option avec l'auteur déjà inclus
437
+ const newOption = new Option(course.title, course.id, false, false);
438
+ $(newOption).data('author', course.author); // Ajouter l'auteur comme data
439
+ select.append(newOption);
440
+ });
441
+ })
442
+
443
+ .fail(function() {
444
+ Toast.fire({
445
+ icon: 'error',
446
+ title: 'Erreur de chargement des cours',
447
+ text: 'Veuillez réessayer ultérieurement'
448
+ });
449
+ });
450
+
451
+ // Gestion du changement de cours avec animations
452
+ $('#course-select').on('change', function() {
453
+ const courseId = $(this).val();
454
+
455
+ if (courseId) {
456
+ $.ajax({
457
+ url: `/api/philosophy/courses/${courseId}`,
458
+ method: 'GET',
459
+ beforeSend: function() {
460
+ $('.course-meta').addClass('animate-pulse');
461
+ },
462
+ success: function(course) {
463
+ $('.course-meta').removeClass('hidden animate-pulse')
464
+ .addClass('animate-fadeIn');
465
+ $('#course-author span').text(`Pr. ${course.author}`);
466
+ $('#course-date span').text(new Date(course.updated_at).toLocaleDateString('fr-FR', {
467
+ day: 'numeric',
468
+ month: 'long',
469
+ year: 'numeric' }));
470
+
471
+ // Afficher une notification de succès
472
+ Toast.fire({
473
+ icon: 'success',
474
+ title: 'Cours chargé avec succès'
475
+ });
476
+ },
477
+ error: function() {
478
+ Toast.fire({
479
+ icon: 'error',
480
+ title: 'Erreur',
481
+ text: 'Impossible de charger les détails du cours'
482
+ });
483
+ }
484
+ });
485
+ } else {
486
+ $('.course-meta').addClass('animate-fadeOut').on('animationend', function() {
487
+ $(this).addClass('hidden').removeClass('animate-fadeOut');
488
+ });
489
+ }
490
+
491
+ });
492
+
493
+ // Gestion de la soumission avec conversion en Markdown et sauvegarde
494
+ $('#submit-btn').click(function() {
495
+ const question = $('#question').val().trim();
496
+
497
+ if (!question) {
498
+ // Gestion de l'erreur si la question est vide (inchangée)
499
+ return;
500
+ }
501
+
502
+ // Animation de chargement sophistiquée
503
+ Swal.fire({
504
+ title: 'Génération en cours',
505
+ html: `
506
+ <div class="space-y-4">
507
+ <div class="flex justify-center">
508
+ <div class="w-16 h-16 relative">
509
+ <div class="absolute inset-0 rounded-full border-4 border-violet-200 animate-ping"></div>
510
+ <div class="absolute inset-0 rounded-full border-4 border-violet-500 animate-pulse"></div>
511
+ </div>
512
+ </div>
513
+ <div class="text-gray-600">
514
+ <p class="animate-pulse">Analyse philosophique en cours...</p>
515
+ <p class="text-sm mt-2 text-gray-500">Veuillez patienter quelques instants</p>
516
+ </div>
517
+ </div>
518
+ `,
519
+ allowOutsideClick: false,
520
+ showConfirmButton: false,
521
+ customClass: {
522
+ popup: 'rounded-2xl'
523
+ }
524
+ });
525
+
526
+ const data = {
527
+ question: question,
528
+ type: $('#type-select').val(),
529
+ courseId: $('#course-select').val() || null
530
+ };
531
+
532
+ $.ajax({
533
+ url: '/submit_philo',
534
+ method: 'POST',
535
+ contentType: 'application/json',
536
+ data: JSON.stringify(data),
537
+ success: function(data) {
538
+ Swal.close();
539
+
540
+ const htmlContent = marked.parse(data.response);
541
+ // Afficher la dissertation
542
+ $('#response > div').html(htmlContent);
543
+ $('#response').removeClass('hidden').addClass('animate-fadeIn');
544
+ $('#copy-btn').removeClass('hidden').addClass('animate-slideUp');
545
+
546
+ // Sauvegarder la dissertation
547
+ saveDissertation(question, data.response);
548
+
549
+ Toast.fire({
550
+ icon: 'success',
551
+ title: 'Dissertation générée et sauvegardée avec succès',
552
+ timer: 2000
553
+ });
554
+ },
555
+ error: function() {
556
+ Swal.fire({
557
+ icon: 'error',
558
+ title: 'Erreur de génération',
559
+ text: 'Une erreur est survenue lors de la génération de votre dissertation.',
560
+ customClass: {
561
+ popup: 'rounded-2xl',
562
+ confirmButton: 'bg-violet-600 hover:bg-violet-700 text-white font-medium py-2 px-4 rounded-lg transition-colors duration-200'
563
+ }
564
+ });
565
+ }
566
+ });
567
+ });
568
+
569
+
570
+ function saveDissertation(title, content) {
571
+ let savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];
572
+ savedDissertations.push({ title, content, timestamp: Date.now() });
573
+ localStorage.setItem('dissertations', JSON.stringify(savedDissertations));
574
+ updateSavedDissertationsList();
575
+
576
+ }
577
+
578
+ function deleteDissertation(index) {
579
+ let savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];
580
+ savedDissertations.splice(index, 1);
581
+ localStorage.setItem('dissertations', JSON.stringify(savedDissertations));
582
+ updateSavedDissertationsList();
583
+ Toast.fire({
584
+ icon: 'success',
585
+ title: 'Dissertation supprimée avec succès'
586
+ });
587
+
588
+ }
589
+
590
+ // Fonction pour afficher les dissertations sauvegardées (avec sections repliables et suppression)
591
+ function updateSavedDissertationsList() {
592
+ const dissertationsList = $('#dissertations-list');
593
+ dissertationsList.empty(); // Vider la liste actuelle
594
+
595
+ let savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];
596
+
597
+ if (savedDissertations.length === 0) {
598
+ dissertationsList.append('<p class="text-gray-500">Aucune dissertation sauvegardée.</p>');
599
+ return;
600
+ }
601
+
602
+
603
+
604
+ savedDissertations.forEach((diss, index) => {
605
+ const date = moment(diss.timestamp).format('LLL');
606
+
607
+ const collapsible = $(`<button class="collapsible rounded-xl border border-gray-100 flex justify-between w-full"><span>${diss.title}</span><span class="text-gray-500 text-sm">${date}</span></button>`);
608
+ const deleteButton = $('<button class="text-red-500 hover:text-red-700 ml-2">Supprimer</button>');
609
+ const content = $('<div class="content prose prose-violet max-w-none p-4"></div>').html(marked.parse(diss.content)); // Convertir en HTML
610
+
611
+ collapsible.append(deleteButton); // Ajouter le bouton supprimer
612
+ dissertationsList.append(collapsible, content);
613
+
614
+ // Gestionnaire d'événement pour chaque section repliable
615
+ collapsible.click(function(event) {
616
+ // Empêcher la propagation de l'événement click sur le bouton "Supprimer"
617
+ if (event.target === deleteButton[0]) {
618
+ return;
619
+ }
620
+
621
+ content.slideToggle("fast");
622
+ collapsible.toggleClass("active");
623
+ });
624
+
625
+ deleteButton.click(function() {
626
+ // Supprimer la dissertation correspondante
627
+ deleteDissertation(index);
628
+
629
+ });
630
+ });
631
+ }
632
+
633
+ // Appeler la fonction pour afficher les dissertations au chargement de la page
634
+ updateSavedDissertationsList();
635
+
636
+ // Nouvelle gestion de la copie
637
+ $('#copy-btn').click(function() {
638
+ // Sélectionner le contenu de la réponse en utilisant innerHTML pour obtenir le HTML formaté
639
+ const responseDiv = document.querySelector('#response > div');
640
+ let textToCopy = '';
641
+
642
+ // Créer un élément temporaire pour convertir le HTML en texte brut tout en préservant le formatage
643
+ const temp = document.createElement('div');
644
+ temp.innerHTML = responseDiv.innerHTML;
645
+
646
+ // Fonction récursive pour extraire le texte en préservant les sauts de ligne
647
+ function extractText(node) {
648
+ let text = '';
649
+ node.childNodes.forEach(child => {
650
+ if (child.nodeType === 3) { // Nœud texte
651
+ text += child.textContent;
652
+ } else if (child.nodeType === 1) { // Élément
653
+ // Ajouter des sauts de ligne pour les éléments de bloc
654
+ if (window.getComputedStyle(child).display === 'block') {
655
+ text += '\n';
656
+ }
657
+ text += extractText(child);
658
+ if (window.getComputedStyle(child).display === 'block') {
659
+ text += '\n';
660
+ }
661
+ }
662
+ });
663
+ return text;
664
+ }
665
+
666
+ textToCopy = extractText(temp).trim();
667
+
668
+ // Animation et copie
669
+ $(this).addClass('scale-95 bg-violet-100');
670
+
671
+ // Utiliser l'API Clipboard avec gestion des erreurs
672
+ navigator.clipboard.writeText(textToCopy)
673
+ .then(() => {
674
+ $(this).removeClass('scale-95 bg-violet-100')
675
+ .addClass('bg-green-50 text-green-700');
676
+
677
+ setTimeout(() => {
678
+ $(this).removeClass('bg-green-50 text-green-700');
679
+ }, 1000);
680
+
681
+ Toast.fire({
682
+ icon: 'success',
683
+ title: 'Copié avec succès',
684
+ text: 'Le contenu a été copié dans votre presse-papiers',
685
+ timer: 2000
686
+ });
687
+ })
688
+ .catch((err) => {
689
+ // Fallback pour les appareils mobiles qui ne supportent pas l'API Clipboard
690
+ try {
691
+ // Créer un élément textarea temporaire
692
+ const textarea = document.createElement('textarea');
693
+ textarea.value = textToCopy;
694
+ textarea.style.position = 'fixed'; // Évite le défilement
695
+ textarea.style.opacity = '0';
696
+ document.body.appendChild(textarea);
697
+
698
+ // Sélectionner et copier le texte
699
+ textarea.select();
700
+ document.execCommand('copy');
701
+
702
+ // Nettoyer
703
+ document.body.removeChild(textarea);
704
+
705
+ // Feedback positif
706
+ $(this).removeClass('scale-95 bg-violet-100')
707
+ .addClass('bg-green-50 text-green-700');
708
+
709
+ setTimeout(() => {
710
+ $(this).removeClass('bg-green-50 text-green-700');
711
+ }, 1000);
712
+
713
+ Toast.fire({
714
+ icon: 'success',
715
+ title: 'Copié avec succès',
716
+ timer: 2000
717
+ });
718
+ } catch (fallbackErr) {
719
+ // Si même le fallback échoue
720
+ $(this).removeClass('scale-95 bg-violet-100')
721
+ .addClass('bg-red-50 text-red-700');
722
+
723
+ setTimeout(() => {
724
+ $(this).removeClass('bg-red-50 text-red-700');
725
+ }, 1000);
726
+
727
+ Toast.fire({
728
+ icon: 'error',
729
+ title: 'Erreur de copie',
730
+ text: 'Impossible de copier le contenu',
731
+ timer: 3000
732
+ });
733
+ }
734
+ });
735
+ });
736
+
737
+ // Ajout des styles d'animation personnalisés
738
+ const style = document.createElement('style');
739
+ style.textContent = `
740
+ @keyframes fadeIn {
741
+ from { opacity: 0; transform: translateY(10);} to { opacity: 1; transform: translateY(0); }
742
+ }
743
+ @keyframes slideUp {
744
+ from { opacity: 0; transform: translateY(20px); }
745
+ to { opacity: 1; transform: translateY(0); }
746
+ }
747
+ @keyframes shake {
748
+ 0%, 100% { transform: translateX(0); }
749
+ 25% { transform: translateX(-5px); }
750
+ 75% { transform: translateX(5px); }
751
+ }
752
+ .animate-fadeIn {
753
+ animation: fadeIn 0.5s ease-out forwards;
754
+ }
755
+ .animate-slideUp {
756
+ animation: slideUp 0.5s ease-out forwards;
757
+ }
758
+ .animate-shake {
759
+ animation: shake 0.5s ease-in-out;
760
+ }
761
+ `;
762
+ document.head.appendChild(style);
763
+
764
+ // Met à jour le label initial avec la valeur par défaut du select
765
+ const initialSelectValue = $('#type-select').val();
766
+ const initialSelectedText = $('#type-select option:selected').text();
767
+ $('#current-type-label').text(`Type ${initialSelectValue} - ${initialSelectedText}`);
768
+ });
769
+ </script>
770
+
771
+ </body>
772
+ </html>