feat: pré-sélection de la catégorie par âge et sexe lors de la création d'une licence
This commit is contained in:
@@ -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} + ' €)'"></option>
|
||||
@@ -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) {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user