mise a jour du dom ajouter catégorie
This commit is contained in:
@@ -4,107 +4,59 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Ajouter une catégorie</title>
|
<title>Ajouter une catégorie</title>
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
|
|
||||||
|
|
||||||
<style>
|
<!-- Bootstrap CSS -->
|
||||||
body{
|
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
|
||||||
background: #f4f6f981;
|
|
||||||
|
<!-- Ton CSS -->
|
||||||
}
|
<link rel="stylesheet" href="/css/blog.css">
|
||||||
.container{
|
|
||||||
|
|
||||||
margin-top: 50px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<!-- HEADER -->
|
|
||||||
<header>
|
<header>
|
||||||
<nav class="navbar navbar-expand-xxl bg-body-tertiary shadow-sm">
|
<nav class="navbar navbar-expand-xxl bg-body-tertiary shadow-sm">
|
||||||
<div class="container-fluid align-items-center">
|
<div class="container-fluid align-items-center">
|
||||||
<a class="navbar-brand" href="#">L'Il'eau chiens - Admin</a>
|
<a class="navbar-brand" href="#">L'Il'eau chiens - Admin</a>
|
||||||
|
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
|
|
||||||
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
|
|
||||||
aria-expanded="false" aria-label="Toggle navigation">
|
|
||||||
<span class="navbar-toggler-icon"></span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
|
||||||
|
|
||||||
<!-- MENU GAUCHE -->
|
|
||||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
|
||||||
<li class="nav-item"><a class="nav-link active" href="#">Blog</a></li>
|
|
||||||
<li class="nav-item"><a class="nav-link" href="#">Boutique</a></li>
|
|
||||||
<li class="nav-item"><a class="nav-link" href="#">Prestations</a></li>
|
|
||||||
<li class="nav-item"><a class="nav-link" href="#">FAQ</a></li>
|
|
||||||
<li class="nav-item"><a class="nav-link" href="#">Fiche de renseignements</a></li>
|
|
||||||
<li class="nav-item"><a class="nav-link" href="#">Partenaires</a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<!-- MENU DROIT -->
|
|
||||||
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="#"><i class="bi bi-megaphone me-1"></i> Message d'actu</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="#"><i class="bi bi-box-arrow-up-right me-1"></i> Voir le site</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="#"><i class="bi bi-gear me-1"></i> Configuration</a>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="nav-item dropdown">
|
|
||||||
<a class="nav-link dropdown-toggle" href="#" id="userMenu" data-bs-toggle="dropdown">
|
|
||||||
<i class="bi bi-person-circle me-1"></i> <span id="userFirstName">Prénom</span>
|
|
||||||
</a>
|
|
||||||
<ul class="dropdown-menu dropdown-menu-end">
|
|
||||||
<li><a class="dropdown-item" href="#">Profil</a></li>
|
|
||||||
<li><hr class="dropdown-divider"></li>
|
|
||||||
<li><a class="dropdown-item" href="#">Sortir</a></li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2 class="mb-5 text-center">Ajouter une catégorie</h2>
|
<h2 class="mb-5 text-center">Ajouter une catégorie</h2>
|
||||||
|
|
||||||
<!--Erreur champ vide -->
|
<!-- Messages DOM -->
|
||||||
<div id="errorEmpty" class="alert alert-danger d-none">Le nom de catégorie est obligatoire.</div>
|
<div id="messages" class="mb-3"></div>
|
||||||
|
|
||||||
<!--Erreur nom deja existant -->
|
<form id="addCategoryForm">
|
||||||
<div id="errorExists" class="alert alert-danger d-none">Cette catégorie existe déjà. Veuillez en choisir une autre.</div>
|
|
||||||
|
|
||||||
<!--Succès ajout catégorie -->
|
<div class="mb-4">
|
||||||
<div id="successMessage" class="alert alert-success d-none">Catégorie ajoutée avec succès !</div>
|
<label class="form-label fw-bold">Nom de la catégorie *</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="categoryName"
|
||||||
|
class="form-control"
|
||||||
|
placeholder="Actualité, chien, chat…">
|
||||||
|
</div>
|
||||||
|
|
||||||
<form id="addCategoryForm">
|
<div class="mb-3">
|
||||||
|
<label class="form-label fw-bold">Description</label>
|
||||||
|
<textarea
|
||||||
|
id="categoryDescription"
|
||||||
|
class="form-control"
|
||||||
|
rows="4"
|
||||||
|
placeholder="Entrez une description (optionnel)">
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex gap-3 mt-4">
|
||||||
|
<a href="../html/accueil_blog.html" class="btn btn-secondary w-50">Annuler</a>
|
||||||
|
<button type="submit" class="btn btn-primary w-50">Ajouter</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
<script src="../js/ajouter_categorie.js"></script>
|
||||||
<label class="form-label fw-bold">Nom de la catégorie (obligatoire)</label>
|
<script src="/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<input type="text" id="categoryName" class="form-control" placeholder="Actualité, chien, chat .." required></div>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<label class="form-label fw-bold">Description</label>
|
|
||||||
<textarea id="categoryDescription" class="form-control" rows="4" placeholder="Entrez une description (optionnel)"></textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="d-flex gap-3 mt-4">
|
|
||||||
<a href="../html/accueil_blog.html" class="btn btn-secondary w-50">Annuler</a>
|
|
||||||
<button type="submit" class="btn btn-primary w-50">Ajouter</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="../js/ajouter_categorie.js"></script>
|
|
||||||
<script src="../../node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,47 +1,52 @@
|
|||||||
|
|
||||||
const form = document.getElementById("addCategoryForm");
|
const form = document.getElementById("addCategoryForm");
|
||||||
|
const messages = document.getElementById("messages");
|
||||||
|
|
||||||
const nameField = document.getElementById("categoryName");
|
const nameField = document.getElementById("categoryName");
|
||||||
const descField = document.getElementById("categoryDescription");
|
const descField = document.getElementById("categoryDescription");
|
||||||
|
|
||||||
const errorEmpty = document.getElementById("errorEmpty");
|
// Catégories existantes (simulation BDD)
|
||||||
const errorExists = document.getElementById("errorExists");
|
|
||||||
const successMessage = document.getElementById("successMessage");
|
|
||||||
|
|
||||||
// Catégories existantes ( à remplacer en BD si besoin)
|
|
||||||
const existingCategories = ["Actualités", "Chien", "Chat", "Boutique"];
|
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) {
|
form.addEventListener("submit", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
messages.innerHTML = "";
|
||||||
|
|
||||||
const nom = nameField.value.trim();
|
const nom = nameField.value.trim();
|
||||||
|
|
||||||
//Remettre tout a zero
|
// Champ obligatoire
|
||||||
errorEmpty.classList.add("d-none");
|
if (!nom) {
|
||||||
errorExists.classList.add("d-none");
|
showMessage("danger", "Le nom de la catégorie est obligatoire.");
|
||||||
successMessage.classList.add("d-none");
|
|
||||||
|
|
||||||
//Erreur champs vide
|
|
||||||
if (nom === "") {
|
|
||||||
errorEmpty.classList.remove("d-none");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Erreur catégorie existante
|
// Catégorie existante
|
||||||
if (existingCategories.includes(nom)) {
|
if (existingCategories.includes(nom)) {
|
||||||
errorExists.classList.remove("d-none");
|
showMessage("danger", "Cette catégorie existe déjà. Veuillez en choisir une autre.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Succès
|
// Ajout catégorie (simulation)
|
||||||
successMessage.classList.remove("d-none");
|
existingCategories.push(nom);
|
||||||
|
|
||||||
// Ajout d'une nouvelle catégorie
|
showMessage("success", "Catégorie ajoutée avec succès !");
|
||||||
existingCategories.push(nom);
|
|
||||||
|
|
||||||
// Redirection après 1 seconde
|
// Reset formulaire
|
||||||
setTimeout(() => {
|
form.reset();
|
||||||
window.location.href = "../html/accueil_blog.html";
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
|
// Redirection
|
||||||
});
|
setTimeout(() => {
|
||||||
|
window.location.href = "../html/accueil_blog.html";
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
|||||||
3
package-lock.json
generated
3
package-lock.json
generated
@@ -76,8 +76,7 @@
|
|||||||
"node_modules/scheduler": {
|
"node_modules/scheduler": {
|
||||||
"version": "0.27.0",
|
"version": "0.27.0",
|
||||||
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz",
|
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz",
|
||||||
"integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==",
|
"integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q=="
|
||||||
"peer": true
|
|
||||||
},
|
},
|
||||||
"node_modules/tinymce": {
|
"node_modules/tinymce": {
|
||||||
"version": "8.2.2",
|
"version": "8.2.2",
|
||||||
|
|||||||
Reference in New Issue
Block a user