diff --git a/blog/html/modifier_article.html b/blog/html/modifier_article.html index 091bbff..56c423b 100644 --- a/blog/html/modifier_article.html +++ b/blog/html/modifier_article.html @@ -152,7 +152,7 @@
- +
diff --git a/blog/js/ajouter_article.js b/blog/js/ajouter_article.js index 3224329..298d7d1 100644 --- a/blog/js/ajouter_article.js +++ b/blog/js/ajouter_article.js @@ -19,7 +19,7 @@ form.addEventListener('submit', function(e) { const fichierImage = imgField.files[0]; const contenu = tinymce.get("articleContent").getContent(); const categorie = categoryField.value; - const published = publishedField.checked; // ← récupère la case cochée + const published = publishedField.checked; // récupère la case cochée // Reset messages errorEmpty.classList.add('d-none'); @@ -92,7 +92,7 @@ form.addEventListener('submit', function(e) { // Redirection setTimeout(() => { - window.location.href = "../html/liste_categorie_article.html"; + window.location.href = "../html/accueil_blog.html"; }, 1000); }); diff --git a/blog/js/liste_articles.js b/blog/js/liste_articles.js index f562797..d3a17de 100644 --- a/blog/js/liste_articles.js +++ b/blog/js/liste_articles.js @@ -1,14 +1,67 @@ +// Sélecteur du tableau +const articlesTableBody = document.getElementById("articlesTableBody"); +// Charger les articles depuis le localStorage +let articles = JSON.parse(localStorage.getItem("articles")) || []; + +// Fonction d'affichage des articles +function afficherArticles() { + articlesTableBody.innerHTML = ""; // Nettoie le tableau + + if (articles.length === 0) { + articlesTableBody.innerHTML = ` + + + Aucun article pour le moment. + + + `; + return; + } + + articles.forEach(article => { + const tr = document.createElement("tr"); + + tr.innerHTML = ` + + ${article.titre} + ${article.published ? 'Publié Facebook' : ''} + + + Modifier + + + + `; + + articlesTableBody.appendChild(tr); + }); +} + +// Gestion de suppression document.addEventListener("click", function (e) { const btn = e.target.closest(".delete-btn"); - if (!btn) return; // on a cliqué ailleurs + if (!btn) return; - // On récupère la ligne de l'article const row = btn.closest("tr"); const titre = row.querySelector("td").textContent.trim(); + const id = Number(btn.dataset.id); if (confirm(`Voulez-vous vraiment supprimer l'article : "${titre}" ?`)) { - row.remove(); // supprime la ligne + + // Supprimer dans le tableau local + articles = articles.filter(article => article.id !== id); + localStorage.setItem("articles", JSON.stringify(articles)); + + // Supprimer visuel + row.remove(); + alert("Article supprimé !"); } -}); \ No newline at end of file +}); + +// Lancer l'affichage dès que la page charge +afficherArticles();