mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-08-10 15:21:22 +02:00
cleanup: sélection multiple + page dédiée (/admin/cleanup.php)
- cleanup-tmp.php: accepte les arrays filepond_dirs[] et trash_files[] pour suppression en lot - cleanup-stats-fragment.php: ajout checkboxes + barre d'actions groupées + formulaire bulk HTMX - admin-cleanup-bulk.js: module JS pour toggleAll, updateBulk, bulkDelete - Nouvelle page /admin/cleanup.php remplace la modale (tmp-cleanup.php supprimé) - Bouton Nettoyer dans index.php devient un lien vers la page dédiée
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* admin-cleanup-bulk.js — Bulk selection and deletion for the temp files cleanup dialog.
|
||||
*
|
||||
* Provides: cleanupToggleAll, cleanupUpdateBulk, cleanupBulkDelete.
|
||||
* All functions are attached to `window` for onclick handlers in PHP templates.
|
||||
*/
|
||||
(() => {
|
||||
function cleanupToggleAll(src, group) {
|
||||
const selector = group === 'filepond'
|
||||
? 'input[name="filepond_dirs[]"]'
|
||||
: 'input[name="trash_files[]"]';
|
||||
document.querySelectorAll(selector).forEach((cb) => {
|
||||
cb.checked = src.checked;
|
||||
});
|
||||
cleanupUpdateBulk();
|
||||
}
|
||||
|
||||
function cleanupUpdateBulk() {
|
||||
const bar = document.getElementById('cleanup-bulk-actions');
|
||||
const countEl = document.getElementById('cleanup-selected-count');
|
||||
if (!bar || !countEl) return;
|
||||
|
||||
const n = document.querySelectorAll(
|
||||
'input[name="filepond_dirs[]"]:checked, input[name="trash_files[]"]:checked'
|
||||
).length;
|
||||
countEl.textContent = n;
|
||||
bar.style.display = n > 0 ? 'flex' : 'none';
|
||||
}
|
||||
|
||||
function cleanupBulkDelete() {
|
||||
const form = document.getElementById('cleanup-bulk-form');
|
||||
const container = document.getElementById('cleanup-bulk-checkboxes');
|
||||
if (!form || !container) return;
|
||||
|
||||
// Populate hidden inputs from checked checkboxes
|
||||
container.innerHTML = '';
|
||||
document.querySelectorAll(
|
||||
'input[name="filepond_dirs[]"]:checked, input[name="trash_files[]"]:checked'
|
||||
).forEach((cb) => {
|
||||
const inp = document.createElement('input');
|
||||
inp.type = 'hidden';
|
||||
inp.name = cb.name; // "filepond_dirs[]" or "trash_files[]"
|
||||
inp.value = cb.value;
|
||||
container.appendChild(inp);
|
||||
});
|
||||
|
||||
// Submit via HTMX
|
||||
htmx.trigger(form, 'submit');
|
||||
}
|
||||
|
||||
function reattachListeners() {
|
||||
document.querySelectorAll(
|
||||
'input[name="filepond_dirs[]"], input[name="trash_files[]"]'
|
||||
).forEach((cb) => {
|
||||
cb.addEventListener('change', cleanupUpdateBulk);
|
||||
});
|
||||
cleanupUpdateBulk();
|
||||
}
|
||||
|
||||
document.addEventListener('htmx:afterSwap', (evt) => {
|
||||
// Only reattach if the swap target is our cleanup wrapper
|
||||
if (evt.detail.target.id === 'tmp-cleanup-stats-wrapper') {
|
||||
reattachListeners();
|
||||
}
|
||||
});
|
||||
|
||||
// Export to global scope for onclick handlers in HTML
|
||||
window.cleanupToggleAll = cleanupToggleAll;
|
||||
window.cleanupUpdateBulk = cleanupUpdateBulk;
|
||||
window.cleanupBulkDelete = cleanupBulkDelete;
|
||||
})();
|
||||
@@ -16,6 +16,7 @@ import "./htmx-global-setup.js";
|
||||
|
||||
// Admin features
|
||||
import "./admin-index-bulk.js";
|
||||
import "./admin-cleanup-bulk.js";
|
||||
import "./admin-tags.js";
|
||||
import "./admin-contenus-langues.js";
|
||||
import "./admin-contenus-motscles.js";
|
||||
|
||||
Reference in New Issue
Block a user