Actualiser js/public.js

This commit is contained in:
2026-06-21 09:19:19 +02:00
parent 8e62de8de2
commit 8a3b10a095
+15 -31
View File
@@ -7,7 +7,6 @@ let searchQuery = '';
let currentPage = 1; let currentPage = 1;
const itemsPerPage = 12; const itemsPerPage = 12;
// ── GÉNÉRATEUR D'ÉTOILES ─
function getStarsHTML(rating) { function getStarsHTML(rating) {
const r = parseFloat(rating) || 0; const r = parseFloat(rating) || 0;
const full = Math.floor(r); const full = Math.floor(r);
@@ -19,12 +18,11 @@ function getStarsHTML(rating) {
return html; return html;
} }
// ── GÉNÉRATION MENU STREAMING ──
function generateStreamingSelect() { function generateStreamingSelect() {
const select = document.getElementById('pub-streaming-select'); const select = document.getElementById('pub-streaming-select');
if (!select) return; if (!select) return;
const platforms = new Set(); const platforms = new Set(); // Fixed: S et -> Set
films.forEach(f => { films.forEach(f => { // Fixed: = > -> =>
if (f.type === 'critique' && f.streaming && if (f.type === 'critique' && f.streaming &&
f.streaming !== 'Disponible en support physique ou Cinéma' && f.streaming !== 'Disponible en support physique ou Cinéma' &&
f.streaming.trim() !== '') { f.streaming.trim() !== '') {
@@ -49,7 +47,6 @@ function generateStreamingSelect() {
}); });
} }
// ── CHARGEMENT ──
async function loadPublicData() { async function loadPublicData() {
try { try {
const response = await fetch(`${API_URL}?action=get_films`); const response = await fetch(`${API_URL}?action=get_films`);
@@ -61,7 +58,6 @@ async function loadPublicData() {
} }
} }
// ── NAVIGATION ONGLETS ──
function switchPubTab(tabName) { function switchPubTab(tabName) {
currentPubTab = tabName; currentPubTab = tabName;
activeRatingFilter = 0; activeRatingFilter = 0;
@@ -72,6 +68,7 @@ function switchPubTab(tabName) {
const ratingBar = document.getElementById('rating-filter-bar'); const ratingBar = document.getElementById('rating-filter-bar');
if (ratingBar) ratingBar.style.display = (tabName === 'critique') ? 'flex' : 'none'; if (ratingBar) ratingBar.style.display = (tabName === 'critique') ? 'flex' : 'none';
if (select) select.style.display = (tabName === 'critique') ? 'block' : 'none'; if (select) select.style.display = (tabName === 'critique') ? 'block' : 'none';
document.querySelectorAll('.rating-filter-btn').forEach(btn => { document.querySelectorAll('.rating-filter-btn').forEach(btn => {
btn.classList.remove('active'); btn.classList.remove('active');
btn.querySelectorAll('.rf-star').forEach(s => s.classList.remove('filled')); btn.querySelectorAll('.rf-star').forEach(s => s.classList.remove('filled'));
@@ -82,7 +79,6 @@ function switchPubTab(tabName) {
renderPublicGrid(); renderPublicGrid();
} }
// ── FILTRE PAR NOTE (regroupement : 5★ = 4.5+5, 4★ = 3.5+4, etc.) ──
function filterByRating(stars) { function filterByRating(stars) {
if (currentPubTab !== 'critique') return; if (currentPubTab !== 'critique') return;
activeRatingFilter = (activeRatingFilter === stars) ? 0 : stars; activeRatingFilter = (activeRatingFilter === stars) ? 0 : stars;
@@ -96,7 +92,6 @@ function filterByRating(stars) {
renderPublicGrid(); renderPublicGrid();
} }
// ── RENDU GRILLE ──
function renderPublicGrid() { function renderPublicGrid() {
const grid = document.getElementById('grid'); const grid = document.getElementById('grid');
const emptyState = document.getElementById('empty-state'); const emptyState = document.getElementById('empty-state');
@@ -131,11 +126,11 @@ function renderPublicGrid() {
} }
if (countLabel) { if (countLabel) {
countLabel.textContent = `${filtered.length} ${currentPubTab === 'critique' ? 'critique' : 'œuvre'}${filtered.length > 1 ? 's' : ''}`; countLabel.textContent = `${filtered.length} ${currentPubTab === 'critique' ? 'critique' : 'œuvre'}${filtered.length > 1 ? 's' : ''}`; // Fixed: filtere d -> filtered
} }
if (filtered.length === 0) { if (filtered.length === 0) {
if (emptyState) emptyState.style.display = 'block'; if (emptyState) emptyState.style.display = 'block'; // Fixed: di splay -> display
renderPagination(0); renderPagination(0);
return; return;
} }
@@ -194,7 +189,6 @@ function renderPublicGrid() {
renderPagination(totalPages); renderPagination(totalPages);
} }
// ── PAGINATION ──
function renderPagination(totalPages) { function renderPagination(totalPages) {
const container = document.getElementById('pub-pagination'); const container = document.getElementById('pub-pagination');
if (!container) return; if (!container) return;
@@ -206,14 +200,14 @@ function renderPagination(totalPages) {
info.textContent = `Page ${currentPage} / ${totalPages}`; info.textContent = `Page ${currentPage} / ${totalPages}`;
container.appendChild(info); container.appendChild(info);
const prevBtn = document.createElement('button'); const prevBtn = document.createElement('button'); // Fixed: p revBtn -> prevBtn
prevBtn.innerHTML = '<i class="ti ti-chevron-left"></i>'; prevBtn.innerHTML = '<i class="ti ti-chevron-left"></i>';
prevBtn.disabled = currentPage === 1; prevBtn.disabled = currentPage === 1;
prevBtn.onclick = () => { currentPage--; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); }; prevBtn.onclick = () => { currentPage--; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); };
container.appendChild(prevBtn); container.appendChild(prevBtn);
const maxButtons = 5; const maxButtons = 5;
let startPage = Math.max(1, currentPage - Math.floor(maxButtons / 2)); let startPage = Math.max(1, currentPage - Math.floor(maxButtons / 2)); // Fixed: curren tPage -> currentPage
let endPage = Math.min(totalPages, startPage + maxButtons - 1); let endPage = Math.min(totalPages, startPage + maxButtons - 1);
if (endPage - startPage + 1 < maxButtons) { if (endPage - startPage + 1 < maxButtons) {
startPage = Math.max(1, endPage - maxButtons + 1); startPage = Math.max(1, endPage - maxButtons + 1);
@@ -229,8 +223,9 @@ function renderPagination(totalPages) {
if (endPage < totalPages - 1) container.appendChild(createPubEllipsis()); if (endPage < totalPages - 1) container.appendChild(createPubEllipsis());
container.appendChild(createPubPageBtn(totalPages)); container.appendChild(createPubPageBtn(totalPages));
} }
const nextBtn = document.createElement('button'); const nextBtn = document.createElement('button');
nextBtn.innerHTML = '<i class="ti ti-chevron-right"></i>'; nextBtn.innerHTML = '<i class="ti ti-chevron-right"></i>'; // Fixed: i nnerHTML -> innerHTML
nextBtn.disabled = currentPage === totalPages; nextBtn.disabled = currentPage === totalPages;
nextBtn.onclick = () => { currentPage++; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); }; nextBtn.onclick = () => { currentPage++; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); };
container.appendChild(nextBtn); container.appendChild(nextBtn);
@@ -252,7 +247,6 @@ function createPubEllipsis() {
return span; return span;
} }
// ── DÉTAIL ──
function openDetail(id) { function openDetail(id) {
const f = films.find(item => item.id == id); const f = films.find(item => item.id == id);
if (!f) return; if (!f) return;
@@ -261,14 +255,14 @@ function openDetail(id) {
const dTitle = document.getElementById('d-title'); const dTitle = document.getElementById('d-title');
const dMeta = document.getElementById('d-meta'); const dMeta = document.getElementById('d-meta');
const dBody = document.getElementById('d-body'); const dBody = document.getElementById('d-body');
const detailModalLayout = document.getElementById('detail-modal-layout'); const detailModalLayout = document.getElementById('detail-modal-layout'); // Fixed: detailModalLa yout
const detailOverlay = document.getElementById('detail-overlay'); const detailOverlay = document.getElementById('detail-overlay');
if (f.poster) { if (f.poster) {
if (dPoster) dPoster.src = f.poster; if (dPoster) dPoster.src = f.poster;
if (dPosterWrap) { if (dPosterWrap) {
dPosterWrap.style.display = 'block'; dPosterWrap.style.display = 'block';
dPosterWrap.className = `detail-poster poster-${f.type}`; dPosterWrap.className = `detail-poster poster-${f.type}`; // Fixed: poster-$ {f.type}
} }
if (detailModalLayout) detailModalLayout.classList.remove('no-poster'); if (detailModalLayout) detailModalLayout.classList.remove('no-poster');
} else { } else {
@@ -277,7 +271,7 @@ function openDetail(id) {
} }
if (dTitle) dTitle.textContent = f.title; if (dTitle) dTitle.textContent = f.title;
if (dMeta) dMeta.textContent = `${f.year ? f.year + ' | ' : ''}${f.director || 'Réalisateur inconnu'}`; if (dMeta) dMeta.textContent = `${f.year ? f.year + ' | ' : ''}${f.director || 'Réalisateur inconnu'}`; // Fixed: Réa lisateur
if (dBody) { if (dBody) {
if (f.type === 'critique') { if (f.type === 'critique') {
@@ -298,18 +292,9 @@ function openDetail(id) {
${f.number_of_discs ? `<span class="tech-pill"><i class="ti ti-layers-intersect"></i> ${f.number_of_discs} Disque(s)</span>` : ''} ${f.number_of_discs ? `<span class="tech-pill"><i class="ti ti-layers-intersect"></i> ${f.number_of_discs} Disque(s)</span>` : ''}
</div> </div>
<div class="pub-tech-grid"> <div class="pub-tech-grid">
<div class="tech-meta-item"> <div class="tech-meta-item"><span class="tech-meta-label">Éditeur</span><span class="tech-meta-value">${f.publisher || '—'}</span></div>
<span class="tech-meta-label">Éditeur</span> <div class="tech-meta-item"><span class="tech-meta-label">Format Image</span><span class="tech-meta-value">${f.aspect_ratio || '—'}</span></div>
<span class="tech-meta-value">${f.publisher || '&mdash;'}</span> <div class="tech-meta-item" style="grid-column: span 2;"><span class="tech-meta-label">Code Barre (EAN)</span><span class="tech-meta-value">${f.ean_isbn13 || ''}</span></div>
</div>
<div class="tech-meta-item">
<span class="tech-meta-label">Format Image</span>
<span class="tech-meta-value">${f.aspect_ratio || '&mdash;'}</span>
</div>
<div class="tech-meta-item" style="grid-column: span 2;">
<span class="tech-meta-label">Code Barre (EAN)</span>
<span class="tech-meta-value">${f.ean_isbn13 || '&mdash;'}</span>
</div>
</div> </div>
<div class="pub-synopsis-box"> <div class="pub-synopsis-box">
<h4>Synopsis / Notes</h4> <h4>Synopsis / Notes</h4>
@@ -326,7 +311,6 @@ function closeDetail() {
if (detailOverlay) detailOverlay.classList.remove('open'); if (detailOverlay) detailOverlay.classList.remove('open');
} }
// ── INITIALISATION ──
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
loadPublicData(); loadPublicData();
const searchInput = document.getElementById('pub-search-input'); const searchInput = document.getElementById('pub-search-input');