additional cleanup and fixes
This commit is contained in:
@@ -35,18 +35,6 @@ export function loadFileList() {
|
||||
|
||||
|
||||
|
||||
|
||||
export function toggleDeleteButton() {
|
||||
const selectedFiles = document.querySelectorAll(".file-checkbox:checked");
|
||||
const deleteBtn = document.getElementById("deleteSelectedBtn");
|
||||
const copyBtn = document.getElementById("copySelectedBtn");
|
||||
const moveBtn = document.getElementById("moveSelectedBtn");
|
||||
const disabled = selectedFiles.length === 0;
|
||||
deleteBtn.disabled = disabled;
|
||||
if (copyBtn) copyBtn.disabled = disabled;
|
||||
if (moveBtn) moveBtn.disabled = disabled;
|
||||
}
|
||||
|
||||
export function toggleAllCheckboxes(source) {
|
||||
const checkboxes = document.querySelectorAll(".file-checkbox");
|
||||
checkboxes.forEach(checkbox => checkbox.checked = source.checked);
|
||||
@@ -90,59 +78,6 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
}
|
||||
});
|
||||
|
||||
export function editFile(fileName) {
|
||||
const threshold = 10 * 1024 * 1024; // 10 MB threshold
|
||||
fetch(`uploads/${encodeURIComponent(fileName)}`, { method: 'HEAD' })
|
||||
.then(response => {
|
||||
const fileSize = parseInt(response.headers.get('Content-Length') || "0", 10);
|
||||
if (fileSize > threshold) {
|
||||
alert("This file is too large to edit in the browser.");
|
||||
return;
|
||||
}
|
||||
return fetch(`uploads/${encodeURIComponent(fileName)}?t=${new Date().getTime()}`);
|
||||
})
|
||||
.then(response => {
|
||||
if (!response) return;
|
||||
if (!response.ok) throw new Error("HTTP error! Status: " + response.status);
|
||||
return response.text();
|
||||
})
|
||||
.then(content => {
|
||||
if (!content) return;
|
||||
const modal = document.createElement("div");
|
||||
modal.id = "editorContainer";
|
||||
modal.classList.add("modal", "editor-modal");
|
||||
modal.innerHTML = `
|
||||
<h3>Editing: ${fileName}</h3>
|
||||
<textarea id="fileEditor" style="width:100%; height:60%; resize:none;">${content}</textarea>
|
||||
<div style="margin-top:10px; text-align:right;">
|
||||
<button onclick="saveFile('${fileName}')" class="btn btn-primary">Save</button>
|
||||
<button onclick="document.getElementById('editorContainer').remove()" class="btn btn-secondary">Close</button>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(modal);
|
||||
modal.style.display = "block";
|
||||
})
|
||||
.catch(error => console.error("Error in editFile:", error));
|
||||
}
|
||||
|
||||
export function saveFile(fileName) {
|
||||
const editor = document.getElementById("fileEditor");
|
||||
if (!editor) {
|
||||
console.error("Editor not found!");
|
||||
return;
|
||||
}
|
||||
const fileData = {
|
||||
fileName: fileName,
|
||||
content: editor.value
|
||||
};
|
||||
sendRequest("saveFile.php", "POST", fileData)
|
||||
.then(result => {
|
||||
alert(result.success || result.error);
|
||||
document.getElementById("editorContainer")?.remove();
|
||||
loadFileList();
|
||||
})
|
||||
.catch(error => console.error("Error saving file:", error));
|
||||
}
|
||||
|
||||
// ===== NEW CODE: Copy & Move Functions =====
|
||||
|
||||
@@ -159,6 +94,10 @@ export function copySelectedFiles() {
|
||||
alert("Please select a target folder.");
|
||||
return;
|
||||
}
|
||||
if (currentFolder === targetFolder) {
|
||||
alert("Cannot copy files to the same folder.");
|
||||
return;
|
||||
}
|
||||
// Send the correct keys
|
||||
sendRequest("copyFiles.php", "POST", {
|
||||
source: currentFolder,
|
||||
@@ -172,8 +111,6 @@ export function copySelectedFiles() {
|
||||
.catch(error => console.error("Error copying files:", error));
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function moveSelectedFiles() {
|
||||
const selectedFiles = Array.from(document.querySelectorAll(".file-checkbox:checked"))
|
||||
.map(checkbox => checkbox.value);
|
||||
@@ -186,11 +123,10 @@ export function moveSelectedFiles() {
|
||||
alert("Please select a target folder.");
|
||||
return;
|
||||
}
|
||||
console.log("Payload:", {
|
||||
source: currentFolder,
|
||||
destination: document.getElementById("copyMoveFolderSelect").value,
|
||||
files: selectedFiles
|
||||
});
|
||||
if (currentFolder === targetFolder) {
|
||||
alert("Cannot move files to the same folder.");
|
||||
return;
|
||||
}
|
||||
sendRequest("moveFiles.php", "POST", {
|
||||
source: currentFolder,
|
||||
destination: targetFolder,
|
||||
@@ -204,14 +140,13 @@ export function moveSelectedFiles() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Populate the Copy/Move folder dropdown
|
||||
export function loadCopyMoveFolderList() {
|
||||
$.get('getFolderList.php', function (response) {
|
||||
const folderSelect = $('#copyMoveFolderSelect');
|
||||
folderSelect.empty();
|
||||
// Always add a "Root" option as the default.
|
||||
folderSelect.append($('<option>', { value: "root", text: "Root" }));
|
||||
folderSelect.append($('<option>', { value: "root", text: "(Root)" }));
|
||||
if (Array.isArray(response) && response.length > 0) {
|
||||
response.forEach(function (folder) {
|
||||
folderSelect.append($('<option>', {
|
||||
@@ -224,11 +159,8 @@ export function loadCopyMoveFolderList() {
|
||||
}
|
||||
|
||||
// Attach functions to window for inline onclick support
|
||||
window.toggleDeleteButton = toggleDeleteButton;
|
||||
window.toggleAllCheckboxes = toggleAllCheckboxes;
|
||||
window.deleteSelectedFiles = deleteSelectedFiles;
|
||||
window.editFile = editFile;
|
||||
window.saveFile = saveFile;
|
||||
window.loadFileList = loadFileList;
|
||||
window.copySelectedFiles = copySelectedFiles;
|
||||
window.moveSelectedFiles = moveSelectedFiles;
|
||||
|
||||
Reference in New Issue
Block a user