feat(admin): improve uploads and dashboard UX
This commit is contained in:
33
src/static/admin/js/mostovik-admin-upload.js
Normal file
33
src/static/admin/js/mostovik-admin-upload.js
Normal file
@@ -0,0 +1,33 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const pickers = document.querySelectorAll("[data-file-picker]");
|
||||
|
||||
for (const picker of pickers) {
|
||||
const input = picker.querySelector("[data-file-input]");
|
||||
const summary = picker.querySelector("[data-file-summary]");
|
||||
|
||||
if (!input || !summary) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const emptyText = summary.dataset.emptyText || "Файл не выбран";
|
||||
|
||||
const renderSummary = () => {
|
||||
const files = Array.from(input.files || []);
|
||||
|
||||
if (!files.length) {
|
||||
summary.textContent = emptyText;
|
||||
return;
|
||||
}
|
||||
|
||||
if (files.length === 1) {
|
||||
summary.textContent = files[0].name;
|
||||
return;
|
||||
}
|
||||
|
||||
summary.textContent = `Выбрано файлов: ${files.length}`;
|
||||
};
|
||||
|
||||
input.addEventListener("change", renderSummary);
|
||||
renderSummary();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user