summaryrefslogtreecommitdiff
path: root/public/js/CalendarModalView.js
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2026-01-29 22:51:19 +0100
committerpolo <ordipolo@gmx.fr>2026-01-29 22:51:19 +0100
commite3a42c8342bba0db15e2ca9a78911121e5d539da (patch)
treedf2b669452ba82774d741a4b9e48948b8dc45a0a /public/js/CalendarModalView.js
parentf007bac3b9172711dc0fcca1306270ab99dbd8a4 (diff)
downloadfullcalendar-e3a42c8342bba0db15e2ca9a78911121e5d539da.tar.gz
fullcalendar-e3a42c8342bba0db15e2ca9a78911121e5d539da.tar.bz2
fullcalendar-e3a42c8342bba0db15e2ca9a78911121e5d539da.zip
classe CalendarModalView, contrôles getElementOrThrow et assertElementTypeHEADmaster
Diffstat (limited to 'public/js/CalendarModalView.js')
-rw-r--r--public/js/CalendarModalView.js120
1 files changed, 120 insertions, 0 deletions
diff --git a/public/js/CalendarModalView.js b/public/js/CalendarModalView.js
new file mode 100644
index 0000000..a7afba9
--- /dev/null
+++ b/public/js/CalendarModalView.js
@@ -0,0 +1,120 @@
1// js/CalendarModalView.js
2
3class CalendarModalView {
4 constructor(data) {
5 this.modal = '';
6 if (data.mode !== 'show' && data.mode !== 'new' && data.mode !== 'edit') {
7 throw new Error("unknown mode in CalendarModal's constructor");
8 }
9 this.data = data;
10 }
11 getView() {
12 switch (this.data.mode) {
13 case 'show':
14 this.makeShowView();
15 break;
16 case 'new':
17 case 'edit':
18 this.makeEditView();
19 break;
20 default:
21 throw new Error("unknown mode set in CalendarModal");
22 }
23 return this.modal;
24 }
25 makeShowView() {
26 if (this.data.mode !== 'show') {
27 throw new Error('');
28 }
29 if (this.data.all_day) {
30 this.data.end.setDate(this.data.end.getDate() - 1); // jour de fin modifié pour ne pas faire bizarre pour l'utilisateur
31 }
32 this.modal += `<div id="event" style="border-color: ` + this.escapeHtml(this.data.color) + `;">
33 <h3>` + this.escapeHtml(this.data.title) + `</h3>
34 <p><i>` + this.escapeHtml(this.data.description) + `</i></p>`;
35 // allDay un jour
36 if (this.data.all_day && (this.data.start.getTime() === this.data.end.getTime())) { // comparaison des timestamps
37 this.modal += `<p>le ` + this.escapeHtml(this.displayDate(this.data.start)) + `</p>`; // affichage simplifié évènement d'un jour
38 }
39 // allDay plusieurs jours
40 else if (this.data.all_day) {
41 this.modal += `<p>du ` + this.escapeHtml(this.displayDate(this.data.start)) + `<br>
42 au ` + this.escapeHtml(this.displayDate(this.data.end)) + `</p>`;
43 }
44 // non allDay
45 else {
46 this.modal += `<p>du ` + this.escapeHtml(this.displayDate(this.data.start)) + `<br>
47 à ` + this.escapeHtml(this.displayHour(this.data.start)) + `</p>
48 <p>au ` + this.escapeHtml(this.displayDate(this.data.end)) + `<br>
49 à ` + this.escapeHtml(this.displayHour(this.data.end)) + `</p>`;
50 }
51 this.modal += `<button class="event_close_button">Fermer</button>
52 </div>`;
53 }
54 displayDate(date) {
55 return date.getDate().toString().padStart(2, '0') + '/' + (date.getMonth() + 1).toString().padStart(2, '0') + '/' + date.getFullYear();
56 }
57 displayHour(date) {
58 return date.getHours().toString().padStart(2, '0') + 'h' + date.getMinutes().toString().padStart(2, '0');
59 }
60 makeEditView() {
61 if (this.data.mode === 'show') {
62 throw new Error('');
63 }
64 if (this.data.all_day) {
65 this.data.end.setDate(this.data.end.getDate() - 1); // jour de fin modifié pour ne pas faire bizarre pour l'utilisateur
66 }
67 const title = this.data.mode === 'edit' ? this.data.title : '';
68 const id = this.data.mode === 'edit' ? this.data.id : '';
69 const description = this.data.mode === 'edit' ? this.data.description : '';
70 const color = this.data.mode === 'edit' ? this.data.color : '#3788D8'; // bleu par défaut
71 this.modal += `<div id="event" style="border-color: ` + this.escapeHtml(color) + `;">
72 <div class="event_title_box">
73 <h2>` + (this.data.mode === 'edit' ? "Modifier un" : "Nouvel") + ` évènement</h2>
74 </div>
75 <div class="">
76 <label for="event_title">Nom</label>
77 <input type="text" id="event_title" value="` + this.escapeHtml(title !== null && title !== void 0 ? title : '') + `">
78 <input type="hidden" id="event_id" value="` + this.escapeHtml(id !== null && id !== void 0 ? id : '') + `">
79 </div>
80 <div class="">
81 <label for="event_description">Description</label>
82 <textarea id="event_description" cols="27">` + this.escapeHtml(description !== null && description !== void 0 ? description : '') + `</textarea>
83 </div>
84 <div class="">
85 <input type="checkbox" id="event_all_day" class="event_all_day" ` + (this.data.all_day ? 'checked' : '') + `>
86 <label for="event_all_day">Journée entière</label>
87 </div>
88 <div class="">
89 <label for="event_start">Début</label>
90 <input type="` + this.escapeHtml(this.data.input_type) + `" id="event_start" value="` + this.escapeHtml(this.makeInputValue(this.data.start)) + `">
91 </div>
92 <div class="">
93 <label for="event_end">Fin</label>
94 <input type="` + this.escapeHtml(this.data.input_type) + `" id="event_end" value="` + this.escapeHtml(this.makeInputValue(this.data.end)) + `">
95 </div>
96 <div class="">
97 <label for="event_color">Couleur</label>
98 <input type="color" id="event_color" value="` + this.escapeHtml(color) + `">
99 </div>`
100 + (this.data.mode === 'edit'
101 ? '<button class="submit_update_event">Modifier</button><button class="delete_event">Supprimer</button>'
102 : '<button class="submit_new_event">Enregistrer</button>')
103 + `<button class="event_close_button">Annuler</button>
104 </div>`;
105 }
106 makeInputValue(date) {
107 return date.getFullYear() + '-' + (date.getMonth() + 1).toString().padStart(2, '0') + '-' + date.getDate().toString().padStart(2, '0')
108 + (this.data.all_day ? '' : 'T' + date.getHours().toString().padStart(2, '0') + ':' + date.getMinutes().toString().padStart(2, '0'));
109 }
110 escapeHtml(html) {
111 if (html === null || html === undefined)
112 return '';
113 return String(html)
114 .replace(/&/g, "&amp;") // & en premier
115 .replace(/</g, "&lt;")
116 .replace(/>/g, "&gt;")
117 .replace(/"/g, "&quot;")
118 .replace(/'/g, "&#039;");
119 }
120}