Ajouter prestation : DOM message + mise ne place du header+fichier style css prestation
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
// Récupération des éléments
|
||||
// Éléments
|
||||
const form = document.getElementById("addCategoryForm");
|
||||
const messages = document.getElementById("messages");
|
||||
|
||||
const titleField = document.getElementById("categoryName");
|
||||
const typeField = document.getElementById("prestationType");
|
||||
const descField = document.getElementById("prestationDescription");
|
||||
const priceMinField = document.getElementById("priceMin");
|
||||
const priceMaxField = document.getElementById("priceMax");
|
||||
|
||||
const errorEmpty = document.getElementById("errorEmpty");
|
||||
const errorExists = document.getElementById("errorExists");
|
||||
const successMessage = document.getElementById("successMessage");
|
||||
|
||||
// Prestations existantes (simulation)
|
||||
// Prestations existantes (simulation BDD)
|
||||
const existingPrestations = [
|
||||
"Toilettage complet",
|
||||
"Coupe ciseaux",
|
||||
@@ -18,38 +16,42 @@ const existingPrestations = [
|
||||
"Démêlage poil long"
|
||||
];
|
||||
|
||||
|
||||
function showMessage(type, text) {
|
||||
messages.innerHTML = "";
|
||||
|
||||
const div = document.createElement("div");
|
||||
div.className = `alert alert-${type}`;
|
||||
div.textContent = text;
|
||||
|
||||
messages.appendChild(div);
|
||||
}
|
||||
|
||||
|
||||
form.addEventListener("submit", function (e) {
|
||||
e.preventDefault();
|
||||
messages.innerHTML = "";
|
||||
|
||||
// Récupérer le titre
|
||||
const titre = titleField.value.trim();
|
||||
|
||||
// Réinitialiser les alertes
|
||||
errorEmpty.classList.add("d-none");
|
||||
errorExists.classList.add("d-none");
|
||||
successMessage.classList.add("d-none");
|
||||
|
||||
// 1. Vérif : titre obligatoire
|
||||
if (titre === "") {
|
||||
errorEmpty.classList.remove("d-none");
|
||||
// Titre obligatoire
|
||||
if (!titre) {
|
||||
showMessage("danger", "Le titre de la prestation est obligatoire.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Vérif : prestation déjà existante (exemple simple)
|
||||
// Doublon
|
||||
if (existingPrestations.includes(titre)) {
|
||||
errorExists.classList.remove("d-none");
|
||||
showMessage("danger", "Cette prestation existe déjà. Veuillez en choisir une autre.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Tout est ok → succès
|
||||
successMessage.classList.remove("d-none");
|
||||
|
||||
// Simuler ajout en base
|
||||
// Succès
|
||||
existingPrestations.push(titre);
|
||||
showMessage("success", "Prestation ajoutée avec succès !");
|
||||
|
||||
|
||||
// Redirection
|
||||
setTimeout(() => {
|
||||
window.location.href = "../liste_prestation/liste_prestation.html";
|
||||
}, 1500);
|
||||
window.location.href = "../liste_prestation/liste_prestation.html";
|
||||
}, 1500);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user