docs: вложения статей (doc_files), подписи и библиотека картинок, быстрое ред. отзыва
This commit is contained in:
@@ -116,6 +116,9 @@
|
||||
.dp-side { position: static; max-height: none; }
|
||||
.dp-article { padding: 20px 16px; }
|
||||
}
|
||||
.md-figure { margin: 6px 0; text-align: center; }
|
||||
.md-figure img { max-width: 100%; border-radius: 10px; border: 1px solid var(--border); cursor: zoom-in; }
|
||||
.md-figure figcaption { font-size: .82rem; color: var(--muted); margin-top: 4px; font-style: italic; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -183,6 +183,33 @@
|
||||
.docs-side { position: static; max-height: none; }
|
||||
.docs-article { padding: 20px 16px; }
|
||||
}
|
||||
.docs-files { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
|
||||
.docs-files-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
|
||||
.docs-files-title { font-weight: 700; font-size: .9rem; }
|
||||
.docs-files-actions { display: flex; gap: 6px; flex-wrap: wrap; }
|
||||
.docs-files-hint { font-size: .78rem; color: var(--muted); }
|
||||
.docs-files-table-wrap { overflow: auto; }
|
||||
.docs-files-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
|
||||
.docs-files-table th, .docs-files-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: middle; }
|
||||
.docs-files-table th { background: rgba(127,127,127,.09); font-weight: 600; }
|
||||
.docs-files-acts { display: flex; gap: 4px; flex-wrap: wrap; }
|
||||
.docs-files-acts button { padding: 3px 8px; font-size: .75rem; }
|
||||
.docs-attachments { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--border); }
|
||||
.docs-attachments-title { font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
|
||||
.docs-attachments-list { margin: 0; padding-left: 18px; }
|
||||
.docs-attachments-list li { margin: 0 0 4px; font-size: .9rem; }
|
||||
.docs-attach-size { color: var(--muted); font-size: .78rem; margin-left: 6px; }
|
||||
.docs-imglib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; max-height: 420px; overflow: auto; padding: 4px 0; }
|
||||
.docs-imglib-item { border: 1px solid var(--border); border-radius: 8px; padding: 4px; cursor: pointer; background: var(--bg); }
|
||||
.docs-imglib-item:hover { border-color: var(--accent); }
|
||||
.docs-imglib-item img { width: 100%; height: 90px; object-fit: cover; border-radius: 6px; display: block; }
|
||||
.docs-imglib-name { font-size: .72rem; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.docs-caption-row { display: flex; gap: 4px; margin-top: 4px; }
|
||||
.docs-caption-input { flex: 1; font-size: .75rem; padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
|
||||
.docs-caption-row button { padding: 3px 8px; font-size: .75rem; }
|
||||
.md-figure { margin: 6px 0; text-align: center; }
|
||||
.md-figure img { max-width: 100%; border-radius: 10px; border: 1px solid var(--border); cursor: zoom-in; }
|
||||
.md-figure figcaption { font-size: .82rem; color: var(--muted); margin-top: 4px; font-style: italic; }
|
||||
</style>
|
||||
</head>
|
||||
<body data-page="docs">
|
||||
@@ -237,6 +264,7 @@
|
||||
<span class="sep"></span>
|
||||
<button type="button" data-md="link" title="Ссылка">Ссылка</button>
|
||||
<button type="button" data-md="image" title="Картинка">Картинка</button>
|
||||
<button type="button" id="docsImgLibBtn" title="Все изображения документации">Библиотека</button>
|
||||
</div>
|
||||
<div class="docs-edit-grid">
|
||||
<div class="docs-edit-area">
|
||||
@@ -244,7 +272,25 @@
|
||||
</div>
|
||||
<div class="docs-preview"><div class="docs-body" id="docsPreview"></div></div>
|
||||
</div>
|
||||
<div class="docs-files" id="docsFilesPanel">
|
||||
<div class="docs-files-head">
|
||||
<span class="docs-files-title">Вложения</span>
|
||||
<div class="docs-files-actions">
|
||||
<button type="button" class="btn-primary ghost" id="docsFileUploadBtn"><i data-lucide="paperclip"></i> Прикрепить файл</button>
|
||||
<button type="button" class="btn-primary ghost" id="docsFilePickerBtn" title="Выбрать из уже загруженных"><i data-lucide="folder-open"></i> Из загруженных</button>
|
||||
<button type="button" class="btn-primary ghost" id="docsFileAllBtn" title="Показать все вложения"><i data-lucide="layers"></i> Все</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="docs-files-hint" id="docsFilesHint">Файлы, прикреплённые к статье. Вставить в текст — кнопка «Вставить» вставляет ссылку в Markdown.</div>
|
||||
<div class="docs-files-table-wrap">
|
||||
<table class="docs-files-table" id="docsFilesTable">
|
||||
<thead><tr><th>Имя</th><th>Размер</th><th>Статус</th><th>Действия</th></tr></thead>
|
||||
<tbody id="docsFilesBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<input type="file" id="docsImageFile" class="docs-file-input" accept="image/*">
|
||||
<input type="file" id="docsFileInput" class="docs-file-input" multiple>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
@@ -277,6 +323,15 @@
|
||||
|
||||
<div class="toast" id="toast"></div>
|
||||
|
||||
<div class="modal-overlay" id="docsImageLibModal">
|
||||
<div class="edit-modal" style="max-width:720px">
|
||||
<h3>Все изображения документации</h3>
|
||||
<div class="docs-imglib-grid" id="docsImgLibGrid"></div>
|
||||
<div class="card-foot">
|
||||
<button type="button" class="btn-primary ghost" id="docsImgLibClose">Закрыть</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="vendor/lucide.min.js"></script>
|
||||
<script src="js/datetime.js"></script>
|
||||
<script src="admin.js"></script>
|
||||
|
||||
@@ -61,6 +61,8 @@
|
||||
.fb-resident-photo img { width:100%; height:100%; object-fit:cover; display:block; }
|
||||
#fbPromptModal { overflow:auto; align-items:flex-start; padding:4vh 16px; }
|
||||
#fbPromptModal > .edit-modal { margin:auto; }
|
||||
#fbQuickModal { z-index:105; }
|
||||
#fbImgbbModal { z-index:110; }
|
||||
.feedback-item { position:relative; }
|
||||
.feedback-item.fb-ai-made { background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 130 100'%3E%3Ctext x='128' y='92' text-anchor='end' font-family='Arial,Helvetica,sans-serif' font-weight='800' font-size='104' fill='%23808080' fill-opacity='0.1'%3EAI%3C/text%3E%3C/svg%3E"); background-repeat:no-repeat; background-position:right 6px bottom 2px; background-size:auto 148px; }
|
||||
.fb-author { display:inline-flex; align-items:center; gap:6px; min-width:0; font-size:.78rem; color:var(--muted); border:1px solid var(--border); border-radius:999px; background:rgba(127,127,127,.08); padding:2px 10px 2px 2px; }
|
||||
@@ -88,6 +90,12 @@
|
||||
.fb-works .fb-work-files .fb-work-thumb img { display:block; width:56px; height:56px; object-fit:cover; border-radius:8px; cursor:zoom-in; }
|
||||
.fb-works .fb-work-files .fb-work-file { flex:none; max-width:none; font-size:12px; line-height:1.3; color:var(--accent); text-decoration:underline; white-space:nowrap; }
|
||||
.fb-works-empty { font-size:.83rem; color:var(--muted); }
|
||||
.fb-quick-head { display:flex; align-items:center; gap:12px; }
|
||||
.fb-quick-head .fb-card-photo { cursor:pointer; }
|
||||
.fb-quick-meta { min-width:0; }
|
||||
.fb-quick-resident { font-weight:600; font-size:1.05rem; overflow-wrap:anywhere; }
|
||||
.fb-quick-topic { font-size:.9rem; color:var(--text); margin-top:2px; overflow-wrap:anywhere; }
|
||||
.fb-quick-date { font-size:.82rem; color:var(--muted); margin-top:2px; }
|
||||
</style>
|
||||
</head>
|
||||
<body data-page="feedback">
|
||||
@@ -331,6 +339,34 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-overlay" id="fbQuickModal">
|
||||
<div class="edit-modal" style="max-width:760px;width:96%;max-height:92dvh;overflow-y:auto">
|
||||
<div class="fb-modal-head">
|
||||
<h3>Быстрое редактирование отзыва</h3>
|
||||
<button type="button" class="icon-btn" id="fbQuickClose" title="Закрыть"><i data-lucide="x"></i></button>
|
||||
</div>
|
||||
<div class="settings-stack">
|
||||
<div class="fb-quick-head" id="fbQuickHead">
|
||||
<div id="fbQuickPhotoWrap"></div>
|
||||
<div class="fb-quick-meta">
|
||||
<div class="fb-quick-resident" id="fbQuickResident">—</div>
|
||||
<div class="fb-quick-topic" id="fbQuickTopic" hidden></div>
|
||||
<div class="fb-quick-date" id="fbQuickDate"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-field">
|
||||
<label>Текст отзыва</label>
|
||||
<textarea id="fbQuickText" class="settings-input" rows="8" maxlength="5000" placeholder="Текст отзыва"></textarea>
|
||||
<div class="hint" style="display:flex;justify-content:space-between;align-items:center"><span id="fbQuickTextHint">0 / 5000</span><button type="button" class="btn-primary" id="fbQuickImgbbBtn" style="font-size:.8rem;padding:4px 8px">Картинка из работ</button></div>
|
||||
</div>
|
||||
<div class="card-foot" style="justify-content:flex-end;gap:8px">
|
||||
<button type="button" class="btn-primary ghost" id="fbQuickCancel">Отмена</button>
|
||||
<button type="button" class="btn-primary" id="fbQuickSave">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="vendor/lucide.min.js"></script>
|
||||
<script src="js/datetime.js"></script>
|
||||
<script src="admin.js"></script>
|
||||
|
||||
+326
-1
@@ -13,6 +13,11 @@
|
||||
const hintEl = el('docsEditHint');
|
||||
const searchEl = el('docsSearch');
|
||||
const imageFileEl = el('docsImageFile');
|
||||
const fileInputEl = el('docsFileInput');
|
||||
const filesBodyEl = el('docsFilesBody');
|
||||
const filesPanelEl = el('docsFilesPanel');
|
||||
const imgLibModal = el('docsImageLibModal');
|
||||
const imgLibGrid = el('docsImgLibGrid');
|
||||
const sectionModal = el('docsSectionModal');
|
||||
const sectionTitleEl = el('docsSectionTitle');
|
||||
const sectionParentEl = el('docsSectionParent');
|
||||
@@ -182,6 +187,10 @@
|
||||
<div class="docs-meta">${meta.join('')}</div>
|
||||
<div class="docs-article-actions">${actions.join('')}</div>
|
||||
<div class="docs-body">${WhatIDoMD.render(article.body)}</div>
|
||||
${(article.files && article.files.length) ? `<div class="docs-attachments">
|
||||
<div class="docs-attachments-title">Вложения</div>
|
||||
<ul class="docs-attachments-list">${article.files.map(f => `<li><a href="${esc(f.path)}" target="_blank" rel="noopener">${esc(f.name)}</a> <span class="docs-attach-size">${fmtBytes(f.size_bytes)}</span></li>`).join('')}</ul>
|
||||
</div>` : ''}
|
||||
</article>`;
|
||||
}
|
||||
|
||||
@@ -203,6 +212,10 @@
|
||||
if (editState && editState.dirty && !confirm('Несохранённые изменения будут потеряны. Продолжить?')) return;
|
||||
const data = await req('/api/docs/articles/' + encodeURIComponent(slug));
|
||||
current = data.item;
|
||||
try {
|
||||
const fdata = await req('/api/docs/articles/' + current.id + '/files');
|
||||
current.files = fdata.items || [];
|
||||
} catch (e) { current.files = []; }
|
||||
editState = null;
|
||||
if (updateHash !== false) history.replaceState(null, '', '#a=' + encodeURIComponent(current.slug));
|
||||
renderArticle();
|
||||
@@ -246,7 +259,8 @@
|
||||
showToast('Нет разделов, где вам разрешено писать', true);
|
||||
return;
|
||||
}
|
||||
editState = { id: article ? article.id : null, dirty: false };
|
||||
editState = { id: article ? article.id : null, dirty: false, files: [] };
|
||||
if (article && article.id) loadDocFiles(article.id); else renderDocFilesTable();
|
||||
titleEl.value = article ? article.title : '';
|
||||
bodyEl.value = article ? article.body : '';
|
||||
publishedEl.checked = article ? article.is_published : true;
|
||||
@@ -290,6 +304,7 @@
|
||||
is_public: isAdmin() ? publicEl.checked : false,
|
||||
};
|
||||
const saveBtn = el('docsSaveBtn');
|
||||
const pendingFileIds = (editState && editState.files ? editState.files : []).filter(f => !f.article_id).map(f => f.id);
|
||||
saveBtn.disabled = true;
|
||||
try {
|
||||
const path = editState.id ? '/api/docs/articles/' + editState.id : '/api/docs/articles';
|
||||
@@ -297,6 +312,9 @@
|
||||
const data = await req(path, { method, body: JSON.stringify(payload) });
|
||||
editState.dirty = false;
|
||||
closeEditor();
|
||||
for (const fid of pendingFileIds) {
|
||||
try { await req('/api/docs/files/' + fid + '/attach', { method: 'PUT', body: JSON.stringify({ article_id: data.item.id }) }); } catch (e) {}
|
||||
}
|
||||
await loadTree();
|
||||
await openArticle(data.item.slug);
|
||||
showToast('Статья сохранена');
|
||||
@@ -401,6 +419,223 @@
|
||||
}
|
||||
}
|
||||
|
||||
function fmtBytes(n) {
|
||||
n = Number(n) || 0;
|
||||
if (n < 1024) return n + ' Б';
|
||||
if (n < 1024 * 1024) return (n / 1024).toFixed(1) + ' КБ';
|
||||
return (n / (1024 * 1024)).toFixed(1) + ' МБ';
|
||||
}
|
||||
|
||||
async function loadDocFiles(articleId) {
|
||||
if (!editState) return;
|
||||
if (!articleId) {
|
||||
// unsaved article: show unattached files + unattached images
|
||||
try {
|
||||
const [fdata, idata] = await Promise.all([
|
||||
req('/api/docs/files/unattached'),
|
||||
req('/api/docs/images/unattached'),
|
||||
]);
|
||||
const files = (fdata.items || []).map(x => Object.assign({}, x, { _kind: 'file', _unattached: true }));
|
||||
const images = (idata.items || []).map(x => Object.assign({}, x, { _kind: 'image', name: (x.path || '').split('/').pop(), size_bytes: null, mime: 'image/*', _unattached: true }));
|
||||
editState.files = files.concat(images);
|
||||
renderDocFilesTable();
|
||||
} catch (e) {
|
||||
editState.files = [];
|
||||
renderDocFilesTable();
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const [fdata, idata] = await Promise.all([
|
||||
req('/api/docs/articles/' + articleId + '/files'),
|
||||
req('/api/docs/articles/' + articleId + '/images'),
|
||||
]);
|
||||
const files = (fdata.items || []).map(x => Object.assign({}, x, { _kind: 'file' }));
|
||||
const images = (idata.items || []).map(x => Object.assign({}, x, { _kind: 'image', name: (x.path || '').split('/').pop(), size_bytes: null, mime: 'image/*' }));
|
||||
editState.files = files.concat(images);
|
||||
renderDocFilesTable();
|
||||
} catch (e) {
|
||||
editState.files = [];
|
||||
renderDocFilesTable();
|
||||
}
|
||||
}
|
||||
|
||||
function docFileStatus(f) {
|
||||
const body = bodyEl.value || '';
|
||||
const used = body.indexOf(f.path) !== -1;
|
||||
if (used) return '<span class="docs-badge">В тексте</span>';
|
||||
if (f.article_id) return '<span class="docs-badge">Прикреплён</span>';
|
||||
return '<span class="docs-badge">Не привязан</span>';
|
||||
}
|
||||
|
||||
function renderDocFilesTable() {
|
||||
if (!filesBodyEl) return;
|
||||
const files = (editState && editState.files) || [];
|
||||
if (!files.length) {
|
||||
filesBodyEl.innerHTML = '<tr><td colspan="4" class="docs-empty" style="padding:8px">Вложений пока нет</td></tr>';
|
||||
return;
|
||||
}
|
||||
filesBodyEl.innerHTML = files.map(f => {
|
||||
const isImg = f._kind === 'image';
|
||||
const thumb = isImg ? `<img src="/uploads/thumb/${esc(f.path.split('/').pop())}" alt="" style="width:36px;height:36px;object-fit:cover;border-radius:6px;vertical-align:middle;margin-right:6px">` : '';
|
||||
const acts = f._unattached
|
||||
? (isImg
|
||||
? `<button type="button" class="btn-primary ghost" data-file-act="delete" style="color:#ef4444;border-color:rgba(239,68,68,.35)" title="Удалить">Удалить</button>`
|
||||
: `<button type="button" class="btn-primary ghost" data-file-act="attach" title="Прикрепить к статье">Прикрепить</button>
|
||||
<button type="button" class="btn-primary ghost" data-file-act="delete" style="color:#ef4444;border-color:rgba(239,68,68,.35)" title="Удалить">Удалить</button>`)
|
||||
: (isImg
|
||||
? `<button type="button" class="btn-primary ghost" data-file-act="insert" title="Вставить в текст">Вставить</button>
|
||||
<button type="button" class="btn-primary ghost" data-file-act="delete" style="color:#ef4444;border-color:rgba(239,68,68,.35)" title="Удалить">Удалить</button>`
|
||||
: `<button type="button" class="btn-primary ghost" data-file-act="insert" title="Вставить в текст">Вставить</button>
|
||||
<button type="button" class="btn-primary ghost" data-file-act="replace" title="Заменить файл">Заменить</button>
|
||||
<button type="button" class="btn-primary ghost" data-file-act="detach" title="Открепить">Открепить</button>
|
||||
<button type="button" class="btn-primary ghost" data-file-act="delete" style="color:#ef4444;border-color:rgba(239,68,68,.35)" title="Удалить">Удалить</button>`);
|
||||
const status = isImg ? '<span class="docs-badge">Картинка</span>' : (f._unattached ? '<span class="docs-badge">Не привязан</span>' : docFileStatus(f));
|
||||
const captionInput = isImg ? `<div class="docs-caption-row"><input class="docs-caption-input" data-caption-for="${f.id}" value="${esc(f.caption || '')}" placeholder="Подпись (alt/title)" maxlength="300"><button type="button" class="btn-primary ghost" data-file-act="caption" title="Сохранить подпись">✓</button></div>` : '';
|
||||
return `<tr data-file-id="${f.id}" data-file-kind="${f._kind || 'file'}">
|
||||
<td>${thumb}<a href="${esc(f.path)}" target="_blank" rel="noopener">${esc(f.name)}</a>${captionInput}</td>
|
||||
<td>${isImg ? '—' : fmtBytes(f.size_bytes)}</td>
|
||||
<td>${status}</td>
|
||||
<td class="docs-files-acts">${acts}</td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
async function uploadDocFile(file, articleId) {
|
||||
if (!file) return;
|
||||
showToast('Загрузка файла...');
|
||||
try {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
if (articleId) form.append('article_id', String(articleId));
|
||||
const data = await req('/api/docs/files', { method: 'POST', body: form });
|
||||
if (editState) {
|
||||
editState.files = editState.files || [];
|
||||
editState.files.unshift(data.item);
|
||||
renderDocFilesTable();
|
||||
}
|
||||
showToast('Файл прикреплён');
|
||||
} catch (e) {
|
||||
showToast(e.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
async function replaceDocFile(id) {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.onchange = async () => {
|
||||
const file = input.files && input.files[0];
|
||||
if (!file) return;
|
||||
showToast('Замена файла...');
|
||||
try {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const data = await req('/api/docs/files/' + id + '/replace', { method: 'POST', body: form });
|
||||
const old = (editState.files || []).find(f => Number(f.id) === Number(id));
|
||||
if (old && old.path && data.item.path && bodyEl.value.indexOf(old.path) !== -1) {
|
||||
bodyEl.value = bodyEl.value.split(old.path).join(data.item.path);
|
||||
markDirty();
|
||||
updatePreview();
|
||||
}
|
||||
if (editState) {
|
||||
editState.files = (editState.files || []).map(f => Number(f.id) === Number(id) ? data.item : f);
|
||||
renderDocFilesTable();
|
||||
}
|
||||
showToast('Файл заменён');
|
||||
} catch (e) {
|
||||
showToast(e.message, true);
|
||||
}
|
||||
};
|
||||
input.click();
|
||||
}
|
||||
|
||||
async function detachDocFile(id) {
|
||||
if (!confirm('Открепить файл от статьи?')) return;
|
||||
try {
|
||||
const data = await req('/api/docs/files/' + id + '/attach', { method: 'PUT', body: JSON.stringify({ article_id: null }) });
|
||||
if (editState) {
|
||||
editState.files = (editState.files || []).filter(f => Number(f.id) !== Number(id));
|
||||
renderDocFilesTable();
|
||||
}
|
||||
showToast('Файл откреплён');
|
||||
} catch (e) {
|
||||
showToast(e.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteDocFile(id) {
|
||||
if (!confirm('Удалить файл без возможности восстановления?')) return;
|
||||
try {
|
||||
await req('/api/docs/files/' + id, { method: 'DELETE' });
|
||||
if (editState) {
|
||||
editState.files = (editState.files || []).filter(f => Number(f.id) !== Number(id));
|
||||
renderDocFilesTable();
|
||||
}
|
||||
showToast('Файл удалён');
|
||||
} catch (e) {
|
||||
showToast(e.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
function isImageFile(f) {
|
||||
const mime = String(f.mime || '').toLowerCase();
|
||||
if (mime.startsWith('image/')) return true;
|
||||
return /\.(jpe?g|png|gif|webp|bmp|avif|ico|jfif)$/i.test(String(f.name || f.path || ''));
|
||||
}
|
||||
function insertDocFileLink(f) {
|
||||
const md = isImageFile(f) ? `` : `[${f.name}](${f.path})`;
|
||||
insertBlock(md);
|
||||
}
|
||||
|
||||
async function loadUnattachedDocFiles() {
|
||||
try {
|
||||
const data = await req('/api/docs/files/unattached');
|
||||
const items = data.items || [];
|
||||
if (!items.length) { showToast('Нет незагруженных файлов', true); return; }
|
||||
const prev = (editState && editState.files) || [];
|
||||
const merged = prev.concat(items.map(x => Object.assign({}, x, { _unattached: true })));
|
||||
if (editState) { editState.files = merged; renderDocFilesTable(); }
|
||||
} catch (e) {
|
||||
showToast(e.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
async function openImageLibrary() {
|
||||
if (!imgLibModal || !imgLibGrid) return;
|
||||
imgLibGrid.innerHTML = '<div class="docs-empty">Загрузка...</div>';
|
||||
imgLibModal.classList.add('open');
|
||||
try {
|
||||
const data = await req('/api/docs/images');
|
||||
const items = data.items || [];
|
||||
if (!items.length) {
|
||||
imgLibGrid.innerHTML = '<div class="docs-empty">Изображений пока нет</div>';
|
||||
return;
|
||||
}
|
||||
imgLibGrid.innerHTML = items.map(it => `
|
||||
<div class="docs-imglib-item" data-img-path="${esc(it.path)}" title="${esc(it.path)}">
|
||||
<img src="${esc('/uploads/thumb/' + it.path.split('/').pop())}" alt="" loading="lazy">
|
||||
<div class="docs-imglib-name">${esc(it.path.split('/').pop())}</div>
|
||||
</div>`).join('');
|
||||
} catch (e) {
|
||||
imgLibGrid.innerHTML = '<div class="docs-empty">' + esc(e.message) + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAllDocFiles() {
|
||||
try {
|
||||
const data = await req('/api/docs/files');
|
||||
const items = (data.items || []).map(x => Object.assign({}, x, { _all: true }));
|
||||
if (editState) {
|
||||
// mark which are attached to current article
|
||||
const curId = editState.id;
|
||||
editState.files = items.map(x => Object.assign({}, x, { _unattached: !x.article_id || Number(x.article_id) !== Number(curId) }));
|
||||
renderDocFilesTable();
|
||||
}
|
||||
} catch (e) {
|
||||
showToast(e.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
function fillParentSelect(excludeId, selectedId) {
|
||||
const list = sectionList().filter(s => Number(s.id) !== Number(excludeId));
|
||||
sectionParentEl.innerHTML = '<option value="">— Корень —</option>' + list.map(s => {
|
||||
@@ -623,6 +858,96 @@
|
||||
imageFileEl.value = '';
|
||||
if (file) await uploadImage(file);
|
||||
});
|
||||
if (fileInputEl) fileInputEl.addEventListener('change', async () => {
|
||||
const files = [...(fileInputEl.files || [])];
|
||||
fileInputEl.value = '';
|
||||
const aid = editState && editState.id ? editState.id : null;
|
||||
for (const f of files) await uploadDocFile(f, aid);
|
||||
if (aid) await loadDocFiles(aid);
|
||||
});
|
||||
const uploadBtn = el('docsFileUploadBtn');
|
||||
if (uploadBtn) uploadBtn.addEventListener('click', () => fileInputEl && fileInputEl.click());
|
||||
const pickerBtn = el('docsFilePickerBtn');
|
||||
if (pickerBtn) pickerBtn.addEventListener('click', async () => {
|
||||
if (!editState || !editState.id) { showToast('Сначала сохраните статью', true); return; }
|
||||
await loadUnattachedDocFiles();
|
||||
});
|
||||
const allBtn = el('docsFileAllBtn');
|
||||
if (allBtn) allBtn.addEventListener('click', async () => {
|
||||
if (!editState || !editState.id) { showToast('Сначала сохраните статью', true); return; }
|
||||
await loadAllDocFiles();
|
||||
});
|
||||
const libBtn = el('docsImgLibBtn');
|
||||
if (libBtn) libBtn.addEventListener('click', () => openImageLibrary());
|
||||
const libClose = el('docsImgLibClose');
|
||||
if (libClose) libClose.addEventListener('click', () => imgLibModal && imgLibModal.classList.remove('open'));
|
||||
if (imgLibModal) imgLibModal.addEventListener('click', e => { if (e.target === imgLibModal) imgLibModal.classList.remove('open'); });
|
||||
if (imgLibGrid) imgLibGrid.addEventListener('click', e => {
|
||||
const item = e.target.closest('.docs-imglib-item');
|
||||
if (!item) return;
|
||||
const p = item.dataset.imgPath;
|
||||
if (!p) return;
|
||||
const name = p.split('/').pop().replace(/\.[^.]+$/, '');
|
||||
insertBlock(``);
|
||||
if (imgLibModal) imgLibModal.classList.remove('open');
|
||||
showToast('Картинка вставлена');
|
||||
});
|
||||
if (filesBodyEl) filesBodyEl.addEventListener('click', e => {
|
||||
const btn = e.target.closest('[data-file-act]');
|
||||
if (!btn) return;
|
||||
const tr = btn.closest('tr');
|
||||
const id = tr && tr.dataset.fileId;
|
||||
if (!id) return;
|
||||
const act = btn.dataset.fileAct;
|
||||
const f = (editState.files || []).find(x => String(x.id) === String(id));
|
||||
if (act === 'insert' && f) insertDocFileLink(f);
|
||||
if (act === 'caption') {
|
||||
const input = tr.querySelector('.docs-caption-input');
|
||||
const val = input ? input.value : '';
|
||||
req('/api/docs/images/' + id, { method: 'PUT', body: JSON.stringify({ caption: val }) })
|
||||
.then(data => {
|
||||
if (editState) {
|
||||
editState.files = (editState.files || []).map(x => String(x.id) === String(id) && x._kind === 'image' ? Object.assign({}, x, { caption: data.item.caption }) : x);
|
||||
renderDocFilesTable();
|
||||
}
|
||||
if (data.item.body && editState) {
|
||||
bodyEl.value = data.item.body;
|
||||
markDirty();
|
||||
updatePreview();
|
||||
}
|
||||
showToast('Подпись сохранена');
|
||||
}).catch(err => showToast(err.message, true));
|
||||
return;
|
||||
}
|
||||
if (act === 'replace') replaceDocFile(id);
|
||||
if (act === 'detach') detachDocFile(id);
|
||||
if (act === 'delete') {
|
||||
const kind = tr.dataset.fileKind || (f && f._kind) || 'file';
|
||||
if (kind === 'image') {
|
||||
req('/api/docs/images/' + id, { method: 'DELETE' })
|
||||
.then(() => {
|
||||
if (editState) {
|
||||
editState.files = (editState.files || []).filter(x => !(String(x.id) === String(id) && x._kind === 'image'));
|
||||
renderDocFilesTable();
|
||||
}
|
||||
showToast('Изображение удалено');
|
||||
}).catch(err => showToast(err.message, true));
|
||||
} else {
|
||||
deleteDocFile(id);
|
||||
}
|
||||
}
|
||||
if (act === 'attach') {
|
||||
if (!editState || !editState.id) { showToast('Сначала сохраните статью', true); return; }
|
||||
req('/api/docs/files/' + id + '/attach', { method: 'PUT', body: JSON.stringify({ article_id: editState.id }) })
|
||||
.then(data => {
|
||||
if (editState) {
|
||||
editState.files = (editState.files || []).map(x => String(x.id) === String(id) ? data.item : x).filter(x => x.article_id);
|
||||
renderDocFilesTable();
|
||||
}
|
||||
showToast('Файл прикреплён');
|
||||
}).catch(err => showToast(err.message, true));
|
||||
}
|
||||
});
|
||||
el('docsSaveBtn').addEventListener('click', saveArticle);
|
||||
el('docsCancelBtn').addEventListener('click', cancelEdit);
|
||||
}
|
||||
|
||||
+81
-5
@@ -43,6 +43,7 @@
|
||||
const actions = canWrite ? `${hasAiInfo ? `<button type="button" class="btn-link" data-aiinfo="${f.id}">AI</button>` : ''}
|
||||
${f.ai_status === 'error' ? `<button type="button" class="btn-link" data-retry="${f.id}">Повторить</button>` : ''}
|
||||
${f.deleted_at ? '' : `<button type="button" class="btn-link" data-sent="${f.id}">${f.sent_at ? 'Вернуть' : 'Отправлено'}</button>`}
|
||||
${aiMade ? `<button type="button" class="icon-btn" data-quick="${f.id}" title="Быстрое редактирование"><i data-lucide="zap"></i></button>` : ''}
|
||||
<button type="button" class="icon-btn" data-edit="${f.id}" title="Изменить"><i data-lucide="pencil"></i></button>
|
||||
<button type="button" class="icon-btn danger" data-del="${f.id}" title="${f.deleted_at ? 'Удалить навсегда' : 'Удалить'}"><i data-lucide="trash-2"></i></button>
|
||||
${f.deleted_at ? `<button type="button" class="btn-link" data-restore="${f.id}">Восстановить</button>` : ''}` : '';
|
||||
@@ -646,8 +647,10 @@
|
||||
}
|
||||
|
||||
let fbImgbbSelected = null;
|
||||
async function openImgbbPicker() {
|
||||
const resident = document.getElementById('fbResident').value.trim();
|
||||
let fbImgbbTextBox = 'fbText';
|
||||
async function openImgbbPicker(textId, residentName) {
|
||||
fbImgbbTextBox = textId || 'fbText';
|
||||
const resident = residentName != null ? String(residentName) : document.getElementById('fbResident').value.trim();
|
||||
const inp = document.getElementById('fbImgbbResident');
|
||||
const list = document.getElementById('fbImgbbList');
|
||||
const empty = document.getElementById('fbImgbbEmpty');
|
||||
@@ -933,6 +936,72 @@
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
let quickFeedback = null;
|
||||
|
||||
function setQuickTextHint() {
|
||||
const ta = document.getElementById('fbQuickText');
|
||||
const hint = document.getElementById('fbQuickTextHint');
|
||||
if (ta && hint) hint.textContent = `${ta.value.length} / 5000`;
|
||||
}
|
||||
|
||||
async function openQuickModal(id) {
|
||||
const m = document.getElementById('fbQuickModal');
|
||||
const f = feedbacks.find(x => x.id === id);
|
||||
if (!m || !f) return;
|
||||
quickFeedback = f;
|
||||
m.classList.add('open');
|
||||
try { await loadStudentPhotos(); } catch (e) {}
|
||||
const wrap = document.getElementById('fbQuickPhotoWrap');
|
||||
if (wrap) wrap.innerHTML = cardResidentPhoto(f.resident);
|
||||
const res = document.getElementById('fbQuickResident');
|
||||
if (res) res.textContent = f.resident || 'Резидент не указан';
|
||||
const topic = document.getElementById('fbQuickTopic');
|
||||
if (topic) { topic.textContent = f.topic || ''; topic.hidden = !f.topic; }
|
||||
const date = document.getElementById('fbQuickDate');
|
||||
if (date) date.textContent = fmtDate(f.feedback_date);
|
||||
const ta = document.getElementById('fbQuickText');
|
||||
if (ta) ta.value = f.text || '';
|
||||
setQuickTextHint();
|
||||
if (window.lucide) lucide.createIcons();
|
||||
}
|
||||
|
||||
function closeQuickModal() {
|
||||
const m = document.getElementById('fbQuickModal');
|
||||
if (m) m.classList.remove('open');
|
||||
quickFeedback = null;
|
||||
}
|
||||
|
||||
async function saveQuickFeedback() {
|
||||
if (!quickFeedback) return;
|
||||
const ta = document.getElementById('fbQuickText');
|
||||
if (!ta) return;
|
||||
const id = quickFeedback.id;
|
||||
const body = {
|
||||
feedback_date: quickFeedback.feedback_date || todayIso(),
|
||||
group_id: quickFeedback.group_id,
|
||||
resident: quickFeedback.resident || '',
|
||||
topic: quickFeedback.topic || '',
|
||||
past_review: quickFeedback.past_review || null,
|
||||
text: ta.value.trim(),
|
||||
ai_check: false,
|
||||
ai_profile: quickFeedback.ai_profile || null,
|
||||
short_message_ids: Array.isArray(quickFeedback.short_message_ids) ? quickFeedback.short_message_ids : [],
|
||||
};
|
||||
const btn = document.getElementById('fbQuickSave');
|
||||
const prev = btn ? btn.textContent : '';
|
||||
try {
|
||||
if (btn) { btn.disabled = true; btn.textContent = 'Сохранение...'; }
|
||||
const r = await fetch(`${API}/api/feedbacks/${id}`, { method: 'PUT', headers: {...hdr(), 'Content-Type':'application/json'}, body: JSON.stringify(body) });
|
||||
if (r.ok) { closeQuickModal(); loadFeedbacks(); return; }
|
||||
const err = await r.json().catch(() => null);
|
||||
alert((err && err.error) || `Ошибка ${r.status}`);
|
||||
} catch (e) {
|
||||
alert('Ошибка сети');
|
||||
} finally {
|
||||
if (btn) { btn.disabled = false; btn.textContent = prev; }
|
||||
}
|
||||
}
|
||||
|
||||
async function loadFeedbacks() {
|
||||
const el = document.getElementById('feedbackList');
|
||||
const st = document.getElementById('feedbackState');
|
||||
@@ -1098,14 +1167,14 @@
|
||||
document.getElementById('fbPastReviewWrap').style.display = e.target.checked ? '' : 'none';
|
||||
if (e.target.checked) loadLastPastReview();
|
||||
});
|
||||
document.getElementById('fbImgbbBtn').addEventListener('click', () => openImgbbPicker());
|
||||
document.getElementById('fbImgbbBtn').addEventListener('click', () => openImgbbPicker('fbText'));
|
||||
document.getElementById('fbImgbbModalClose').addEventListener('click', closeImgbbPicker);
|
||||
document.getElementById('fbImgbbModal').addEventListener('click', e => { if (e.target.id === 'fbImgbbModal') closeImgbbPicker(); });
|
||||
document.getElementById('fbImgbbModalCancel').addEventListener('click', closeImgbbPicker);
|
||||
document.getElementById('fbImgbbModalOk').addEventListener('click', async () => {
|
||||
if (!fbImgbbSelected) return;
|
||||
const text = document.getElementById('fbText');
|
||||
const hint = document.getElementById('fbTextHint');
|
||||
const text = document.getElementById(fbImgbbTextBox);
|
||||
const hint = document.getElementById(fbImgbbTextBox + 'Hint');
|
||||
const ok = document.getElementById('fbImgbbModalOk');
|
||||
const btn = document.getElementById('fbImgbbBtn');
|
||||
if (!window.WhatIDoImgBB || !window.WhatIDoImgBB.configured()) {
|
||||
@@ -1132,6 +1201,12 @@
|
||||
document.getElementById('fbText').addEventListener('input', () => {
|
||||
document.getElementById('fbTextHint').textContent = `${document.getElementById('fbText').value.length} / 5000`;
|
||||
});
|
||||
document.getElementById('fbQuickClose').addEventListener('click', closeQuickModal);
|
||||
document.getElementById('fbQuickCancel').addEventListener('click', closeQuickModal);
|
||||
document.getElementById('fbQuickModal').addEventListener('click', e => { if (e.target.id === 'fbQuickModal') closeQuickModal(); });
|
||||
document.getElementById('fbQuickSave').addEventListener('click', saveQuickFeedback);
|
||||
document.getElementById('fbQuickImgbbBtn').addEventListener('click', () => openImgbbPicker('fbQuickText', quickFeedback ? quickFeedback.resident : ''));
|
||||
document.getElementById('fbQuickText').addEventListener('input', setQuickTextHint);
|
||||
document.getElementById('fbTopic').addEventListener('change', applyTopicText);
|
||||
document.getElementById('feedbackList').addEventListener('click', async e => {
|
||||
const aiinfo = e.target.closest('[data-aiinfo]'); if (aiinfo) {
|
||||
@@ -1147,6 +1222,7 @@
|
||||
try { const r = await fetch(`${API}/api/feedbacks/${id}/sent`, { method:'PUT', headers: {...hdr(), 'Content-Type':'application/json'}, body: JSON.stringify({ sent: next }) }); if (r.ok) loadFeedbacks(); } catch (e) {}
|
||||
return;
|
||||
}
|
||||
const quickBtn = e.target.closest('[data-quick]'); if (quickBtn) { openQuickModal(parseInt(quickBtn.dataset.quick, 10)); return; }
|
||||
const edit = e.target.closest('[data-edit]'); if (edit) { openModal({id: parseInt(edit.dataset.edit,10)}); return; }
|
||||
const del = e.target.closest('[data-del]'); if (del) {
|
||||
const id = parseInt(del.dataset.id||del.dataset.del,10);
|
||||
|
||||
@@ -403,18 +403,23 @@ function closeReportCard() {
|
||||
setReportFieldsOpen(false);
|
||||
}
|
||||
|
||||
function fileExtLabel(name) {
|
||||
const m = String(name || '').match(/\.[^.\/]+$/);
|
||||
return m ? m[0].toLowerCase() : esc(name || '');
|
||||
}
|
||||
|
||||
function filesHTML(files) {
|
||||
if (!files || !files.length) return '';
|
||||
return `<div class="entry-files">${files.map(f => {
|
||||
const url = `${API}/api/files/${f.token}`;
|
||||
const label = fileExtLabel(f.name);
|
||||
let link;
|
||||
if (isImageFile(f.name)) {
|
||||
link = `<a class="f-link" href="#" data-img="${url}" title="Открыть">${esc(f.name)}</a>`;
|
||||
link = `<a class="f-link" href="#" data-img="${url}" title="${esc(f.name)}">${label}</a>`;
|
||||
} else if (isPlayableVideoFile(f.name)) {
|
||||
link = `<a class="f-link" href="${url}?play=1" data-video="${url}?play=1" data-video-name="${esc(f.name)}" data-video-token="${f.token}" title="Смотреть">${esc(f.name)}</a>`;
|
||||
link = `<a class="f-link" href="${url}?play=1" data-video="${url}?play=1" data-video-name="${esc(f.name)}" data-video-token="${f.token}" title="${esc(f.name)}">${label}</a>`;
|
||||
} else {
|
||||
const note = isVideoFile(f.name) ? 'Скачать (браузер не умеет играть этот формат)' : 'Скачать';
|
||||
link = `<a class="f-link" href="${url}" download title="${note}">${esc(f.name)}</a>`;
|
||||
link = `<a class="f-link" href="${url}" download title="${esc(f.name)}">${label}</a>`;
|
||||
}
|
||||
return `<span class="f-item">${link}<button class="f-detach" data-detach="${f.id}" title="Открепить файл">✕</button></span>`;
|
||||
}).join('')}</div>`;
|
||||
|
||||
+5
-2
@@ -27,10 +27,13 @@
|
||||
return `\u0000${codes.length - 1}\u0000`;
|
||||
});
|
||||
text = esc(text);
|
||||
text = text.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (m, alt, src) => {
|
||||
text = text.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (m, alt, src, title) => {
|
||||
const url = safeUrl(src.replace(/&/g, '&'));
|
||||
if (!url) return alt;
|
||||
return `<img src="${esc(thumbUrl(url))}" data-img="${esc(url)}" alt="${esc(alt)}" loading="lazy">`;
|
||||
const t = title ? title.replace(/&/g, '&') : '';
|
||||
const img = `<img src="${esc(thumbUrl(url))}" data-img="${esc(url)}" alt="${esc(alt)}"${t ? ` title="${esc(t)}"` : ''} loading="lazy">`;
|
||||
if (t) return `<figure class="md-figure">${img}<figcaption>${esc(t)}</figcaption></figure>`;
|
||||
return img;
|
||||
});
|
||||
text = text.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (m, label, href) => {
|
||||
const url = safeUrl(href.replace(/&/g, '&'));
|
||||
|
||||
+7
-2
@@ -24,12 +24,17 @@ function isImageFile(name) {
|
||||
return /\.(jpe?g|jfif|png|gif|webp|bmp|avif|svg|ico)$/i.test(name || '');
|
||||
}
|
||||
|
||||
function fileExtLabel(name) {
|
||||
const m = String(name || '').match(/\.[^.\/]+$/);
|
||||
return m ? m[0].toLowerCase() : esc(name || '');
|
||||
}
|
||||
|
||||
function filesHTML(files) {
|
||||
if (!files || !files.length) return '';
|
||||
return `<div class="entry-files">${files.map(f =>
|
||||
isImageFile(f.name)
|
||||
? `<a class="f-link" href="#" data-img="${API}/api/files/${f.token}" title="Открыть">${esc(f.name)}</a>`
|
||||
: `<a class="f-link" href="${API}/api/files/${f.token}" download title="Скачать">${esc(f.name)}</a>`
|
||||
? `<a class="f-link" href="#" data-img="${API}/api/files/${f.token}" title="${esc(f.name)}">${fileExtLabel(f.name)}</a>`
|
||||
: `<a class="f-link" href="${API}/api/files/${f.token}" download title="${esc(f.name)}">${fileExtLabel(f.name)}</a>`
|
||||
).join('')}</div>`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user