This commit is contained in:
2026-01-19 15:55:45 +00:00
parent b30acf98f9
commit edaea568ae
3 changed files with 143 additions and 87 deletions

View File

@@ -1448,40 +1448,110 @@ function enregistrer_avenant()
}
function pop_afficher_selection_retrait()
{
var div_selection_assure = $('#div_selection_assure');
div_selection_assure.html(`
<div class="d-flex flex-column align-items-center justify-content-center" style="padding-top:80px;">
<div class="spinner-border text-primary" role="status" style="width:3rem; height:3rem;">
<span class="visually-hidden">Loading...</span>
</div>
<span class="mt-3 fs-5 fw-bold">
Veuillez patienter... / Please wait...
</span>
</div>
`);
/**
* Initialise un DataTable de manière générique avec support Ajax et Bootstrap
* @param {string} selector - L'ID ou la classe du tableau (ex: '#monTableau')
* @param {Object} customOptions - Options spécifiques pour surcharger la config par défaut
*/
function genericInitDataTable(selector, customOptions = {}) {
// 1. Sécurité : Vérifier si l'élément existe
if ($(selector).length === 0) return;
// 2. Si une instance existe déjà, on la détruit proprement
if ($.fn.DataTable.isDataTable(selector)) {
$(selector).DataTable().destroy();
$(selector).empty(); // Optionnel : vide le DOM si nécessaire
}
// 3. Configuration par défaut (Standard pour votre portail RH)
const defaultOptions = {
"language": {
"url": "//cdn.datatables.net/plug-ins/1.13.6/i18n/fr-FR.json"
},
"pageLength": 10,
"responsive": true,
"dom": '<"d-flex justify-content-between align-items-center mb-3"fB>rt<"d-flex justify-content-between align-items-center mt-3"ip>',
"buttons": [
{
extend: 'excelHtml5',
className: 'btn btn-sm btn-outline-success rounded-pill px-3',
text: '<i class="far fa-file-excel me-1"></i> Excel'
},
{
extend: 'pdfHtml5',
className: 'btn btn-sm btn-outline-danger rounded-pill px-3',
text: '<i class="far fa-file-pdf me-1"></i> PDF'
}
],
"drawCallback": function() {
// Style Bootstrap pour le champ de recherche
$('.dataTables_filter input').addClass('form-control form-control-sm shadow-none rounded-pill');
$('.dataTables_paginate .paginate_button').addClass('btn btn-xs');
}
};
// 4. Fusion des options par défaut avec les options personnalisées
const finalOptions = $.extend(true, {}, defaultOptions, customOptions);
// 5. Initialisation
return $(selector).DataTable(finalOptions);
}
$.ajax({
url: $("#racineWeb").val()+"Ajaxselectionretrait/",
type : 'post',
error: function(errorData) {
},
success: function(data) {
div_selection_assure.html(data);
// $('#div_test_gabarit').html(data);
},
complete: function() {
const modal = document.getElementById("popdetailassure");
if (modal && modal.parentNode !== document.body) {
document.body.appendChild(modal);
}
// Ouvrir le modal via le bouton caché
document.getElementById("btn_pop").click();
}
});
function pop_afficher_selection_retrait() {
var div_selection_assure = $('#div_selection_assure');
// 1. Affichage du Loader
div_selection_assure.html(`
<div class="d-flex flex-column align-items-center justify-content-center" style="padding-top:80px; min-height:300px;">
<div class="spinner-border text-primary" role="status" style="width:3rem; height:3rem;">
<span class="visually-hidden">Loading...</span>
</div>
<span class="mt-3 fs-5 fw-bold text-muted">
Chargement de la liste... / Loading list...
</span>
</div>
`);
// 2. Appel Ajax
$.ajax({
url: $("#racineWeb").val() + "Ajaxselectionretrait/",
type: 'post',
error: function(xhr, status, error) {
div_selection_assure.html(`
<div class="alert alert-danger m-3">
<i class="fas fa-exclamation-circle me-2"></i> Erreur lors du chargement : ${error}
</div>
`);
},
success: function(data) {
// Injection des données
div_selection_assure.html(data);
// 3. INITIALISATION DU DATATABLE GÉNÉRIQUE
// On cible l'ID du tableau qui est généré dans votre vue Ajax
genericInitDataTable('#table_retrait_assures', {
"order": [[1, "asc"]], // Trie par nom
"pageLength": 10,
"columnDefs": [
{ "orderable": false, "targets": [-1] } // Désactive le tri sur la dernière colonne (Action)
]
});
},
complete: function() {
// 4. Gestion propre du Modal
const modalEl = document.getElementById("popdetailassure");
// S'assurer que le modal est au bon endroit dans le DOM
if (modalEl && modalEl.parentNode !== document.body) {
document.body.appendChild(modalEl);
}
// Ouverture du modal via l'instance Bootstrap
var myModal = bootstrap.Modal.getOrCreateInstance(modalEl);
myModal.show();
}
});
}
function beneficiaire_a_retirer(p_choix, p_id_beneficiaire)