Fix name not in rename modal

This commit is contained in:
2025-05-31 12:09:24 +02:00
parent f13f5a1e08
commit 821330eba5
3 changed files with 21 additions and 6 deletions

View File

@@ -29,6 +29,8 @@ export class FileManager {
this.fileToDeletePath = ''; this.fileToDeletePath = '';
this.fileToMove = null; this.fileToMove = null;
this.fileToMovePath = ''; this.fileToMovePath = '';
this.fileToRename = null;
this.fileToRenamePath = '';
console.log('[FileManager] Initialized with roomManager:', roomManager); console.log('[FileManager] Initialized with roomManager:', roomManager);
} }
@@ -139,7 +141,10 @@ export class FileManager {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content') 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
}, },
body: JSON.stringify({ new_name: newName }) body: JSON.stringify({
new_name: newName,
path: this.fileToRenamePath
})
}); });
console.log('[FileManager] Rename response status:', response.status); console.log('[FileManager] Rename response status:', response.status);
@@ -157,6 +162,9 @@ export class FileManager {
await this.roomManager.viewManager.renderFiles(this.currentFiles); await this.roomManager.viewManager.renderFiles(this.currentFiles);
console.log('[FileManager] File renamed and view updated'); console.log('[FileManager] File renamed and view updated');
} }
// Clear the rename state
this.fileToRename = null;
this.fileToRenamePath = '';
return { success: true, message: 'File renamed successfully' }; return { success: true, message: 'File renamed successfully' };
} else { } else {
throw new Error(result.message || 'Failed to rename file'); throw new Error(result.message || 'Failed to rename file');

View File

@@ -174,8 +174,15 @@ export class ModalManager {
/** /**
* Shows the rename modal for a file or folder. * Shows the rename modal for a file or folder.
* @param {string} filename - The current name of the file/folder * @param {string} filename - The current name of the file/folder
* @param {string} [path=''] - The path of the file/folder
*/ */
showRenameModal(filename) { showRenameModal(filename, path = '') {
console.log('[ModalManager] Showing rename modal for:', { filename, path });
// Store the file info in the FileManager
this.roomManager.fileManager.fileToRename = filename;
this.roomManager.fileManager.fileToRenamePath = path;
document.getElementById('renameError').textContent = ''; document.getElementById('renameError').textContent = '';
const ext = filename.includes('.') ? filename.substring(filename.lastIndexOf('.')) : ''; const ext = filename.includes('.') ? filename.substring(filename.lastIndexOf('.')) : '';
const isFile = ext && filename.lastIndexOf('.') > 0; const isFile = ext && filename.lastIndexOf('.') > 0;
@@ -444,9 +451,9 @@ export class ModalManager {
} }
const result = await this.roomManager.fileManager.renameFile( const result = await this.roomManager.fileManager.renameFile(
this.renameTarget, this.roomManager.fileManager.fileToRename,
newName, newName,
this.roomManager.currentPath this.roomManager.fileManager.fileToRenamePath
); );
if (result.success) { if (result.success) {

View File

@@ -351,9 +351,9 @@ export class ViewManager {
if (this.roomManager.canRename) { if (this.roomManager.canRename) {
actions.push(` actions.push(`
<button class="btn btn-sm file-action-btn" title="Rename" onclick="window.roomManager.modalManager.showRenameModal('${file.id}')" <button class="btn btn-sm file-action-btn" title="Rename" onclick="window.roomManager.modalManager.showRenameModal('${file.name}', '${file.path || ''}')"
style="background-color:var(--primary-opacity-8);color:var(--primary-color);"> style="background-color:var(--primary-opacity-8);color:var(--primary-color);">
<i class="fas fa-edit"></i> <i class="fas fa-pen"></i>
</button> </button>
`); `);
} }