Actualiser js/public.js
This commit is contained in:
+15
-31
@@ -7,7 +7,6 @@ let searchQuery = '';
|
||||
let currentPage = 1;
|
||||
const itemsPerPage = 12;
|
||||
|
||||
// ── GÉNÉRATEUR D'ÉTOILES ─
|
||||
function getStarsHTML(rating) {
|
||||
const r = parseFloat(rating) || 0;
|
||||
const full = Math.floor(r);
|
||||
@@ -19,12 +18,11 @@ function getStarsHTML(rating) {
|
||||
return html;
|
||||
}
|
||||
|
||||
// ── GÉNÉRATION MENU STREAMING ──
|
||||
function generateStreamingSelect() {
|
||||
const select = document.getElementById('pub-streaming-select');
|
||||
if (!select) return;
|
||||
const platforms = new Set();
|
||||
films.forEach(f => {
|
||||
const platforms = new Set(); // Fixed: S et -> Set
|
||||
films.forEach(f => { // Fixed: = > -> =>
|
||||
if (f.type === 'critique' && f.streaming &&
|
||||
f.streaming !== 'Disponible en support physique ou Cinéma' &&
|
||||
f.streaming.trim() !== '') {
|
||||
@@ -49,7 +47,6 @@ function generateStreamingSelect() {
|
||||
});
|
||||
}
|
||||
|
||||
// ── CHARGEMENT ──
|
||||
async function loadPublicData() {
|
||||
try {
|
||||
const response = await fetch(`${API_URL}?action=get_films`);
|
||||
@@ -61,7 +58,6 @@ async function loadPublicData() {
|
||||
}
|
||||
}
|
||||
|
||||
// ── NAVIGATION ONGLETS ──
|
||||
function switchPubTab(tabName) {
|
||||
currentPubTab = tabName;
|
||||
activeRatingFilter = 0;
|
||||
@@ -72,6 +68,7 @@ function switchPubTab(tabName) {
|
||||
const ratingBar = document.getElementById('rating-filter-bar');
|
||||
if (ratingBar) ratingBar.style.display = (tabName === 'critique') ? 'flex' : 'none';
|
||||
if (select) select.style.display = (tabName === 'critique') ? 'block' : 'none';
|
||||
|
||||
document.querySelectorAll('.rating-filter-btn').forEach(btn => {
|
||||
btn.classList.remove('active');
|
||||
btn.querySelectorAll('.rf-star').forEach(s => s.classList.remove('filled'));
|
||||
@@ -82,7 +79,6 @@ function switchPubTab(tabName) {
|
||||
renderPublicGrid();
|
||||
}
|
||||
|
||||
// ── FILTRE PAR NOTE (regroupement : 5★ = 4.5+5, 4★ = 3.5+4, etc.) ──
|
||||
function filterByRating(stars) {
|
||||
if (currentPubTab !== 'critique') return;
|
||||
activeRatingFilter = (activeRatingFilter === stars) ? 0 : stars;
|
||||
@@ -96,7 +92,6 @@ function filterByRating(stars) {
|
||||
renderPublicGrid();
|
||||
}
|
||||
|
||||
// ── RENDU GRILLE ──
|
||||
function renderPublicGrid() {
|
||||
const grid = document.getElementById('grid');
|
||||
const emptyState = document.getElementById('empty-state');
|
||||
@@ -131,11 +126,11 @@ function renderPublicGrid() {
|
||||
}
|
||||
|
||||
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 (emptyState) emptyState.style.display = 'block';
|
||||
if (emptyState) emptyState.style.display = 'block'; // Fixed: di splay -> display
|
||||
renderPagination(0);
|
||||
return;
|
||||
}
|
||||
@@ -194,7 +189,6 @@ function renderPublicGrid() {
|
||||
renderPagination(totalPages);
|
||||
}
|
||||
|
||||
// ── PAGINATION ──
|
||||
function renderPagination(totalPages) {
|
||||
const container = document.getElementById('pub-pagination');
|
||||
if (!container) return;
|
||||
@@ -206,14 +200,14 @@ function renderPagination(totalPages) {
|
||||
info.textContent = `Page ${currentPage} / ${totalPages}`;
|
||||
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.disabled = currentPage === 1;
|
||||
prevBtn.onclick = () => { currentPage--; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); };
|
||||
container.appendChild(prevBtn);
|
||||
|
||||
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);
|
||||
if (endPage - startPage + 1 < maxButtons) {
|
||||
startPage = Math.max(1, endPage - maxButtons + 1);
|
||||
@@ -229,8 +223,9 @@ function renderPagination(totalPages) {
|
||||
if (endPage < totalPages - 1) container.appendChild(createPubEllipsis());
|
||||
container.appendChild(createPubPageBtn(totalPages));
|
||||
}
|
||||
|
||||
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.onclick = () => { currentPage++; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); };
|
||||
container.appendChild(nextBtn);
|
||||
@@ -252,7 +247,6 @@ function createPubEllipsis() {
|
||||
return span;
|
||||
}
|
||||
|
||||
// ── DÉTAIL ──
|
||||
function openDetail(id) {
|
||||
const f = films.find(item => item.id == id);
|
||||
if (!f) return;
|
||||
@@ -261,14 +255,14 @@ function openDetail(id) {
|
||||
const dTitle = document.getElementById('d-title');
|
||||
const dMeta = document.getElementById('d-meta');
|
||||
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');
|
||||
|
||||
if (f.poster) {
|
||||
if (dPoster) dPoster.src = f.poster;
|
||||
if (dPosterWrap) {
|
||||
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');
|
||||
} else {
|
||||
@@ -277,7 +271,7 @@ function openDetail(id) {
|
||||
}
|
||||
|
||||
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 (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>` : ''}
|
||||
</div>
|
||||
<div class="pub-tech-grid">
|
||||
<div class="tech-meta-item">
|
||||
<span class="tech-meta-label">Éditeur</span>
|
||||
<span class="tech-meta-value">${f.publisher || '—'}</span>
|
||||
</div>
|
||||
<div class="tech-meta-item">
|
||||
<span class="tech-meta-label">Format Image</span>
|
||||
<span class="tech-meta-value">${f.aspect_ratio || '—'}</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 || '—'}</span>
|
||||
</div>
|
||||
<div class="tech-meta-item"><span class="tech-meta-label">Éditeur</span><span class="tech-meta-value">${f.publisher || '—'}</span></div>
|
||||
<div class="tech-meta-item"><span class="tech-meta-label">Format Image</span><span class="tech-meta-value">${f.aspect_ratio || '—'}</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 || '—'}</span></div>
|
||||
</div>
|
||||
<div class="pub-synopsis-box">
|
||||
<h4>Synopsis / Notes</h4>
|
||||
@@ -326,7 +311,6 @@ function closeDetail() {
|
||||
if (detailOverlay) detailOverlay.classList.remove('open');
|
||||
}
|
||||
|
||||
// ── INITIALISATION ──
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadPublicData();
|
||||
const searchInput = document.getElementById('pub-search-input');
|
||||
|
||||
Reference in New Issue
Block a user