refactor: Modularize UI components and utilities
- Extract UI components into separate JS files - Centralize configuration values in config.js - Introduce a dedicated logger module - Improve file tree drag-and-drop and undo functionality - Refactor modal handling to a single manager - Add URL routing support for SPA navigation - Implement view mode for read-only access
This commit is contained in:
37
static/js/file-upload.js
Normal file
37
static/js/file-upload.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* File Upload Module
|
||||
* Handles file upload dialog for uploading files to the file tree
|
||||
*/
|
||||
|
||||
/**
|
||||
* Show file upload dialog
|
||||
* @param {string} targetPath - The target directory path
|
||||
* @param {Function} onUpload - Callback function to handle file upload
|
||||
*/
|
||||
function showFileUploadDialog(targetPath, onUpload) {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.multiple = true;
|
||||
|
||||
input.addEventListener('change', async (e) => {
|
||||
const files = Array.from(e.target.files);
|
||||
if (files.length === 0) return;
|
||||
|
||||
for (const file of files) {
|
||||
try {
|
||||
await onUpload(targetPath, file);
|
||||
} catch (error) {
|
||||
Logger.error('Upload failed:', error);
|
||||
if (window.showNotification) {
|
||||
window.showNotification(`Failed to upload ${file.name}`, 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
input.click();
|
||||
}
|
||||
|
||||
// Make function globally available
|
||||
window.showFileUploadDialog = showFileUploadDialog;
|
||||
|
||||
Reference in New Issue
Block a user