feat(files): photo-style cards with main-design buttons and links
This commit is contained in:
+19
-18
@@ -34,26 +34,25 @@ function humanSize(b) {
|
||||
function fileCardHTML(f) {
|
||||
const url = `${API}/api/files/${f.token}`;
|
||||
const thumb = isImageFile(f.name)
|
||||
? `<img src="${thumbSrc(url)}" data-img="${esc(url)}" loading="lazy" decoding="async" alt="">`
|
||||
: `<div class="file-icon">📄</div>`;
|
||||
const target = isImageFile(f.name)
|
||||
? `href="#" data-img="${esc(url)}"`
|
||||
: `href="${url}" download`;
|
||||
? `<img src="${esc(thumbSrc(url))}" data-img="${esc(url)}" loading="lazy" decoding="async" alt="">`
|
||||
: `<div class="ph-card__placeholder">📄</div>`;
|
||||
const meta = mode === 'detached'
|
||||
? `<div class="group" style="color:#f59e0b">Откреплён от записи, не привязан</div>`
|
||||
: `<div class="group">${esc(f.student_name)} · ${esc(f.group_name)}</div>`;
|
||||
? '<div class="ph-meta">Откреплён от записи, не привязан</div>'
|
||||
: `<div class="ph-meta">${esc(f.student_name || '')} · ${esc(f.group_name || '')}</div>`;
|
||||
const time = `<div class="ph-time">${fmtFull(f.created_at)}${f.size ? ' · ' + humanSize(f.size) : ''}</div>`;
|
||||
const action = mode === 'detached'
|
||||
? `<button class="f-action f-del" data-delete="${f.id}" title="Удалить файл навсегда">Удалить</button>`
|
||||
: `<button class="f-action" data-detach="${f.id}" title="Открепить файл от записи">Открепить</button>`;
|
||||
? `<button class="ph-action ph-action--danger" data-delete="${f.id}" title="Удалить файл навсегда">Удалить</button>`
|
||||
: `<button class="ph-action" data-detach="${f.id}" title="Открепить от записи">Открепить</button>`;
|
||||
return `
|
||||
<div class="card">
|
||||
<div class="ph-card">
|
||||
${thumb}
|
||||
<div class="info">
|
||||
<div class="file-name"><a ${target}>${esc(f.name)}</a></div>
|
||||
<div class="ph-body">
|
||||
<span class="ph-badge">📎 Файл</span>
|
||||
<div class="ph-title">${isImageFile(f.name) ? esc(f.name) : `<a href="${url}" download class="ph-link">${esc(f.name)}</a>`}</div>
|
||||
${meta}
|
||||
<div class="time">${fmtFull(f.created_at)}${f.size ? ' · ' + humanSize(f.size) : ''}</div>
|
||||
${time}
|
||||
${action}
|
||||
</div>
|
||||
<div class="f-actions">${action}</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
@@ -61,16 +60,18 @@ function fileCardHTML(f) {
|
||||
function renderGrid() {
|
||||
const grid = document.getElementById('grid');
|
||||
if (!currentFiles.length) {
|
||||
grid.className = 'grid';
|
||||
grid.className = 'ph-grid';
|
||||
grid.innerHTML = mode === 'detached'
|
||||
? '<div class="empty">Откреплённых файлов нет</div>'
|
||||
: '<div class="empty">Файлов не найдено</div>';
|
||||
? '<div class="empty" style="grid-column:1/-1">Откреплённых файлов нет</div>'
|
||||
: '<div class="empty" style="grid-column:1/-1">Файлов не найдено</div>';
|
||||
return;
|
||||
}
|
||||
grid.className = 'grid';
|
||||
grid.className = 'ph-grid';
|
||||
grid.innerHTML = currentFiles.map(fileCardHTML).join('');
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function detachFile(id) {
|
||||
if (!confirm('Открепить файл от записи? Он переместится во вкладку «Откреплённые».')) return;
|
||||
const res = await fetch(`${API}/api/files/${id}/detach`, { method: 'POST', headers: hdr() });
|
||||
|
||||
Reference in New Issue
Block a user