From 194986f880daf3efe5809c7d1ce0dbcc50224735 Mon Sep 17 00:00:00 2001 From: Youssef Date: Mon, 29 Jun 2026 09:28:38 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20pr=C3=A9-s=C3=A9lection=20de=20la=20cat?= =?UTF-8?q?=C3=A9gorie=20par=20=C3=A2ge=20et=20sexe=20lors=20de=20la=20cr?= =?UTF-8?q?=C3=A9ation=20d'une=20licence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/templates/adherents/form.html | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/as-talange-web/src/main/resources/templates/adherents/form.html b/as-talange-web/src/main/resources/templates/adherents/form.html index 241ae82..98d63e1 100644 --- a/as-talange-web/src/main/resources/templates/adherents/form.html +++ b/as-talange-web/src/main/resources/templates/adherents/form.html @@ -431,6 +431,7 @@ th:data-nom="${cat.nom}" th:data-annee-min="${cat.anneeMin}" th:data-annee-max="${cat.anneeMax}" + th:data-sexe="${cat.sexe}" th:data-tarif-base="${cat.tarifBase}" th:data-tarif-exterieur="${cat.tarifExterieur}" th:text="${cat.nom} + ' (Talange: ' + ${cat.tarifBase} + ' € / Ext: ' + ${cat.tarifExterieur} + ' €)'"> @@ -604,25 +605,41 @@ document.getElementById('typeLicenceSelect').value = ''; - // Pré-sélection de la catégorie selon l'année de naissance + // Pré-sélection de la catégorie selon l'année de naissance et le sexe const dateNaissanceStr = document.getElementById('dateNaissance').value; + const adherentSexe = document.getElementById('sexe') ? document.getElementById('sexe').value : 'MASCULIN'; let foundCat = false; + let fallbackCatId = ''; let preSelectedCatId = ''; if (dateNaissanceStr) { const birthYear = new Date(dateNaissanceStr).getFullYear(); Array.from(catSelect.options).forEach(opt => { + if (!opt.value) return; const min = parseInt(opt.getAttribute('data-annee-min')); const max = parseInt(opt.getAttribute('data-annee-max')); + const catSexe = opt.getAttribute('data-sexe') || 'MASCULIN'; + if (!isNaN(min) && !isNaN(max) && birthYear >= min && birthYear <= max) { - catSelect.value = opt.value; - preSelectedCatId = opt.value; - foundCat = true; + if (catSexe === adherentSexe) { + catSelect.value = opt.value; + preSelectedCatId = opt.value; + foundCat = true; + } + if (catSexe === 'MASCULIN') { + fallbackCatId = opt.value; + } } }); } + if (!foundCat && fallbackCatId) { + catSelect.value = fallbackCatId; + preSelectedCatId = fallbackCatId; + foundCat = true; + } + if (!foundCat) { catSelect.value = ''; } @@ -730,6 +747,7 @@ const dob = new Date(dateInput.value); const birthYear = dob.getFullYear(); const isResident = residentCheckbox ? residentCheckbox.checked : true; + const adherentSexe = document.getElementById('sexe') ? document.getElementById('sexe').value : 'MASCULIN'; const categories = []; const catSelect = document.getElementById('categorieSelect'); @@ -739,17 +757,21 @@ const nom = opt.getAttribute('data-nom'); const min = parseInt(opt.getAttribute('data-annee-min')); const max = parseInt(opt.getAttribute('data-annee-max')); + const sexe = opt.getAttribute('data-sexe') || 'MASCULIN'; const tarifBase = parseFloat(opt.getAttribute('data-tarif-base') || '0'); const tarifExterieur = parseFloat(opt.getAttribute('data-tarif-exterieur') || '0'); if (id) { - categories.push({ id, nom, min, max, tarifBase, tarifExterieur }); + categories.push({ id, nom, min, max, sexe, tarifBase, tarifExterieur }); } }); } if (categories.length === 0) return; - const matchingCat = categories.find(c => birthYear >= c.min && birthYear <= c.max); + let matchingCat = categories.find(c => birthYear >= c.min && birthYear <= c.max && c.sexe === adherentSexe); + if (!matchingCat) { + matchingCat = categories.find(c => birthYear >= c.min && birthYear <= c.max && c.sexe === 'MASCULIN'); + } if (!matchingCat) return; document.querySelectorAll('.licence-row').forEach(row => { @@ -897,7 +919,10 @@ } if (sexeSelect) { - sexeSelect.addEventListener('change', updateEquipmentStyleLabels); + sexeSelect.addEventListener('change', function() { + updateEquipmentStyleLabels(); + updateLicencesCategoryAndPrices(); + }); } if (typeMaillotSelect) { typeMaillotSelect.addEventListener('change', updateEquipmentStyleLabels);