more commits..

This commit is contained in:
pika 2025-03-23 03:53:45 +01:00
parent 6dda02141e
commit 7823be6481
20 changed files with 1835 additions and 631 deletions

View file

@ -243,4 +243,133 @@ document.addEventListener('DOMContentLoaded', function () {
document.getElementById('new-name').focus();
});
}
});
// Delete functionality
const deleteModal = document.getElementById('delete-modal');
const deleteForm = document.getElementById('delete-form');
const deleteItemIdInput = document.getElementById('delete-item-id');
if (deleteModal && deleteForm) {
// Update the form action when the modal is shown
document.querySelectorAll('.action-btn.delete').forEach(btn => {
btn.addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
const itemElement = this.closest('.folder-item, .file-item');
const itemId = itemElement.dataset.id;
// Set the item ID in the form
deleteItemIdInput.value = itemId;
// Update the form action URL
const formAction = deleteForm.action;
deleteForm.action = formAction.replace('placeholder', itemId);
// Show the modal
deleteModal.classList.add('active');
});
});
// Close modal when cancel is clicked
deleteModal.querySelector('.modal-cancel').addEventListener('click', function () {
deleteModal.classList.remove('active');
});
// Close modal when X is clicked
deleteModal.querySelector('.modal-close').addEventListener('click', function () {
deleteModal.classList.remove('active');
});
}
});
// Browser-specific functionality
document.addEventListener('DOMContentLoaded', function () {
// Initialize folder browser view
initializeFolderBrowser();
});
function initializeFolderBrowser() {
// Handle item selection
const items = document.querySelectorAll('.folder-item, .file-item');
items.forEach(item => {
item.addEventListener('click', function (e) {
// Only select if not clicking on an action button
if (!e.target.closest('.file-actions')) {
// Remove selection from all items
items.forEach(i => i.classList.remove('selected'));
// Select this item
this.classList.add('selected');
}
});
});
// Handle folder creation form submission
const newFolderForm = document.getElementById('new-folder-form');
if (newFolderForm) {
newFolderForm.addEventListener('submit', function (e) {
// Form will be submitted normally, we just close the modal
const modal = document.getElementById('new-folder-modal');
if (modal) {
modal.classList.remove('active');
}
});
}
// Handle file/folder actions from context menu
document.querySelectorAll('.context-menu-item').forEach(item => {
item.addEventListener('click', function () {
const action = this.getAttribute('data-action');
const menu = this.closest('.context-menu');
const itemId = menu.getAttribute('data-item-id');
const itemType = menu.getAttribute('data-item-type');
// Handle different actions
switch (action) {
case 'open':
if (itemType === 'folder') {
window.location.href = `/files/browser/${itemId}`;
}
break;
case 'download':
if (itemType === 'file') {
window.location.href = `/files/download/${itemId}`;
}
break;
case 'share':
// TODO: Implement share functionality
alert('Share functionality coming soon');
break;
case 'rename':
// TODO: Implement rename functionality
alert('Rename functionality coming soon');
break;
case 'delete':
if (confirm(`Are you sure you want to delete this ${itemType}?`)) {
// Send delete request to server
fetch(`/files/delete/${itemType}/${itemId}`, {
method: 'POST',
})
.then(response => response.json())
.then(data => {
if (data.success) {
// Remove item from DOM
document.querySelector(`[data-id="${itemId}"]`).remove();
} else {
alert(`Failed to delete ${itemType}: ${data.error}`);
}
})
.catch(error => {
console.error('Error:', error);
alert(`An error occurred while deleting the ${itemType}`);
});
}
break;
}
// Hide menu after action
menu.style.display = 'none';
});
});
}