- Galerie admin : onglet avec sélection photos + impression par lot - Compteur : compte les copies (×N) et non plus 1 par impression - Flash blanc immédiat après countdown pour masquer le délai AF - Erreur imprimante : petit toast discret au lieu de bannière plein écran Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
117 lines
3.6 KiB
JavaScript
117 lines
3.6 KiB
JavaScript
/* Module galerie */
|
|
|
|
async function chargerGalerie() {
|
|
const photos = await apiGet('/api/galerie');
|
|
const grille = document.getElementById('grille-galerie');
|
|
grille.innerHTML = '';
|
|
|
|
if (photos.length === 0) {
|
|
grille.innerHTML = '<p style="color:var(--texte-secondaire);grid-column:1/-1;text-align:center">Aucune photo pour le moment</p>';
|
|
return;
|
|
}
|
|
|
|
for (const photo of photos) {
|
|
const img = document.createElement('img');
|
|
img.src = '/' + photo.chemin;
|
|
img.alt = photo.nom;
|
|
img.loading = 'lazy';
|
|
img.addEventListener('click', () => voirPhoto(photo));
|
|
grille.appendChild(img);
|
|
}
|
|
}
|
|
|
|
function voirPhoto(photo) {
|
|
photoFinale = photo.nom;
|
|
document.getElementById('photo-partage').src = '/' + photo.chemin;
|
|
allerA('partage');
|
|
}
|
|
|
|
/* --- Admin gallery --- */
|
|
|
|
let adminGaleriePhotos = [];
|
|
let adminGalerieSelection = new Set();
|
|
|
|
async function chargerAdminGalerie() {
|
|
const photos = await apiGet('/api/galerie');
|
|
adminGaleriePhotos = photos;
|
|
adminGalerieSelection.clear();
|
|
const grille = document.getElementById('admin-galerie-grille');
|
|
grille.innerHTML = '';
|
|
|
|
if (photos.length === 0) {
|
|
grille.innerHTML = '<p style="color:var(--texte-secondaire);grid-column:1/-1;text-align:center">Aucune photo</p>';
|
|
majAdminGalerieSelection();
|
|
return;
|
|
}
|
|
|
|
for (const photo of photos) {
|
|
const wrap = document.createElement('div');
|
|
wrap.style.cssText = 'position:relative;cursor:pointer';
|
|
wrap.dataset.nom = photo.nom;
|
|
|
|
const img = document.createElement('img');
|
|
img.src = '/' + photo.chemin;
|
|
img.alt = photo.nom;
|
|
img.loading = 'lazy';
|
|
img.style.cssText = 'width:100%;border-radius:8px;display:block';
|
|
|
|
const check = document.createElement('div');
|
|
check.className = 'admin-galerie-check';
|
|
check.textContent = '✓';
|
|
|
|
wrap.appendChild(img);
|
|
wrap.appendChild(check);
|
|
wrap.addEventListener('click', () => toggleAdminGaleriePhoto(photo.nom, wrap));
|
|
grille.appendChild(wrap);
|
|
}
|
|
majAdminGalerieSelection();
|
|
}
|
|
|
|
function toggleAdminGaleriePhoto(nom, wrap) {
|
|
if (adminGalerieSelection.has(nom)) {
|
|
adminGalerieSelection.delete(nom);
|
|
wrap.querySelector('.admin-galerie-check').classList.remove('visible');
|
|
} else {
|
|
adminGalerieSelection.add(nom);
|
|
wrap.querySelector('.admin-galerie-check').classList.add('visible');
|
|
}
|
|
majAdminGalerieSelection();
|
|
}
|
|
|
|
function adminGalerieSelectAll() {
|
|
const grille = document.getElementById('admin-galerie-grille');
|
|
for (const photo of adminGaleriePhotos) {
|
|
adminGalerieSelection.add(photo.nom);
|
|
}
|
|
grille.querySelectorAll('.admin-galerie-check').forEach(c => c.classList.add('visible'));
|
|
majAdminGalerieSelection();
|
|
}
|
|
|
|
function adminGalerieDeselectAll() {
|
|
adminGalerieSelection.clear();
|
|
const grille = document.getElementById('admin-galerie-grille');
|
|
grille.querySelectorAll('.admin-galerie-check').forEach(c => c.classList.remove('visible'));
|
|
majAdminGalerieSelection();
|
|
}
|
|
|
|
function majAdminGalerieSelection() {
|
|
const span = document.getElementById('admin-galerie-selection');
|
|
const n = adminGalerieSelection.size;
|
|
span.textContent = n > 0 ? n + ' selectionnee' + (n > 1 ? 's' : '') : '';
|
|
}
|
|
|
|
async function adminGalerieImprimer() {
|
|
const noms = [...adminGalerieSelection];
|
|
if (noms.length === 0) return;
|
|
if (!confirm('Imprimer ' + noms.length + ' photo' + (noms.length > 1 ? 's' : '') + ' ?')) return;
|
|
|
|
let ok = 0, fail = 0;
|
|
for (const nom of noms) {
|
|
try {
|
|
const r = await apiPost('/api/imprimer', { photo: nom });
|
|
if (r && r.succes) ok++; else fail++;
|
|
} catch { fail++; }
|
|
}
|
|
alert('Impression : ' + ok + ' OK' + (fail > 0 ? ', ' + fail + ' echec' : ''));
|
|
}
|