Compare commits
2 Commits
feature/su
...
feature/su
| Author | SHA1 | Date | |
|---|---|---|---|
| d09154ef9a | |||
| 65497cd669 |
@@ -2,6 +2,34 @@ const $ = (element) => document.getElementById(element);
|
|||||||
|
|
||||||
const url_liste_conge_attente = $("liste-demande-conges").dataset.url
|
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", {
|
const tableau_liste_demande_conge = new Tabulator("#liste-demande-conges", {
|
||||||
columns: [
|
columns: [
|
||||||
{"title": "Nom et Prénom", "field": "prenom_nom"},
|
{"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 :{
|
{"title": "Validation par supérieur hiérarchique", "field": "validation_direction", formatter:"tickCross", formatterParams :{
|
||||||
allowEmpty : true ,
|
allowEmpty : true ,
|
||||||
}},
|
}},
|
||||||
|
{
|
||||||
|
title: "Action",
|
||||||
|
hozAlign: "center",
|
||||||
|
formatter: (cell) => {
|
||||||
|
const data = cell.getRow().getData();
|
||||||
|
if (!data.est_proprietaire || !data.en_attente) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return '<button type="button" class="btn btn-danger btn-sm">Supprimer</button>';
|
||||||
|
},
|
||||||
|
cellClick: (event, cell) => {
|
||||||
|
const data = cell.getRow().getData();
|
||||||
|
if (data.est_proprietaire && data.en_attente) {
|
||||||
|
event.stopPropagation();
|
||||||
|
supprimerDemandeConge(data.id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
pagination: true,
|
pagination: true,
|
||||||
paginationSize: 5,
|
paginationSize: 5,
|
||||||
})
|
})
|
||||||
|
|
||||||
const bouton_demande_conges = $("bouton-demande-conge");
|
const bouton_demande_conges = $("bouton-demande-conge");
|
||||||
|
const bouton_supprimer_conge = $("bouton-supprimer-demande-conge");
|
||||||
|
|
||||||
bouton_demande_conges.addEventListener("click", (e) => {
|
bouton_demande_conges.addEventListener("click", (e) => {
|
||||||
var modalDemandeConge = new bootstrap.Modal(document.getElementById('modalDemandeConge'));
|
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;
|
$("nombre_jours").value = data.nombre_jours;
|
||||||
$("solde_restant").value = data.solde_conge;
|
$("solde_restant").value = data.solde_conge;
|
||||||
$("motif_refus").value = data.motif_refus;
|
$("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")){
|
if($("validation_hierarchique_valide") & $("validation_hierarchique_refuse")){
|
||||||
$("validation_hierarchique_valide").checked = data.validation_hierarchique === true;
|
$("validation_hierarchique_valide").checked = data.validation_hierarchique === true;
|
||||||
@@ -59,6 +111,10 @@ tableau_liste_demande_conge.on("rowClick", function(row, rowData) {
|
|||||||
modal.show();
|
modal.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bouton_supprimer_conge.addEventListener("click", () => {
|
||||||
|
supprimerDemandeConge(bouton_supprimer_conge.dataset.congeId);
|
||||||
|
});
|
||||||
|
|
||||||
fetch(url_liste_conge_attente)
|
fetch(url_liste_conge_attente)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
|||||||
@@ -83,6 +83,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
|
||||||
|
{% if conge.validation_hierarchique == None and conge.validation_direction == None%}
|
||||||
|
<button type="button" class="btn btn-danger " id="bouton-supprimer-demande-conge"
|
||||||
|
data-url="{% url 'gestion_conges:supprimer-demande-conge' 0 %}"
|
||||||
|
>
|
||||||
|
Supprimer ma demande
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
{% if employe_est_il_chef or membre_de_la_direction or est_chef_projet %}
|
{% if employe_est_il_chef or membre_de_la_direction or est_chef_projet %}
|
||||||
<button type="button" class="btn btn-success" id="bouton-enregistrer-detail-conge">Enregistrer</button>
|
<button type="button" class="btn btn-success" id="bouton-enregistrer-detail-conge">Enregistrer</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -24,4 +24,9 @@ urlpatterns = [
|
|||||||
views.validation_de_conge,
|
views.validation_de_conge,
|
||||||
name='validation-des-conges'
|
name='validation-des-conges'
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
'demande/<int:conge_id>/supprimer/',
|
||||||
|
views.supprimer_demande_conge,
|
||||||
|
name='supprimer-demande-conge',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
@@ -234,4 +234,56 @@ def validation_de_conge(request):
|
|||||||
conge.motif_refus = motif_refus if validation_direction == "refuse" else ""
|
conge.motif_refus = motif_refus if validation_direction == "refuse" else ""
|
||||||
|
|
||||||
conge.save()
|
conge.save()
|
||||||
return JsonResponse({"message": "La décision a été enregistrée avec succès."})
|
return JsonResponse({"message": "La décision a été enregistrée avec succès."})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def _conge_est_en_attente(conge):
|
||||||
|
return (
|
||||||
|
conge.validation_hierarchique is not False
|
||||||
|
and conge.validation_direction is not False
|
||||||
|
and not (
|
||||||
|
conge.validation_hierarchique is True
|
||||||
|
and conge.validation_direction is True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def supprimer_demande_conge(request, conge_id):
|
||||||
|
if request.method != "POST":
|
||||||
|
return JsonResponse(
|
||||||
|
{"success": False, "message": "Méthode non autorisée."},
|
||||||
|
status=405,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
employe = Employe.objects.get(user=request.user)
|
||||||
|
except Employe.DoesNotExist:
|
||||||
|
return JsonResponse(
|
||||||
|
{"success": False, "message": "Profil employé introuvable."},
|
||||||
|
status=403,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
conge = Conge.objects.get(pk=conge_id, employe=employe)
|
||||||
|
except Conge.DoesNotExist:
|
||||||
|
return JsonResponse(
|
||||||
|
{"success": False, "message": "Demande introuvable ou accès non autorisé."},
|
||||||
|
status=404,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not _conge_est_en_attente(conge):
|
||||||
|
return JsonResponse(
|
||||||
|
{
|
||||||
|
"success": False,
|
||||||
|
"message": "Seules les demandes en attente peuvent être supprimées.",
|
||||||
|
},
|
||||||
|
status=400,
|
||||||
|
)
|
||||||
|
|
||||||
|
conge.delete()
|
||||||
|
return JsonResponse(
|
||||||
|
{"success": True, "message": "Votre demande de congé en attente a été supprimée."}
|
||||||
|
)
|
||||||
|
|
||||||
Reference in New Issue
Block a user