mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-08 16:47:38 +03:00
fix move functionality
This commit is contained in:
parent
39a07f07b1
commit
88633bda1a
@ -687,10 +687,13 @@
|
|||||||
<h3>✏️ Edit</h3>
|
<h3>✏️ Edit</h3>
|
||||||
<div class="folder-form">
|
<div class="folder-form">
|
||||||
<input type="hidden" id="editItemType">
|
<input type="hidden" id="editItemType">
|
||||||
|
<input type="hidden" name="originalName">
|
||||||
|
|
||||||
|
|
||||||
<label htmlFor="path-input" class="input-label">Path</label>
|
<label htmlFor="path-input" class="input-label">Path</label>
|
||||||
<select id="editItemPath" class="text-input" name="path" value="" />
|
<select id="editItemPath" class="text-input" name="path" value="" />
|
||||||
<label htmlFor="name-input" class="file-info">Name</label>
|
<label htmlFor="name-input" class="file-info">Name</label>
|
||||||
<input id="editItemName" value="" autoFocus type="text" class="folder-input" placeholder="Name" />
|
<input id="editItemName" name="name" value="" autoFocus type="text" class="folder-input" placeholder="Name" />
|
||||||
<button class="folder-btn" onclick="confirmEdit()">Save</button>
|
<button class="folder-btn" onclick="confirmEdit()">Save</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -699,6 +702,11 @@
|
|||||||
<script>
|
<script>
|
||||||
// get current path from query parameter
|
// get current path from query parameter
|
||||||
let currentPath = decodeURIComponent(new URLSearchParams(window.location.search).get('path') || '/');
|
let currentPath = decodeURIComponent(new URLSearchParams(window.location.search).get('path') || '/');
|
||||||
|
let files = [];
|
||||||
|
|
||||||
|
function joinPath(dirPath, fileName) {
|
||||||
|
return [dirPath.replace(/\/$/, ""), fileName.replace(/^\//, "")].join("/")
|
||||||
|
}
|
||||||
|
|
||||||
function escapeHtml(unsafe) {
|
function escapeHtml(unsafe) {
|
||||||
return unsafe
|
return unsafe
|
||||||
@ -757,7 +765,6 @@
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
let files = [];
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/files?path=' + encodeURIComponent(currentPath));
|
const response = await fetch('/api/files?path=' + encodeURIComponent(currentPath));
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@ -1139,34 +1146,46 @@ function retryAllFailedUploads() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Edit functions
|
// Edit functions
|
||||||
|
|
||||||
|
const editModal = document.querySelector("#editModal");
|
||||||
function openEditModal(name, path, isFolder) {
|
function openEditModal(name, path, isFolder) {
|
||||||
// document.getElementById('editItemName').textContent = (isFolder ? '📁 ' : '📄 ') + name;
|
// document.getElementById('editItemName').textContent = (isFolder ? '📁 ' : '📄 ') + name;
|
||||||
document.getElementById('editItemName').value = name;
|
editModal.querySelector('#editItemName').value = name;
|
||||||
document.getElementById('editItemPath').value = path;
|
editModal.querySelector('[name="originalName"]').value = name;
|
||||||
document.getElementById('editItemType').value = isFolder ? 'folder' : 'file';
|
const pathSelect = editModal.querySelector('#editItemPath');
|
||||||
document.getElementById('editModal').classList.add('open');
|
const availableDirectories = files.filter(file => file.isDirectory).map(f => joinPath(currentPath, f.name));
|
||||||
|
availableDirectories.unshift(currentPath)
|
||||||
|
pathSelect.innerHTML = availableDirectories.map(d => `<option value="${d}">${d}</option>`);
|
||||||
|
|
||||||
|
const dirs = path.split("/");
|
||||||
|
const itemPath = dirs.slice(0, dirs.length - 1).join("/") || "/";
|
||||||
|
editModal.querySelector('#editItemPath').value = itemPath;
|
||||||
|
editModal.querySelector('#editItemType').value = isFolder ? 'folder' : 'file';
|
||||||
|
editModal.classList.add('open');
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeEditModal() {
|
function closeEditModal() {
|
||||||
document.getElementById('editModal').classList.remove('open');
|
editModal.classList.remove('open');
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmEdit() {
|
function confirmEdit() {
|
||||||
const editModal = document.querySelector("#editModal");
|
const originalPath = currentPath;
|
||||||
const path = editModal.querySelector('[name="path"]').value;
|
const originalName = editModal.querySelector('[name="originalName"]').value;
|
||||||
const newPath = editModal.querySelector('[name="newPath"]').value;
|
|
||||||
|
const newPath = editModal.querySelector('[name="path"]').value;
|
||||||
|
const newName = editModal.querySelector('[name="name"]').value;
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('path', path);
|
formData.append('path', joinPath(originalPath, originalName));
|
||||||
formData.append('new_path', newPath);
|
formData.append('new_path', joinPath(newPath, newName));
|
||||||
|
|
||||||
fetch('/api/move', {
|
fetch('/api/move', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
|
closeEditModal();
|
||||||
reloadContent();
|
reloadContent();
|
||||||
closeDeleteModal();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
alert('Failed to edit: ' + xhr.responseText);
|
alert('Failed to edit: ' + xhr.responseText);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user