Actualiser js/admin.js
This commit is contained in:
+29
-8
@@ -32,10 +32,25 @@ function renderAdminTable() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Sélection de masse ──
|
// 1. Sélectionner tout
|
||||||
function toggleSelectAll(source) {
|
function toggleSelectAll(source) {
|
||||||
document.querySelectorAll('.film-checkbox').forEach(cb => cb.checked = source.checked);
|
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
|
// Détection de clic sur une case
|
||||||
@@ -63,26 +78,32 @@ async function deleteSingleFilm(id) {
|
|||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. Suppression
|
||||||
async function executeBulkDelete() {
|
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 (ids.length === 0) return;
|
||||||
if (!confirm(`Supprimer ces ${ids.length} films ?`)) return;
|
if (!confirm(`Supprimer ces ${ids.length} films ?`)) return;
|
||||||
|
|
||||||
const token = localStorage.getItem('token');
|
try {
|
||||||
const res = await fetch(`${API_URL}?action=bulk_delete`, {
|
const res = await fetch(`${API_URL}?action=bulk_delete`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': token, // <-- Vérifiez que ce token est bien présent
|
'Authorization': localStorage.getItem('token'),
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ ids, type: currentAdminTab })
|
body: JSON.stringify({ ids: ids, type: currentAdminTab })
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
console.log("Réponse suppression masse :", data);
|
if (data.success) {
|
||||||
|
|
||||||
document.getElementById('bulk-actions-bar').style.display = 'none';
|
document.getElementById('bulk-actions-bar').style.display = 'none';
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Erreur bulk delete :', err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchAdminTab(tabName) {
|
function switchAdminTab(tabName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user