ajout de liste_categorie + reprise des chemins
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
});
|
||||
@@ -1,104 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Ajouter un article</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
|
||||
<script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/ckeditor.js"></script>
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
body {
|
||||
background: #f4f6f9;
|
||||
}
|
||||
.container {
|
||||
max-width: 700px;
|
||||
margin: 40px auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<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">
|
||||
|
||||
|
||||
<!--Erreur titre vide-->
|
||||
<div id="errorEmpty" class="alert alert-danger d-none">Le titre de l'article est obligatoire</div>
|
||||
|
||||
<!--Erreur image invalide-->
|
||||
<div id="errorImage" class="alert alert-danger d-none">
|
||||
Format d'image invalide. Formats acceptés : JPG, PNG
|
||||
</div>
|
||||
|
||||
<!--Erreur titre existant-->
|
||||
<div id="errorExists" class="alert alert-danger d-none">Ce titre existe déjà. Choisissez un autre titre.</div>
|
||||
|
||||
<!--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">
|
||||
|
||||
<datalist id="categories">
|
||||
<option value="actualités">
|
||||
<option value="chien">
|
||||
<option value="chat">
|
||||
<option value="boutique">
|
||||
</datalist>
|
||||
|
||||
|
||||
<!--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>
|
||||
|
||||
<!--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">
|
||||
<input class="form-check-input" type="checkbox" id="articlePublished">
|
||||
<label class="form-check-label" for="articlePublished">Publié</label>
|
||||
</div>
|
||||
|
||||
|
||||
<!--Boutons-->
|
||||
<div class="d-flex gap-3 mt-4">
|
||||
<a href="../../../blog/categories/articles/liste_article.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="ajouter_article.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
ClassicEditor
|
||||
.create(document.querySelector('#articleContent'))
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,52 +0,0 @@
|
||||
const form = document.getElementById('addArticleForm');
|
||||
const imgField = document.getElementById('articleImage');
|
||||
const titleField = document.getElementById('articleTitle');
|
||||
const contentField = document.getElementById('articleContent');
|
||||
const categoryField = document.getElementById('articleCategory');
|
||||
const publishedField = document.getElementById('articlePublished');
|
||||
|
||||
const errorEmpty = document.getElementById('errorEmpty');
|
||||
const errorImage = document.getElementById('errorImage');
|
||||
const errorExists = document.getElementById('errorExists');
|
||||
const successMsg = document.getElementById('successMsg');
|
||||
|
||||
// Simulation BDD
|
||||
const titreExistants = ['décoration noel', 'coupe de chien'];
|
||||
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const titre = titleField.value.trim() .toLowerCase();
|
||||
const fichierImage = imgField.files[0];
|
||||
|
||||
// Reset messages
|
||||
errorEmpty.classList.add('d-none');
|
||||
errorImage.classList.add('d-none');
|
||||
errorExists.classList.add('d-none');
|
||||
successMsg.classList.add('d-none');
|
||||
|
||||
// Titre obligatoire
|
||||
if (titre === "") {
|
||||
errorEmpty.classList.remove('d-none');
|
||||
return;
|
||||
}
|
||||
|
||||
// Titre déjà existant
|
||||
if (titreExistants.includes(titre)) {
|
||||
errorExists.classList.remove('d-none');
|
||||
return;
|
||||
}
|
||||
|
||||
// Image invalide
|
||||
if (fichierImage) {
|
||||
const validFormats = ['image/jpeg', 'image/png'];
|
||||
if (!validFormats.includes(fichierImage.type)) {
|
||||
errorImage.classList.remove('d-none');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Simuler enregistrement
|
||||
titreExistants.push(titre);
|
||||
|
||||
});
|
||||
@@ -1,57 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Liste des article</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
|
||||
|
||||
<style>
|
||||
body {
|
||||
background: #f4f6f9;
|
||||
}
|
||||
.container {
|
||||
margin-top: 60px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h2 class="mb-0">Listes des articles</h2>
|
||||
<a href="ajouter_article.html" class="btn btn-primary">Ajouter un article</a>
|
||||
</div>
|
||||
|
||||
<table class="table table-bordered table-hover bg-white">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Titre</th>
|
||||
<th>Catégorie</th>
|
||||
<th>Publié</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<!--Exemple d'article-->
|
||||
<tr>
|
||||
<td>Mon premier article</td>
|
||||
<td>Chien</td>
|
||||
<td>Oui</td>
|
||||
<td>
|
||||
<a href="voir_article.html" class="btn btn-sm btn-outline-secondary">Voir</a>
|
||||
<a href="modifier_article.html" class="btn btn-sm btn-outline-primary">Modifier</a>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="confirmerSuppression('Mon premier article')">Supprimer</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +0,0 @@
|
||||
function confirmerSuppression(titre) {
|
||||
const confirmation = confirm(`Êtes-vous sûr de vouloir supprimer l'article "${titre}" ?`);
|
||||
if (confirmation) {
|
||||
alert(`L'article "${titre}" a été supprimé.`);
|
||||
// Ici tu peux rediriger ou supprimer réellement
|
||||
}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Modifier un article</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
|
||||
<script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/ckeditor.js"></script>
|
||||
|
||||
|
||||
<style>
|
||||
body {
|
||||
background: #f4f6f9;
|
||||
}
|
||||
.container {
|
||||
max-width: 700px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
.preview-img {
|
||||
max-width: 15Opx;
|
||||
border-radius: 8px
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<h2 class="mb-4 text-center">Modifier un article</h2>
|
||||
|
||||
<!--Erreur titre vide-->
|
||||
<div id="errorEmpty" class="alert alert-danger d-none">
|
||||
g Le titre de l'article est obligatoire.
|
||||
</div>
|
||||
|
||||
<!--Erreur image invalide-->
|
||||
<div id="errorImage" class="alert alert-danger d-none">
|
||||
Format d'image invalide. Formats acceptés : JPG, PNG, GIF.
|
||||
</div>
|
||||
|
||||
<!--Erreur titre existant-->
|
||||
<div id="errorExists" class="alert alert-danger d-none">
|
||||
Ce titre existe déjà. Veuillez en choisir un autre.
|
||||
</div>
|
||||
|
||||
<!--Succès-->
|
||||
<div id="successMsg" class="alert alert-success d-none">
|
||||
L'article a été modifié avec succès !
|
||||
</div>
|
||||
|
||||
<!-- Formulaire -->
|
||||
<form id="editArticleForm">
|
||||
|
||||
|
||||
|
||||
<!--Titre-->
|
||||
<div class="mb-3">
|
||||
<label class="form-label fw-bold">Titre de l'article (obligatoire)</label>
|
||||
<input type="text" id="articleTitle" class="form-control" value="Titre de l'article actuel" placeholder="Modifier le titre">
|
||||
</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">Contenu de l'article actuel...</textarea>
|
||||
</div>
|
||||
|
||||
<!--Catégorie-->
|
||||
<div class="mb-4">
|
||||
<label class="form-label fw-bold">Catégorie de l'article</label>
|
||||
<input
|
||||
type="text"
|
||||
id="articleCategory"
|
||||
class="form-control"
|
||||
list="categories"
|
||||
placeholder="Entrez une catégorie">
|
||||
|
||||
<datalist id="categories">
|
||||
<option value="actualités">
|
||||
<option value="chien">
|
||||
<option value="chat">
|
||||
<option value="boutique">
|
||||
</datalist>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Image actuelle -->
|
||||
<label class="fw-bold">Image actuelle</label>
|
||||
<div class="mb-4">
|
||||
<img src="/blog/categories/images/article1.jpg" alt="Image actuelle" class="preview-img mb-2">
|
||||
<input type="file" id="articleImage" class="form-control" accept="image/*">
|
||||
</div>
|
||||
|
||||
<!--Publié-->
|
||||
<div class="form-check mb-3">
|
||||
<input class="form-check-input" type="checkbox" id="articlePublished" checked>
|
||||
<label class="form-check-label">Publié</label>
|
||||
</div>
|
||||
|
||||
<!--Boutons-->
|
||||
<div class="d-flex gap-3 mt-4">
|
||||
<a href="../../../blog/categories/articles/liste_article.html" class="btn btn-secondary w-50">Annuler</a>
|
||||
<button type="submit" class="btn btn-primary w-50">Enregistrer</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
ClassicEditor
|
||||
.create(document.querySelector('#articleContent'))
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
</script>
|
||||
|
||||
<script src="modifier_article.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
const form = document.getElementById('editArticleForm');
|
||||
const imgField = document.getElementById('articleImage');
|
||||
const titleField = document.getElementById('articleTitle');
|
||||
const contentField = document.getElementById('articleContent');
|
||||
const categoryField = document.getElementById('articleCategory');
|
||||
const publishedField = document.getElementById('articlePublished');
|
||||
|
||||
const errorEmpty = document.getElementById('errorEmpty');
|
||||
const errorImage = document.getElementById('errorImage');
|
||||
const errorExists = document.getElementById('errorExists');
|
||||
const successMsg = document.getElementById('successMsg');
|
||||
|
||||
// Simulation BDD pour vérifier doublons
|
||||
const titresExistants = [
|
||||
"article de test",
|
||||
"nouveautés chiens",
|
||||
"actualité du mois"
|
||||
];
|
||||
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const titre = titleField.value.trim().toLowerCase();
|
||||
const fichierImage = imgField.files[0];
|
||||
|
||||
// Reset messages
|
||||
errorEmpty.classList.add('d-none');
|
||||
errorImage.classList.add('d-none');
|
||||
errorExists.classList.add('d-none');
|
||||
successMsg.classList.add('d-none');
|
||||
|
||||
//Titre obligatoire
|
||||
if (titre === "") {
|
||||
errorEmpty.classList.remove('d-none');
|
||||
return;
|
||||
}
|
||||
|
||||
// Titre déjà existant ?
|
||||
if (titresExistants.includes(titre)) {
|
||||
errorExists.classList.remove('d-none');
|
||||
return;
|
||||
}
|
||||
|
||||
//Vérification image
|
||||
if (fichierImage) {
|
||||
const validFormats = ['image/jpeg', 'image/png', 'image/gif'];
|
||||
if (!validFormats.includes(fichierImage.type)) {
|
||||
errorImage.classList.remove('d-none');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Succès
|
||||
successMsg.classList.remove('d-none');
|
||||
|
||||
console.log("Article modifié :", {
|
||||
titre,
|
||||
contenu: contentField.value,
|
||||
categorie: categoryField.value,
|
||||
publie: publishedField.checked,
|
||||
image: fichierImage ? fichierImage.name : "Image inchangée"
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
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