From 4b7a0cfdd84eefb309056bea76487ccceb3e262f Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 18 Jun 2026 13:36:51 +0200 Subject: [PATCH] Actualiser js/admin.js --- js/admin.js | 57 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/js/admin.js b/js/admin.js index e174d24..df9446e 100644 --- a/js/admin.js +++ b/js/admin.js @@ -32,10 +32,25 @@ function renderAdminTable() { }); } -// ── Sélection de masse ── +// 1. Sélectionner tout function toggleSelectAll(source) { document.querySelectorAll('.film-checkbox').forEach(cb => cb.checked = source.checked); - document.getElementById('bulk-actions-bar').style.display = source.checked ? 'flex' : 'none'; + updateBulkBar(); +} + +// 2. Mettre à jour la barre (appelée par chaque clic sur une checkbox) +function updateBulkBar() { + const checked = document.querySelectorAll('.film-checkbox:checked'); + const bulkBar = document.getElementById('bulk-actions-bar'); + const bulkCount = document.getElementById('bulk-count'); + + if (checked.length > 0) { + bulkBar.style.display = 'flex'; + bulkCount.textContent = checked.length; + } else { + bulkBar.style.display = 'none'; + document.getElementById('select-all-checkbox').checked = false; + } } // Détection de clic sur une case @@ -63,26 +78,32 @@ async function deleteSingleFilm(id) { loadDashboardData(); } +// 3. Suppression async function executeBulkDelete() { - const ids = Array.from(document.querySelectorAll('.film-checkbox:checked')).map(cb => cb.value); + const checked = document.querySelectorAll('.film-checkbox:checked'); + const ids = Array.from(checked).map(cb => cb.value); + if (ids.length === 0) return; if (!confirm(`Supprimer ces ${ids.length} films ?`)) return; - const token = localStorage.getItem('token'); - const res = await fetch(`${API_URL}?action=bulk_delete`, { - method: 'POST', - headers: { - 'Authorization': token, // <-- Vérifiez que ce token est bien présent - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ ids, type: currentAdminTab }) - }); - - const data = await res.json(); - console.log("Réponse suppression masse :", data); - - document.getElementById('bulk-actions-bar').style.display = 'none'; - loadDashboardData(); + try { + const res = await fetch(`${API_URL}?action=bulk_delete`, { + method: 'POST', + headers: { + 'Authorization': localStorage.getItem('token'), + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ ids: ids, type: currentAdminTab }) + }); + + const data = await res.json(); + if (data.success) { + document.getElementById('bulk-actions-bar').style.display = 'none'; + loadDashboardData(); + } + } catch (err) { + console.error('Erreur bulk delete :', err); + } } function switchAdminTab(tabName) {