PageSourceSearch

https://www.commune-beinheim.fr/assets/js/utils/alerte-utils-e7b2840a0c6385f62c9e3379c884a32b.js

js commune-beinheim.fr collected 2026-10-02 21:32:33 UTC 10,424 bytes, 259 lines download raw bytes

1// Function to display or hide the end validity date input
2import moment from "moment";
3export function afficheFinValidite() {
4    const checkbox = document.getElementById('checkboxFinValidite');
5    const input = document.querySelector('input[name="qsmart_illiwapbundle_alerte[finValidite]"]');
6
7    if (checkbox && input) {
8        if (checkbox.checked) {
9            input.parentElement.classList.remove('d-none');
10        } else {
11            input.parentElement.classList.add('d-none');
12            input.value = '';
13        }
14    }
15}
16
17// Function to display or hide the planning date input
18export function afficheDatePlanification() {
19    const checkbox = document.getElementById('checkboxDatePlanification');
20    const input = document.querySelector('input[name="qsmart_illiwapbundle_alerte[datePlanification]"]');
21
22    if (checkbox && input) {
23        if (checkbox.checked) {
24            input.parentElement.classList.remove('d-none');
25            input.setAttribute('required', 'required');
26        } else {
27            input.parentElement.classList.add('d-none');
28            input.value = '';
29            input.removeAttribute('required');
30        }
31    }
32}
33
34// Function to display or hide the planning suppression date input
35export function afficheDatePlanificationSuppression() {
36    const checkbox = document.getElementById('checkboxDatePlanificationSuppression');
37    const input = document.querySelector('input[name="qsmart_illiwapbundle_alerte[datePlanificationSuppression]"]');
38
39    if (checkbox && input) {
40        if (checkbox.checked) {
41            input.parentElement.classList.remove('d-none');
42            input.setAttribute('required', 'required');
43        } else {
44            input.parentElement.classList.add('d-none');
45            input.value = '';
46            input.removeAttribute('required');
47        }
48    }
49}
50
51// Function to validate that the deletion date is after the planning date
52export function validateDatePlanificationSuppression() {
53    const datePlanificationInput = document.querySelector('input[name="qsmart_illiwapbundle_alerte[datePlanification]"]');
54    const dateSuppressionInput = document.querySelector('input[name="qsmart_illiwapbundle_alerte[datePlanificationSuppression]"]');
55    const checkboxPlanification = document.getElementById('checkboxDatePlanification');
56    const checkboxSuppression = document.getElementById('checkboxDatePlanificationSuppression');
57
58    // Only validate if both checkboxes are checked and both inputs have values
59    if (!checkboxPlanification?.checked || !checkboxSuppression?.checked) {
60        // Clear any previous error
61        clearDateSuppressionError(dateSuppressionInput);
62        return true;
63    }
64
65    if (!datePlanificationInput?.value || !dateSuppressionInput?.value) {
66        return true;
67    }
68
69    const datePlanification = parseFrenchDateTime(datePlanificationInput.value);
70    const dateSuppression = parseFrenchDateTime(dateSuppressionInput.value);
71
72    // Check if deletion date is before planning date
73    if (dateSuppression < datePlanification) {
74        showDateSuppressionError(dateSuppressionInput);
75        return false;
76    } else {
77        clearDateSuppressionError(dateSuppressionInput);
78        return true;
79    }
80}
81
82function parseFrenchDateTime(value) {
83    return moment(value, "DD/MM/YYYY HH:mm", true).toDate();
84}
85
86// Function to show error message for deletion date
87function showDateSuppressionError(input) {
88    if (!input) return;
89
90    // Remove any existing error
91    clearDateSuppressionError(input);
92
93    // Add error class to input
94    input.classList.add('is-invalid');
95
96    // Create error message element
97    const errorDiv = document.createElement('div');
98    errorDiv.className = 'invalid-feedback d-block';
99    errorDiv.id = 'date-suppression-error';
100    errorDiv.textContent = input.getAttribute('data-error-message') || 
101        'La date de suppression doit être postérieure à la date de planification.';
102
103    // Insert error message after the input's parent
104    input.parentElement.appendChild(errorDiv);
105}
106
107// Function to clear error message for deletion date
108function clearDateSuppressionError(input) {
109    if (!input) return;
110
111    input.classList.remove('is-invalid');
112    const existingError = document.getElementById('date-suppression-error');
113    if (existingError) {
114        existingError.remove();
115    }
116}
117
118// Function to display or hide the recurrence fields
119export function afficheRecurrence() {
120    const checkbox = document.getElementById('checkboxRecurrence');
121    const formRecurrence = document.querySelector('.form-recurrence');
122
123    if (checkbox && formRecurrence) {
124        if (checkbox.checked) {
125            formRecurrence.classList.remove('d-none');
126            if (document.querySelector('[name="qsmart_illiwapbundle_alerte[recurrence][repetition]"]').value === '') {
127                document.querySelector('[name="qsmart_illiwapbundle_alerte[recurrence][repetition]"]').value = '1';
128                document.querySelector('[name="qsmart_illiwapbundle_alerte[recurrence][type]"]').value = 'semaine';
129            }
130            afficheRecurrenceSemaineMois();
131            afficheOccurrences();
132        } else {
133            formRecurrence.classList.add('d-none');
134            document.querySelector('[name="qsmart_illiwapbundle_alerte[recurrence][repetition]"]').value = '';
135            document.querySelector('[name="qsmart_illiwapbundle_alerte[recurrence][type]"]').value = '';
136            document.getElementById('qsmart_illiwapbundle_alerte_recurrence_jours').value = '';
137            document.querySelector('[name="qsmart_illiwapbundle_alerte[recurrence][mois]"]').value = '';
138            document.querySelector('[name="qsmart_illiwapbundle_alerte[recurrence][occurrences]"]').value = '';
139            document.querySelector('[name="qsmart_illiwapbundle_alerte[recurrence][dateFin]"]').value = '';
140        }
141    }
142}
143
144// Function to display or hide the number of occurrences input
145export function afficheOccurrences() {
146    const occurrenceInput = document.getElementById('qsmart_illiwapbundle_alerte_recurrence_occurrences');
147    const dateFinInput = document.getElementById('qsmart_illiwapbundle_alerte_recurrence_dateFin');
148
149    if (occurrenceInput && dateFinInput) {
150        if (occurrenceInput.value > 0) {
151            afficheNombreOccurrences();
152            masqueDateOccurrences();
153            document.getElementById('termine_fin_occurence').checked = true;
154        } else {
155            masqueNombreOccurrences();
156        }
157
158        if (dateFinInput.value !== '') {
159            afficheDateOccurrences();
160            masqueNombreOccurrences();
161            document.getElementById('termine_fin_date').checked = true;
162        } else {
163            masqueDateOccurrences();
164        }
165
166        document.querySelectorAll('[name="termine"]').forEach(input => {
167            input.addEventListener('change', function() {
168                switch (this.value) {
169                    case 'jamais':
170                        masqueNombreOccurrences();
171                        masqueDateOccurrences();
172                        break;
173                    case 'fin_date':
174                        masqueNombreOccurrences();
175                        afficheDateOccurrences();
176                        break;
177                    case 'fin_occurence':
178                        afficheNombreOccurrences();
179                        masqueDateOccurrences();
180                        break;
181                }
182            });
183        });
184    }
185}
186
187// Function to disable the number of occurrences input
188export function masqueNombreOccurrences() {
189    const occurrenceInput = document.getElementById('qsmart_illiwapbundle_alerte_recurrence_occurrences');
190    if (occurrenceInput) {
191        occurrenceInput.disabled = true;
192        occurrenceInput.value = '';
193    }
194}
195
196// Function to enable the recurrence end date input
197export function afficheDateOccurrences() {
198    const dateInput = document.getElementById('qsmart_illiwapbundle_alerte_recurrence_dateFin');
199    if (dateInput) {
200        dateInput.disabled = false;
201        if (dateInput.value === '') {
202            dateInput.value = dateInput.getAttribute('placeholder');
203        }
204    }
205}
206
207// Function to disable the recurrence end date input
208export function masqueDateOccurrences() {
209    const dateInput = document.getElementById('qsmart_illiwapbundle_alerte_recurrence_dateFin');
210    if (dateInput) {
211        dateInput.disabled = true;
212        dateInput.value = '';
213    }
214}
215
216// Function to enable the number of occurrences input
217export function afficheNombreOccurrences() {
218    const occurrenceInput = document.getElementById('qsmart_illiwapbundle_alerte_recurrence_occurrences');
219    if (occurrenceInput) {
220        occurrenceInput.disabled = false;
221        if (occurrenceInput.value === '') {
222            occurrenceInput.value = 10;
223        }
224    }
225}
226
227
228// Function to display or hide the weekly and monthly recurrence fields
229export function afficheRecurrenceSemaineMois() {
230    const recurrenceType = document.querySelector('[name="qsmart_illiwapbundle_alerte[recurrence][type]"]');
231    const recurrenceJours = document.getElementById('qsmart_illiwapbundle_alerte_recurrence_jours');
232    const recurrenceMois = document.querySelector('[name="qsmart_illiwapbundle_alerte[recurrence][mois]"]');
233
234    console.log(recurrenceType.value, recurrenceJours, recurrenceMois);
235    if (recurrenceType && recurrenceJours && recurrenceMois) {
236        if (recurrenceType.value === "semaine") {
237            recurrenceJours.parentElement.classList.remove('d-none');
238            const joursSelectionnes = Array.from(document.querySelectorAll('[name="qsmart_illiwapbundle_alerte[recurrence][jours][]"]:checked'))
239                .map(c => c.value);
240
241            if (joursSelectionnes.length === 0) {
242                let jourSemaine = new Date().getDay() - 1;
243                if (jourSemaine < 0) jourSemaine = 6;
244                document.getElementById(`qsmart_illiwapbundle_alerte_recurrence_jours_${jourSemaine}`).checked = true;
245            }
246        } else {
247            recurrenceJours.parentElement.classList.add('d-none');
248        }
249
250        if (recurrenceType.value === "mois") {
251            recurrenceMois.parentElement.classList.remove('d-none');
252            if (!recurrenceMois.value) {
253                recurrenceMois.value = 0;
254            }
255        } else {
256            recurrenceMois.parentElement.classList.add('d-none');
257        }
258    }
259}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.