From 65497cd669475e5d31565ca0b0a7d76cad371b7c Mon Sep 17 00:00:00 2001 From: fatima Date: Tue, 6 Oct 2026 16:12:42 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20suppression=20des=20demandes?= =?UTF-8?q?=20de=20cong=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/gestion_conge/js/index.js | 56 +++++++++++++++++++ .../gestion_conge/parts/modalDetailConge.html | 7 +++ gestion_conge/urls.py | 5 ++ gestion_conge/views.py | 54 +++++++++++++++++- 4 files changed, 121 insertions(+), 1 deletion(-) diff --git a/gestion_conge/static/gestion_conge/js/index.js b/gestion_conge/static/gestion_conge/js/index.js index 4f64c38..2e4a412 100644 --- a/gestion_conge/static/gestion_conge/js/index.js +++ b/gestion_conge/static/gestion_conge/js/index.js @@ -2,6 +2,34 @@ const $ = (element) => document.getElementById(element); const url_liste_conge_attente = $("liste-demande-conges").dataset.url +function supprimerDemandeConge(congeId) { + if (!window.confirm("Voulez-vous vraiment supprimer cette demande de congé en attente ?")) { + return; + } + + const form = $("form-detail-conge"); + const csrftoken = new FormData(form).get("csrfmiddlewaretoken"); + const url = $("bouton-supprimer-demande-conge").dataset.url.replace( + "/0/", + `/${congeId}/` + ); + + fetch(url, { + method: "POST", + headers: {"X-CSRFToken": csrftoken}, + }) + .then(response => response.json().then(data => ({response, data}))) + .then(({response, data}) => { + window.alert(data.message); + if (response.ok && data.success) { + window.location.reload(); + } + }) + .catch(() => { + window.alert("La suppression a échoué. Veuillez réessayer."); + }); +} + const tableau_liste_demande_conge = new Tabulator("#liste-demande-conges", { columns: [ {"title": "Nom et Prénom", "field": "prenom_nom"}, @@ -21,12 +49,31 @@ const tableau_liste_demande_conge = new Tabulator("#liste-demande-conges", { {"title": "Validation par supérieur hiérarchique", "field": "validation_direction", formatter:"tickCross", formatterParams :{ allowEmpty : true , }}, + { + title: "Action", + hozAlign: "center", + formatter: (cell) => { + const data = cell.getRow().getData(); + if (!data.est_proprietaire || !data.en_attente) { + return ""; + } + return ''; + }, + cellClick: (event, cell) => { + const data = cell.getRow().getData(); + if (data.est_proprietaire && data.en_attente) { + event.stopPropagation(); + supprimerDemandeConge(data.id); + } + }, + }, ], pagination: true, paginationSize: 5, }) const bouton_demande_conges = $("bouton-demande-conge"); +const bouton_supprimer_conge = $("bouton-supprimer-demande-conge"); bouton_demande_conges.addEventListener("click", (e) => { var modalDemandeConge = new bootstrap.Modal(document.getElementById('modalDemandeConge')); @@ -44,6 +91,11 @@ tableau_liste_demande_conge.on("rowClick", function(row, rowData) { $("nombre_jours").value = data.nombre_jours; $("solde_restant").value = data.solde_conge; $("motif_refus").value = data.motif_refus; + bouton_supprimer_conge.classList.toggle( + "d-none", + !(data.est_proprietaire && data.en_attente) + ); + bouton_supprimer_conge.dataset.congeId = data.id; if($("validation_hierarchique_valide") & $("validation_hierarchique_refuse")){ $("validation_hierarchique_valide").checked = data.validation_hierarchique === true; @@ -59,6 +111,10 @@ tableau_liste_demande_conge.on("rowClick", function(row, rowData) { modal.show(); }); +bouton_supprimer_conge.addEventListener("click", () => { + supprimerDemandeConge(bouton_supprimer_conge.dataset.congeId); +}); + fetch(url_liste_conge_attente) .then(response => response.json()) .then(data => { diff --git a/gestion_conge/templates/gestion_conge/parts/modalDetailConge.html b/gestion_conge/templates/gestion_conge/parts/modalDetailConge.html index d3d3051..386e13a 100644 --- a/gestion_conge/templates/gestion_conge/parts/modalDetailConge.html +++ b/gestion_conge/templates/gestion_conge/parts/modalDetailConge.html @@ -83,6 +83,13 @@