Actualiser js/admin.js
This commit is contained in:
+61
@@ -153,4 +153,65 @@ async function handleCsvUpload(input) {
|
||||
body: formData
|
||||
});
|
||||
loadDashboardData();
|
||||
}
|
||||
|
||||
// ── GESTION SUPPRESSION DE MASSE ──
|
||||
|
||||
// Fonction appelée par le checkbox "Tout cocher"
|
||||
function toggleSelectAll(source) {
|
||||
const checkboxes = document.querySelectorAll('.film-checkbox');
|
||||
checkboxes.forEach(checkbox => checkbox.checked = source.checked);
|
||||
updateBulkBar();
|
||||
}
|
||||
|
||||
// Fonction pour mettre à jour l'affichage de la barre d'actions
|
||||
function updateBulkBar() {
|
||||
const checkboxes = document.querySelectorAll('.film-checkbox:checked');
|
||||
const bulkBar = document.getElementById('bulk-actions-bar');
|
||||
const bulkCount = document.getElementById('bulk-count');
|
||||
|
||||
if (checkboxes.length > 0) {
|
||||
bulkBar.style.display = 'flex';
|
||||
bulkCount.textContent = checkboxes.length;
|
||||
} else {
|
||||
bulkBar.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// Écouteur d'événement pour détecter les clics sur les checkboxes individuelles
|
||||
document.addEventListener('change', (e) => {
|
||||
if (e.target.classList.contains('film-checkbox')) {
|
||||
updateBulkBar();
|
||||
}
|
||||
});
|
||||
|
||||
// Fonction appelée par le bouton "Supprimer la sélection"
|
||||
async function executeBulkDelete() {
|
||||
const selected = Array.from(document.querySelectorAll('.film-checkbox:checked'))
|
||||
.map(cb => cb.value);
|
||||
|
||||
if (selected.length === 0) return;
|
||||
if (!confirm(`Supprimer ces ${selected.length} éléments ?`)) return;
|
||||
|
||||
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: selected, type: currentAdminTab })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
// Réinitialiser la barre après suppression
|
||||
document.getElementById('bulk-actions-bar').style.display = 'none';
|
||||
document.getElementById('select-all-checkbox').checked = false;
|
||||
loadDashboardData();
|
||||
} else {
|
||||
alert("Erreur lors de la suppression.");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Erreur bulk delete :', err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user