Compare commits
2 Commits
baf730af3e
...
f0fbae505f
| Author | SHA1 | Date | |
|---|---|---|---|
| f0fbae505f | |||
| 6b2b45fc6a |
@@ -23,7 +23,7 @@
|
||||
|
||||
<div class="container">
|
||||
<h2 class="mb-5 text-center">Ajouter un article</h2>
|
||||
<form id="ajouterArticleForm" action="../../../blog/categories/articles/liste_article.html" method="GET">
|
||||
<form id="ajouterArticleForm">
|
||||
|
||||
|
||||
<!--Erreur titre vide-->
|
||||
@@ -40,39 +40,40 @@
|
||||
<!--Succès ajout article-->
|
||||
<div id="successMsg" class="alert alert-success d-none">Article ajouté avec succès !</div>
|
||||
|
||||
<!--Catégorie-->
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-bold">Catégorie de l'article</label>
|
||||
<input list="categories" id="articleCategory" class="form-control" placeholder="Entrez une catégorie">
|
||||
<!-- Catégorie -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-bold">Catégorie de l'article</label>
|
||||
<input list="categories" id="articleCategory" class="form-control" placeholder="Entrez une catégorie">
|
||||
|
||||
<datalist id="categories">
|
||||
<option value="actualités">
|
||||
<option value="chien">
|
||||
<option value="chat">
|
||||
<option value="boutique">
|
||||
</datalist>
|
||||
<datalist id="categories">
|
||||
<option value="actualités">
|
||||
<option value="chien">
|
||||
<option value="chat">
|
||||
<option value="boutique">
|
||||
</datalist>
|
||||
</div>
|
||||
|
||||
|
||||
<!--Titre-->
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">Titre de l'article (obligatoire)</label>
|
||||
<input type="text" id="articleTitle" class="form-control" placeholder="Entrez le titre de l'article">
|
||||
</div>
|
||||
<!-- Titre -->
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">Titre de l'article (obligatoire)</label>
|
||||
<input type="text" id="articleTitle" class="form-control" placeholder="Entrez le titre de l'article">
|
||||
</div>
|
||||
|
||||
<!--Contenu-->
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-bold">Contenu de l'article</label>
|
||||
<textarea id="articleContent" class="form-control" rows="5" placeholder="Entrez le contenu de l'article"></textarea>
|
||||
</div>
|
||||
<!-- Contenu -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-bold">Contenu de l'article</label>
|
||||
<textarea id="articleContent" class="form-control" rows="5" placeholder="Entrez le contenu de l'article"></textarea>
|
||||
</div>
|
||||
|
||||
<!-- Image -->
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">Image de l'article</label>
|
||||
<input type="file" id="articleImage" class="form-control" accept="image/*">
|
||||
</div>
|
||||
|
||||
<!--Image-->
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">Image de l'article</label>
|
||||
<input type="file" id="articleImage" class="form-control" accept="image/*">
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<!--Publié-->
|
||||
<div class="form-check mb-3">
|
||||
@@ -44,7 +44,7 @@
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-3 mt-4">
|
||||
<a href="liste_categories.html" class="btn btn-secondary w-50">Annuler</a>
|
||||
<a href="../../../blog/categories/liste_categorie/liste_categorie.html" class="btn btn-secondary w-50">Annuler</a>
|
||||
<button type="submit" class="btn btn-primary w-50">Ajouter</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -37,6 +37,7 @@ form.addEventListener("submit", function (e) {
|
||||
|
||||
|
||||
//Ajout d'une nouvelle catégorie en BDD
|
||||
categoriesExistantes.push(nom);
|
||||
existingCategories.push(nom);
|
||||
|
||||
|
||||
});
|
||||
56
blog/categories/liste_categorie/liste_categorie.html
Normal file
56
blog/categories/liste_categorie/liste_categorie.html
Normal file
@@ -0,0 +1,56 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Liste des catégories</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
|
||||
|
||||
<style>
|
||||
body {
|
||||
background: #f4f6f9;
|
||||
padding: 30px;
|
||||
}
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<h2 class="text-center mb-4">Liste des catégories</h2>
|
||||
|
||||
<!-- Message succès -->
|
||||
<div id="successMsg" class="alert alert-success d-none"></div>
|
||||
|
||||
<!-- Bouton ajouter -->
|
||||
<div class="d-flex justify-content-end mb-4">
|
||||
<a href="../ajouter_categorie/ajouter_categorie.html" class="btn btn-primary">
|
||||
Ajouter une catégorie
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Tableau -->
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Description</th>
|
||||
<th class="text-center">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="categoriesTableBody">
|
||||
<!-- rempli en JS -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script src="liste_categorie.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
52
blog/categories/liste_categorie/liste_categorie.js
Normal file
52
blog/categories/liste_categorie/liste_categorie.js
Normal file
@@ -0,0 +1,52 @@
|
||||
// Simulation BDD
|
||||
let categories = [
|
||||
{ id: 1, nom: "Actualités", description: "Infos et nouveautés" },
|
||||
{ id: 2, nom: "Chien", description: "Articles liés aux chiens" },
|
||||
{ id: 3, nom: "Chat", description: "Conseils pour chats" },
|
||||
{ id: 4, nom: "Boutique", description: "Produits et accessoires" }
|
||||
];
|
||||
|
||||
const tableBody = document.getElementById("categoriesTableBody");
|
||||
const successMsg = document.getElementById("successMsg");
|
||||
|
||||
// Fonction d'affichage
|
||||
function afficherCategories() {
|
||||
tableBody.innerHTML = "";
|
||||
|
||||
categories.forEach((cat, index) => {
|
||||
const row = `
|
||||
<tr>
|
||||
<td>${cat.nom}</td>
|
||||
<td>${cat.description || "-"}</td>
|
||||
|
||||
<td class="text-center">
|
||||
<a href="../modifier_categorie/modifier_categorie.html?id=${cat.id}" class="btn btn-warning btn-sm">
|
||||
Modifier
|
||||
</a>
|
||||
|
||||
<button class="btn btn-danger btn-sm" onclick="supprimerCategorie(${index})">
|
||||
Supprimer
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
tableBody.innerHTML += row;
|
||||
});
|
||||
}
|
||||
|
||||
afficherCategories();
|
||||
|
||||
// Suppression
|
||||
function supprimerCategorie(index) {
|
||||
if (confirm("Voulez-vous vraiment supprimer cette catégorie ?")) {
|
||||
|
||||
const nomCat = categories[index].nom;
|
||||
|
||||
categories.splice(index, 1);
|
||||
|
||||
afficherCategories();
|
||||
|
||||
successMsg.textContent = `La catégorie "${nomCat}" a été supprimée avec succès.`;
|
||||
successMsg.classList.remove("d-none");
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-3 mt-4">
|
||||
<a href="liste_categories.html" class="btn btn-secondary w-50">Annuler</a>
|
||||
<a href="../../categories/liste_categorie/liste_categorie.html" class="btn btn-secondary w-50">Annuler</a>
|
||||
<button type="submit" class="btn btn-primary w-50">Enregistrer</button>
|
||||
</div>
|
||||
|
||||
@@ -8,15 +8,19 @@ const successMsg = document.getElementById("successMsg");
|
||||
form.addEventListener("submit", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
//vérification des champs obligatoires
|
||||
// Vérification des champs obligatoires
|
||||
if (nameField.value.trim() === "" || descField.value.trim() === "") {
|
||||
errorMsg.classList.remove("d-none");
|
||||
successMsg.classList.add("d-none");
|
||||
return;
|
||||
}
|
||||
|
||||
//Succès
|
||||
// Succès
|
||||
errorMsg.classList.add("d-none");
|
||||
successMsg.classList.remove("d-none");
|
||||
|
||||
});
|
||||
// Redirection après succès
|
||||
setTimeout(() => {
|
||||
window.location.href = "../../../blog/categories/liste_categorie/liste_categorie.html";
|
||||
}, 1500);
|
||||
});
|
||||
Reference in New Issue
Block a user