Compare commits
2 Commits
41dcb84987
...
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',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
@@ -235,3 +235,55 @@ def validation_de_conge(request):
|
|||||||
|
|
||||||
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."}
|
||||||
|
)
|
||||||
|
|
||||||
@@ -2,71 +2,7 @@ const $ = (element) => document.getElementById(element);
|
|||||||
const { Schedule } = calendarjs;
|
const { Schedule } = calendarjs;
|
||||||
|
|
||||||
let dateAUtiliser = new Date().toISOString().split('T')[0];
|
let dateAUtiliser = new Date().toISOString().split('T')[0];
|
||||||
|
let currentReservationId = null;
|
||||||
function afficherDetailsReservation(data) {
|
|
||||||
const reservationId = data.id_reservation || data.id;
|
|
||||||
$("id_reservation_detail").value = reservationId;
|
|
||||||
$("id_reservation_refus").value = reservationId;
|
|
||||||
$("id_reservation_zoom").value = reservationId;
|
|
||||||
$("employe").value = data.employe;
|
|
||||||
$("salle").value = data.salle;
|
|
||||||
$("statut-reservation").textContent = data.statut;
|
|
||||||
$("date_evenement").value = data.date_evenement || data.date_debut;
|
|
||||||
$("heure_debut").value = data.heure_debut;
|
|
||||||
$("heure_fin").value = data.heure_fin;
|
|
||||||
$("motif_reservation").value = data.motif_reservation;
|
|
||||||
$("besoin_zoom").checked = data.besoin_zoom;
|
|
||||||
$("besoin_ordinateur").checked = data.besoin_ordinateur ?? data.besoin_ordi;
|
|
||||||
$("lien_zoom").value = data.lien_zoom || "";
|
|
||||||
$("lien_zoom_container").classList.toggle("d-none", !data.besoin_zoom);
|
|
||||||
|
|
||||||
const currentUserId = $("current-user-id").dataset.userId;
|
|
||||||
const isOwner = data.est_proprietaire === true
|
|
||||||
|| String(data.employe_id) === currentUserId;
|
|
||||||
const isPending = data.est_en_attente === true
|
|
||||||
|| data.statut === "En attente"
|
|
||||||
|| data.statut === "en_attente";
|
|
||||||
|
|
||||||
$("bouton-supprimer-reservation").classList.toggle(
|
|
||||||
"d-none",
|
|
||||||
!(isOwner && isPending)
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const id of ["refuserReservation", "refuserReservationInfo", "bouton-valider", "bouton-valider-info"]) {
|
|
||||||
const button = $(id);
|
|
||||||
if (button) {
|
|
||||||
button.style.display = isPending && !isOwner ? "inline-block" : "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function supprimerReservation(reservationId) {
|
|
||||||
if (!window.confirm("Voulez-vous vraiment supprimer cette demande de réservation en attente ?")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const form = $("formulaire-details");
|
|
||||||
const csrf = form.querySelector("[name=csrfmiddlewaretoken]").value;
|
|
||||||
const url = $("bouton-supprimer-reservation").dataset.url.replace(
|
|
||||||
"/0/",
|
|
||||||
`/${reservationId}/`
|
|
||||||
);
|
|
||||||
|
|
||||||
fetch(url, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {"X-CSRFToken": csrf},
|
|
||||||
})
|
|
||||||
.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 calendrier = Schedule(document.getElementById('planning-reservation'), {
|
const calendrier = Schedule(document.getElementById('planning-reservation'), {
|
||||||
type: 'weekdays',
|
type: 'weekdays',
|
||||||
@@ -83,7 +19,31 @@ const calendrier = Schedule(document.getElementById('planning-reservation'), {
|
|||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
afficherDetailsReservation(data);
|
currentReservationId = data.id_reservation;
|
||||||
|
$("id_reservation_detail").value = data.id_reservation;
|
||||||
|
$("id_reservation_refus").value = data.id_reservation;
|
||||||
|
$("id_reservation_zoom").value = data.id_reservation;
|
||||||
|
$("employe").value=data.employe;
|
||||||
|
$("salle").value=data.salle;
|
||||||
|
$("statut-reservation").innerHTML=data.statut;
|
||||||
|
$("date_evenement").value=data.date_evenement;
|
||||||
|
$("heure_debut").value=data.heure_debut;
|
||||||
|
$("heure_fin").value=data.heure_fin;
|
||||||
|
$("motif_reservation").value=data.motif_reservation;
|
||||||
|
$("besoin_zoom").checked=data.besoin_zoom;
|
||||||
|
$("besoin_ordinateur").checked=data.besoin_ordinateur;
|
||||||
|
$("lien_zoom").value=data.lien_zoom;
|
||||||
|
|
||||||
|
const zoomContainer = $("lien_zoom_container");
|
||||||
|
if (!data.besoin_zoom) {
|
||||||
|
zoomContainer.classList.add("d-none");
|
||||||
|
} else {
|
||||||
|
zoomContainer.classList.remove("d-none");
|
||||||
|
}
|
||||||
|
if (data.besoin_zoom === false){
|
||||||
|
$("lien_zoom_container").className = "d-none";
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error => console.error("Impossible de charger les détails de la réservation :", error));
|
.catch(error => console.error("Impossible de charger les détails de la réservation :", error));
|
||||||
}
|
}
|
||||||
@@ -98,10 +58,6 @@ $('semaineDate').addEventListener('change', () => {
|
|||||||
calendrier.render();
|
calendrier.render();
|
||||||
})
|
})
|
||||||
|
|
||||||
$("bouton-supprimer-reservation").addEventListener("click", () => {
|
|
||||||
supprimerReservation($("id_reservation_detail").value);
|
|
||||||
});
|
|
||||||
|
|
||||||
evenement_defini = null
|
evenement_defini = null
|
||||||
|
|
||||||
$("liste-salle").addEventListener("change", (e) => {
|
$("liste-salle").addEventListener("change", (e) => {
|
||||||
@@ -120,22 +76,39 @@ $("liste-salle").addEventListener("change", (e) => {
|
|||||||
function chargement_evenement(){
|
function chargement_evenement(){
|
||||||
const url = $("planning-reservation").dataset.url;
|
const url = $("planning-reservation").dataset.url;
|
||||||
fetch (url)
|
fetch (url)
|
||||||
.then(response => {
|
.then(response => response.json())
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Erreur HTTP ${response.status}`);
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(data => {
|
.then(data => {
|
||||||
calendrier.setData(data);
|
calendrier.setData(data);
|
||||||
})
|
})
|
||||||
.catch(error => console.error("Impossible de charger les réservations :", error));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
chargement_evenement()
|
chargement_evenement()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$("bouton-annuler").addEventListener("click", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const csrf = document.querySelector("[name=csrfmiddlewaretoken]").value;
|
||||||
|
const url_annuler = $("formulaire-details").dataset.urlannuler;
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
fetch(
|
||||||
|
url_annuler,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"X-Requested-With": "XMTHttpRequest",
|
||||||
|
"X-CSRFToken": csrf
|
||||||
|
},
|
||||||
|
body: new FormData($("formulaire-details"))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => console.log(data))
|
||||||
|
})
|
||||||
|
|
||||||
if($("bouton-valider")){
|
if($("bouton-valider")){
|
||||||
$("bouton-valider").addEventListener("click", (e) => {
|
$("bouton-valider").addEventListener("click", (e) => {
|
||||||
const csrf = document.querySelector("[name=csrfmiddlewaretoken]").value;
|
const csrf = document.querySelector("[name=csrfmiddlewaretoken]").value;
|
||||||
@@ -207,7 +180,40 @@ const tableau_reservation_attente = new Tabulator("#tableau-reservation-attente"
|
|||||||
tableau_reservation_attente.on("rowClick", (row, rowData) => {
|
tableau_reservation_attente.on("rowClick", (row, rowData) => {
|
||||||
const data = rowData.getData();
|
const data = rowData.getData();
|
||||||
|
|
||||||
afficherDetailsReservation(data);
|
console.log(data);
|
||||||
|
|
||||||
|
if(data.besoin_zoom === false){
|
||||||
|
$("lien_zoom_container").className = 'd-none';
|
||||||
|
}
|
||||||
|
|
||||||
|
const id_user = $("current-user-id").dataset.userId;
|
||||||
|
|
||||||
|
$("id_reservation_detail").value = data.id;
|
||||||
|
$("id_reservation_refus").value = data.id;
|
||||||
|
$("id_reservation_zoom").value = data.id;
|
||||||
|
|
||||||
|
$("employe").value=data.employe;
|
||||||
|
$("salle").value=data.salle;
|
||||||
|
$("statut-reservation").innerHTML=data.statut;
|
||||||
|
$("date_evenement").value = data.date_evenement;
|
||||||
|
$("heure_debut").value=data.heure_debut;
|
||||||
|
$("heure_fin").value=data.heure_fin;
|
||||||
|
$("motif_reservation").value=data.motif_reservation;
|
||||||
|
$("besoin_zoom").checked=data.besoin_zoom;
|
||||||
|
$("besoin_ordinateur").checked=data.besoin_ordi;
|
||||||
|
$("lien_zoom").value=data.lien_zoom;
|
||||||
|
|
||||||
|
const refuserReservation = document.querySelector("#refuserReservation");
|
||||||
|
const bouton_valider = document.querySelector("#bouton-valider");
|
||||||
|
|
||||||
|
if((refuserReservation | bouton_valider) && data.statut === "En attente"){
|
||||||
|
refuserReservation.style.display = "inline-block";
|
||||||
|
bouton_valider.style.display = "inline-block";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id_user != data.employe_id){
|
||||||
|
$("bouton-annuler").className = "d-none";
|
||||||
|
}
|
||||||
|
|
||||||
const modal = new bootstrap.Modal($("modalDetailReservation"));
|
const modal = new bootstrap.Modal($("modalDetailReservation"));
|
||||||
bootstrap.Modal.getOrCreateInstance($("modalReservationAttente")).hide();
|
bootstrap.Modal.getOrCreateInstance($("modalReservationAttente")).hide();
|
||||||
|
|||||||
@@ -55,5 +55,5 @@
|
|||||||
{% block 'js' %}
|
{% block 'js' %}
|
||||||
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@calendarjs/ce/dist/index.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/@calendarjs/ce/dist/index.min.js"></script>
|
||||||
<script src="{% static 'gestion_salle/js/index.js' %}?v=5"></script>
|
<script src="{% static 'gestion_salle/js/index.js' %}?v=3"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form method="POST" data-urlvalider="{% url 'gestion_salle:valider-reservation' %}" id="formulaire-details">
|
<form method="POST" data-urlannuler="{% url 'gestion_salle:annuler-reservation' %}" data-urlvalider="{% url 'gestion_salle:valider-reservation' %}" id="formulaire-details">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type='' class="form-control" id="id_reservation_detail" name='id_reservation' hidden>
|
<input type='' class="form-control" id="id_reservation_detail" name='id_reservation' hidden>
|
||||||
<div class="form-group mb-2">
|
<div class="form-group mb-2">
|
||||||
@@ -63,18 +63,7 @@
|
|||||||
<button class="btn btn-success me-1" id="bouton-valider-info">Valider</button>
|
<button class="btn btn-success me-1" id="bouton-valider-info">Valider</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span id="current-user-id" data-user-id="{{ user.id }}"></span>
|
<span id="current-user-id" data-user-id="{{ user.id }}"></span>
|
||||||
<button
|
<button class="btn btn-danger" id="bouton-annuler">Annuler</button>
|
||||||
type="button"
|
|
||||||
class="btn btn-outline-danger d-none"
|
|
||||||
id="bouton-supprimer-reservation"
|
|
||||||
data-url="{% url 'gestion_salle:supprimer-reservation' 0 %}"
|
|
||||||
>
|
|
||||||
Supprimer ma demande
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button type="button" class="btn btn-secondary" id="bouton-annuler" data-bs-dismiss="modal">
|
|
||||||
Fermer
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -45,10 +45,5 @@ urlpatterns = [
|
|||||||
'liste-reservation-attente',
|
'liste-reservation-attente',
|
||||||
views.liste_reservation_attente,
|
views.liste_reservation_attente,
|
||||||
name="liste-reservation-attente"
|
name="liste-reservation-attente"
|
||||||
),
|
|
||||||
path(
|
|
||||||
'reservation/<int:reservation_id>/supprimer',
|
|
||||||
views.supprimer_reservation,
|
|
||||||
name="supprimer-reservation",
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
@@ -125,25 +125,19 @@ Veuillez vous connecter à la plateforme pour traiter cette demande.""",
|
|||||||
|
|
||||||
return render(request, "gestion_salle/index.html", context)
|
return render(request, "gestion_salle/index.html", context)
|
||||||
|
|
||||||
@login_required
|
|
||||||
def liste_reservation(request:HttpRequest):
|
def liste_reservation(request:HttpRequest):
|
||||||
"""Vue d'affichage des creneaux disponibles"""
|
"""Vue d'affichage des creneaux disponibles"""
|
||||||
try:
|
reservations = Reservation.objects.filter(statut = "validee")
|
||||||
employe = Employe.objects.get(user=request.user)
|
|
||||||
reservations = Reservation.objects.filter(
|
|
||||||
Q(statut="validee")
|
|
||||||
| Q(statut="en_attente", employe=employe)
|
|
||||||
)
|
|
||||||
except Employe.DoesNotExist:
|
|
||||||
reservations = Reservation.objects.filter(statut="validee")
|
|
||||||
|
|
||||||
liste_reservation = []
|
liste_reservation = []
|
||||||
|
|
||||||
for reservation in reservations:
|
for reservation in reservations:
|
||||||
|
color = None
|
||||||
if reservation.statut == "en_attente":
|
if reservation.statut == "en_attente":
|
||||||
color = "#ffc107"
|
color = "#ffc107"
|
||||||
else:
|
elif reservation.statut == "validee":
|
||||||
color = "#198754"
|
color = "#198754"
|
||||||
|
else:
|
||||||
|
color = "#dc3545"
|
||||||
|
|
||||||
liste_reservation.append({
|
liste_reservation.append({
|
||||||
"guid": reservation.pk,
|
"guid": reservation.pk,
|
||||||
@@ -152,7 +146,6 @@ def liste_reservation(request:HttpRequest):
|
|||||||
"start": reservation.heure_debut,
|
"start": reservation.heure_debut,
|
||||||
"end": reservation.heure_fin,
|
"end": reservation.heure_fin,
|
||||||
"color": color,
|
"color": color,
|
||||||
"statut": dict(Reservation.STATUT).get(reservation.statut),
|
|
||||||
})
|
})
|
||||||
return JsonResponse(liste_reservation, safe=False)
|
return JsonResponse(liste_reservation, safe=False)
|
||||||
|
|
||||||
@@ -190,7 +183,6 @@ def liste_reservation_attente(request):
|
|||||||
liste_reservation = [
|
liste_reservation = [
|
||||||
{
|
{
|
||||||
**model_to_dict(reservation),
|
**model_to_dict(reservation),
|
||||||
"id": reservation.pk,
|
|
||||||
"employe": f"{reservation.employe.user.first_name} {reservation.employe.user.last_name}",
|
"employe": f"{reservation.employe.user.first_name} {reservation.employe.user.last_name}",
|
||||||
"employe_id": reservation.employe.user.id,
|
"employe_id": reservation.employe.user.id,
|
||||||
"salle": dict(Reservation.TYPE_CHOICES).get(reservation.salle),
|
"salle": dict(Reservation.TYPE_CHOICES).get(reservation.salle),
|
||||||
@@ -201,49 +193,6 @@ def liste_reservation_attente(request):
|
|||||||
|
|
||||||
return JsonResponse(liste_reservation, safe=False)
|
return JsonResponse(liste_reservation, safe=False)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def supprimer_reservation(request: HttpRequest, reservation_id: int):
|
|
||||||
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:
|
|
||||||
reservation = Reservation.objects.get(
|
|
||||||
pk=reservation_id,
|
|
||||||
employe=employe,
|
|
||||||
)
|
|
||||||
except Reservation.DoesNotExist:
|
|
||||||
return JsonResponse(
|
|
||||||
{"success": False, "message": "Réservation introuvable ou accès non autorisé."},
|
|
||||||
status=404,
|
|
||||||
)
|
|
||||||
|
|
||||||
if reservation.statut != "en_attente":
|
|
||||||
return JsonResponse(
|
|
||||||
{
|
|
||||||
"success": False,
|
|
||||||
"message": "Seules les réservations en attente peuvent être supprimées.",
|
|
||||||
},
|
|
||||||
status=400,
|
|
||||||
)
|
|
||||||
|
|
||||||
reservation.delete()
|
|
||||||
return JsonResponse(
|
|
||||||
{"success": True, "message": "Votre réservation en attente a été supprimée."}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def detail_reservation(request:HttpRequest, reservation_id:int):
|
def detail_reservation(request:HttpRequest, reservation_id:int):
|
||||||
reservation = Reservation.objects.get(id=reservation_id)
|
reservation = Reservation.objects.get(id=reservation_id)
|
||||||
employe = reservation.employe.user
|
employe = reservation.employe.user
|
||||||
@@ -260,8 +209,6 @@ def detail_reservation(request:HttpRequest, reservation_id:int):
|
|||||||
'besoin_zoom': reservation.besoin_zoom,
|
'besoin_zoom': reservation.besoin_zoom,
|
||||||
'besoin_ordinateur': reservation.besoin_ordi,
|
'besoin_ordinateur': reservation.besoin_ordi,
|
||||||
'lien_zoom': reservation.lien_zoom or '',
|
'lien_zoom': reservation.lien_zoom or '',
|
||||||
'est_proprietaire': request.user.is_authenticated and reservation.employe.user_id == request.user.id,
|
|
||||||
'est_en_attente': reservation.statut == "en_attente",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return JsonResponse(reservation_json, safe=True)
|
return JsonResponse(reservation_json, safe=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user