// domUtils.js import { t } from './i18n.js'; import { openDownloadModal } from './fileActions.js'; // Basic DOM Helpers export function toggleVisibility(elementId, shouldShow) { const element = document.getElementById(elementId); if (element) { element.style.display = shouldShow ? "block" : "none"; } else { console.error(t("element_not_found", { id: elementId })); } } export function escapeHTML(str) { return String(str) .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } export function toggleAllCheckboxes(masterCheckbox) { const checkboxes = document.querySelectorAll(".file-checkbox"); checkboxes.forEach(chk => { chk.checked = masterCheckbox.checked; updateRowHighlight(chk); }); updateFileActionButtons(); } export function updateFileActionButtons() { const fileCheckboxes = document.querySelectorAll("#fileList .file-checkbox"); const selectedCheckboxes = document.querySelectorAll("#fileList .file-checkbox:checked"); const copyBtn = document.getElementById("copySelectedBtn"); const moveBtn = document.getElementById("moveSelectedBtn"); const deleteBtn = document.getElementById("deleteSelectedBtn"); const zipBtn = document.getElementById("downloadZipBtn"); const extractZipBtn = document.getElementById("extractZipBtn"); // keep the “select all” in sync —— const master = document.getElementById("selectAll"); if (master) { if (selectedCheckboxes.length === fileCheckboxes.length) { master.checked = true; master.indeterminate = false; } else if (selectedCheckboxes.length === 0) { master.checked = false; master.indeterminate = false; } else { master.checked = false; master.indeterminate = true; } } if (fileCheckboxes.length === 0) { if (copyBtn) copyBtn.style.display = "none"; if (moveBtn) moveBtn.style.display = "none"; if (deleteBtn) deleteBtn.style.display = "none"; if (zipBtn) zipBtn.style.display = "none"; if (extractZipBtn) extractZipBtn.style.display = "none"; } else { if (copyBtn) copyBtn.style.display = "inline-block"; if (moveBtn) moveBtn.style.display = "inline-block"; if (deleteBtn) deleteBtn.style.display = "inline-block"; if (zipBtn) zipBtn.style.display = "inline-block"; if (extractZipBtn) extractZipBtn.style.display = "inline-block"; const anySelected = selectedCheckboxes.length > 0; if (copyBtn) copyBtn.disabled = !anySelected; if (moveBtn) moveBtn.disabled = !anySelected; if (deleteBtn) deleteBtn.disabled = !anySelected; if (zipBtn) zipBtn.disabled = !anySelected; if (extractZipBtn) { // Enable only if at least one selected file ends with .zip (case-insensitive). const anyZipSelected = Array.from(selectedCheckboxes).some(chk => chk.value.toLowerCase().endsWith(".zip") ); extractZipBtn.disabled = !anyZipSelected; } } } export function showToast(message, duration = 3000) { const toast = document.getElementById("customToast"); if (!toast) { console.error("Toast element not found"); return; } toast.textContent = message; toast.style.display = "block"; // Force reflow for transition effect. void toast.offsetWidth; toast.classList.add("show"); setTimeout(() => { toast.classList.remove("show"); setTimeout(() => { toast.style.display = "none"; }, 500); }, duration); } // --- DOM Building Functions for File Table --- export function buildSearchAndPaginationControls({ currentPage, totalPages, searchTerm }) { const safeSearchTerm = escapeHTML(searchTerm); // Choose the placeholder text based on advanced search mode const placeholderText = window.advancedSearchEnabled ? t("search_placeholder_advanced") : t("search_placeholder"); return `
| ${t("file_name")} ${sortOrder.column === "name" ? (sortOrder.ascending ? "▲" : "▼") : ""} | ${t("actions")} | |
|---|---|---|
| ${safeFileName} |