58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
// É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");
|
|
|
|
// Prestations existantes (simulation BDD)
|
|
const existingPrestations = [
|
|
"Toilettage complet",
|
|
"Coupe ciseaux",
|
|
"Toilettage chiot",
|
|
"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 = "";
|
|
|
|
const titre = titleField.value.trim();
|
|
|
|
// Titre obligatoire
|
|
if (!titre) {
|
|
showMessage("danger", "Le titre de la prestation est obligatoire.");
|
|
return;
|
|
}
|
|
|
|
// Doublon
|
|
if (existingPrestations.includes(titre)) {
|
|
showMessage("danger", "Cette prestation existe déjà. Veuillez en choisir une autre.");
|
|
return;
|
|
}
|
|
|
|
// Succès
|
|
existingPrestations.push(titre);
|
|
showMessage("success", "Prestation ajoutée avec succès !");
|
|
|
|
// Redirection
|
|
setTimeout(() => {
|
|
window.location.href = "../liste_prestation/liste_prestation.html";
|
|
}, 1500);
|
|
});
|