mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
Replace browser alert/confirm dialogs with <dialog> modals
- admin/index.php: alert() → no-selection dialog; confirm() bulk actions → bulk-confirm/bulk-delete dialogs; confirm() single delete → delete-thesis dialog; removed redundant confirm on Dépublier (reversible action) - admin/tags.php: confirm() merge/delete → merge-tag/delete-tag dialogs - admin/acces-etudiante.php: confirm() delete link → delete-link dialog - admin/acces.php: confirm() archive link → archive-link dialog - admin/parametres.php: confirm() maintenance/delete-all → enable-maintenance/delete-all-tfe dialogs; admin password confirm() kept with TODO comment - admin/account.php: admin password confirm() kept with TODO comment - admin.css: add .admin-dialog--sm, .admin-dialog__alert, .admin-dialog__footer styles
This commit is contained in:
@@ -9,19 +9,40 @@ function updateBulk() {
|
||||
document.getElementById('selected-count').textContent = checked.length;
|
||||
bulk.style.display = checked.length > 0 ? 'flex' : 'none';
|
||||
}
|
||||
|
||||
// Pending bulk action state
|
||||
let _pendingBulkAction = null;
|
||||
|
||||
function bulkAction(action) {
|
||||
const checked = document.querySelectorAll('input[name="selected_theses[]"]:checked');
|
||||
if (!checked.length) { alert('Sélectionnez au moins un TFE.'); return; }
|
||||
if (!checked.length) {
|
||||
document.getElementById('no-selection-dialog').showModal();
|
||||
return;
|
||||
}
|
||||
_pendingBulkAction = action;
|
||||
let word, endpoint;
|
||||
if (action === 'publish') { word = 'publier'; endpoint = 'actions/publish.php'; }
|
||||
else if (action === 'unpublish') { word = 'dépublier'; endpoint = 'actions/publish.php'; }
|
||||
else if (action === 'delete') { word = 'supprimer'; endpoint = 'actions/delete.php'; }
|
||||
if (action === 'publish') { word = 'publier'; endpoint = 'actions/publish.php'; }
|
||||
else if (action === 'unpublish') { word = 'dépublier'; endpoint = 'actions/publish.php'; }
|
||||
else if (action === 'delete') { word = 'supprimer'; endpoint = 'actions/delete.php'; }
|
||||
else return;
|
||||
if (action === 'delete') {
|
||||
if (!confirm(`Supprimer définitivement ${checked.length} TFE(s) ? Cette action est irréversible.`)) return;
|
||||
document.getElementById('bulk-delete-count').textContent = checked.length;
|
||||
document.getElementById('bulk-delete-dialog').showModal();
|
||||
} else {
|
||||
if (!confirm(`${word.charAt(0).toUpperCase()+word.slice(1)} ${checked.length} TFE(s) ?`)) return;
|
||||
document.getElementById('bulk-confirm-word').textContent = word.charAt(0).toUpperCase() + word.slice(1);
|
||||
document.getElementById('bulk-confirm-count').textContent = checked.length;
|
||||
document.getElementById('bulk-confirm-dialog').showModal();
|
||||
}
|
||||
}
|
||||
|
||||
function _executeBulkAction() {
|
||||
const action = _pendingBulkAction;
|
||||
if (!action) return;
|
||||
let endpoint;
|
||||
if (action === 'publish' || action === 'unpublish') { endpoint = 'actions/publish.php'; }
|
||||
else if (action === 'delete') { endpoint = 'actions/delete.php'; }
|
||||
else return;
|
||||
const checked = document.querySelectorAll('input[name="selected_theses[]"]:checked');
|
||||
document.getElementById('bulk-action-input').value = action;
|
||||
document.getElementById('bulk-form').action = endpoint;
|
||||
const container = document.getElementById('bulk-checkboxes');
|
||||
@@ -33,11 +54,21 @@ function bulkAction(action) {
|
||||
});
|
||||
document.getElementById('bulk-form').submit();
|
||||
}
|
||||
|
||||
// Pending single-delete state
|
||||
let _pendingDeleteId = null;
|
||||
|
||||
function deleteThesis(id, title) {
|
||||
if (!confirm(`Supprimer « ${title} » ?\nCette action est irréversible.`)) return;
|
||||
const form = document.getElementById('delete-form-' + id);
|
||||
_pendingDeleteId = id;
|
||||
document.getElementById('delete-thesis-title').textContent = title;
|
||||
document.getElementById('delete-thesis-dialog').showModal();
|
||||
}
|
||||
|
||||
function _executeDeleteThesis() {
|
||||
const form = document.getElementById('delete-form-' + _pendingDeleteId);
|
||||
if (form) form.submit();
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.querySelectorAll('input[name="selected_theses[]"]').forEach(cb => cb.addEventListener('change', updateBulk));
|
||||
});
|
||||
@@ -202,8 +233,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
<input type="hidden" name="thesis_id" value="<?= $thesis['id'] ?>">
|
||||
<?php if ($thesis['is_published']): ?>
|
||||
<input type="hidden" name="action" value="unpublish">
|
||||
<button type="submit" class="admin-btn-sm admin-btn-unpublish"
|
||||
onclick="return confirm('Retirer de la publication ?')">Dépublier</button>
|
||||
<button type="submit" class="admin-btn-sm admin-btn-unpublish">Dépublier</button>
|
||||
<?php else: ?>
|
||||
<input type="hidden" name="action" value="publish">
|
||||
<button type="submit" class="admin-btn-sm admin-btn-publish">Publier</button>
|
||||
@@ -236,6 +266,73 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
?>
|
||||
</main>
|
||||
|
||||
<!-- ══════════════════════════════════════════════════════════════
|
||||
CONFIRM DIALOGS (replacing browser alert/confirm)
|
||||
══════════════════════════════════════════════════════════════ -->
|
||||
|
||||
<!-- No-selection alert -->
|
||||
<dialog id="no-selection-dialog" class="admin-dialog admin-dialog--sm" aria-labelledby="no-sel-title">
|
||||
<div class="admin-dialog__header">
|
||||
<h2 id="no-sel-title">Aucune sélection</h2>
|
||||
<button type="button" class="admin-dialog__close" aria-label="Fermer"
|
||||
onclick="this.closest('dialog').close()">✕</button>
|
||||
</div>
|
||||
<div class="admin-dialog__alert">
|
||||
<p>Sélectionnez au moins un TFE avant d'effectuer une action groupée.</p>
|
||||
</div>
|
||||
<div class="admin-dialog__footer">
|
||||
<button type="button" class="admin-btn" onclick="this.closest('dialog').close()">OK</button>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<!-- Bulk publish/unpublish confirm -->
|
||||
<dialog id="bulk-confirm-dialog" class="admin-dialog admin-dialog--sm" aria-labelledby="bulk-confirm-title">
|
||||
<div class="admin-dialog__header">
|
||||
<h2 id="bulk-confirm-title">Confirmation</h2>
|
||||
<button type="button" class="admin-dialog__close" aria-label="Fermer"
|
||||
onclick="this.closest('dialog').close()">✕</button>
|
||||
</div>
|
||||
<div class="admin-dialog__alert">
|
||||
<p><span id="bulk-confirm-word"></span> <span id="bulk-confirm-count"></span> TFE(s) ?</p>
|
||||
</div>
|
||||
<div class="admin-dialog__footer">
|
||||
<button type="button" class="admin-btn" onclick="this.closest('dialog').close(); _executeBulkAction()">Confirmer</button>
|
||||
<button type="button" class="admin-btn-secondary" onclick="this.closest('dialog').close()">Annuler</button>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<!-- Bulk delete confirm -->
|
||||
<dialog id="bulk-delete-dialog" class="admin-dialog admin-dialog--sm" aria-labelledby="bulk-delete-title">
|
||||
<div class="admin-dialog__header">
|
||||
<h2 id="bulk-delete-title">Supprimer des TFE</h2>
|
||||
<button type="button" class="admin-dialog__close" aria-label="Fermer"
|
||||
onclick="this.closest('dialog').close()">✕</button>
|
||||
</div>
|
||||
<div class="admin-dialog__alert">
|
||||
<p>Supprimer définitivement <strong><span id="bulk-delete-count"></span> TFE(s)</strong> ? Cette action est irréversible.</p>
|
||||
</div>
|
||||
<div class="admin-dialog__footer">
|
||||
<button type="button" class="admin-btn admin-btn--danger" onclick="this.closest('dialog').close(); _executeBulkAction()">Supprimer</button>
|
||||
<button type="button" class="admin-btn-secondary" onclick="this.closest('dialog').close()">Annuler</button>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<!-- Single thesis delete confirm -->
|
||||
<dialog id="delete-thesis-dialog" class="admin-dialog admin-dialog--sm" aria-labelledby="delete-thesis-title-label">
|
||||
<div class="admin-dialog__header">
|
||||
<h2 id="delete-thesis-title-label">Supprimer ce TFE</h2>
|
||||
<button type="button" class="admin-dialog__close" aria-label="Fermer"
|
||||
onclick="this.closest('dialog').close()">✕</button>
|
||||
</div>
|
||||
<div class="admin-dialog__alert">
|
||||
<p>Supprimer « <strong id="delete-thesis-title"></strong> » ? Cette action est irréversible.</p>
|
||||
</div>
|
||||
<div class="admin-dialog__footer">
|
||||
<button type="button" class="admin-btn admin-btn--danger" onclick="this.closest('dialog').close(); _executeDeleteThesis()">Supprimer</button>
|
||||
<button type="button" class="admin-btn-secondary" onclick="this.closest('dialog').close()">Annuler</button>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<!-- ══════════════════════════════════════════════════════════════
|
||||
IMPORT DIALOG
|
||||
══════════════════════════════════════════════════════════════ -->
|
||||
|
||||
Reference in New Issue
Block a user