Actualiser js/admin.js

This commit is contained in:
2026-06-18 13:36:51 +02:00
parent fb7e0c87a7
commit 4b7a0cfdd8
+39 -18
View File
@@ -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) {