From f72b6e9337ed6e7acc66e340735c872157acfb4e Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 12 Dec 2025 15:32:17 +0100 Subject: [PATCH] =?UTF-8?q?mise=20a=20jour=20du=20dom=20ajouter=20cat?= =?UTF-8?q?=C3=A9gorie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog/html/ajouter_categorie.html | 120 ++++++++++--------------------- blog/js/ajouter_categorie.js | 57 ++++++++------- package-lock.json | 3 +- 3 files changed, 68 insertions(+), 112 deletions(-) diff --git a/blog/html/ajouter_categorie.html b/blog/html/ajouter_categorie.html index ae80d6a..4e6e0c9 100644 --- a/blog/html/ajouter_categorie.html +++ b/blog/html/ajouter_categorie.html @@ -4,107 +4,59 @@ Ajouter une catégorie - - + + + + + -
-
-

Ajouter une catégorie

+
+

Ajouter une catégorie

- -
Le nom de catégorie est obligatoire.
+ +
- -
Cette catégorie existe déjà. Veuillez en choisir une autre.
+
- -
Catégorie ajoutée avec succès !
+
+ + +
- +
+ + +
+
+ Annuler + +
+
+
-
- -
+ + -
- - -
- -
- Annuler - -
- -
- - - - - \ No newline at end of file + diff --git a/blog/js/ajouter_categorie.js b/blog/js/ajouter_categorie.js index dd7e34c..b8e1038 100644 --- a/blog/js/ajouter_categorie.js +++ b/blog/js/ajouter_categorie.js @@ -1,47 +1,52 @@ - const form = document.getElementById("addCategoryForm"); +const messages = document.getElementById("messages"); + const nameField = document.getElementById("categoryName"); const descField = document.getElementById("categoryDescription"); -const errorEmpty = document.getElementById("errorEmpty"); -const errorExists = document.getElementById("errorExists"); -const successMessage = document.getElementById("successMessage"); - -// Catégories existantes ( à remplacer en BD si besoin) +// Catégories existantes (simulation BDD) const existingCategories = ["Actualités", "Chien", "Chat", "Boutique"]; + +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 nom = nameField.value.trim(); - //Remettre tout a zero - errorEmpty.classList.add("d-none"); - errorExists.classList.add("d-none"); - successMessage.classList.add("d-none"); - - //Erreur champs vide - if (nom === "") { - errorEmpty.classList.remove("d-none"); + // Champ obligatoire + if (!nom) { + showMessage("danger", "Le nom de la catégorie est obligatoire."); return; } - //Erreur catégorie existante + // Catégorie existante if (existingCategories.includes(nom)) { - errorExists.classList.remove("d-none"); + showMessage("danger", "Cette catégorie existe déjà. Veuillez en choisir une autre."); return; } - // Succès -successMessage.classList.remove("d-none"); + // Ajout catégorie (simulation) + existingCategories.push(nom); -// Ajout d'une nouvelle catégorie -existingCategories.push(nom); + showMessage("success", "Catégorie ajoutée avec succès !"); -// Redirection après 1 seconde -setTimeout(() => { - window.location.href = "../html/accueil_blog.html"; -}, 1000); + // Reset formulaire + form.reset(); - -}); \ No newline at end of file + // Redirection + setTimeout(() => { + window.location.href = "../html/accueil_blog.html"; + }, 1000); +}); diff --git a/package-lock.json b/package-lock.json index 1bfd43d..890a3bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -76,8 +76,7 @@ "node_modules/scheduler": { "version": "0.27.0", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz", - "integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==", - "peer": true + "integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==" }, "node_modules/tinymce": { "version": "8.2.2",