@@ -412,6 +412,92 @@ function moveToSubfolder() {
412412 } ) ;
413413}
414414
415+ // Move/Rename Dialog Variables
416+ let currentMovePath = "" ;
417+
418+ function showMoveDialog ( gamePath ) {
419+ currentMovePath = gamePath ;
420+ const dialog = document . getElementById ( "move-dialog" ) ;
421+ const input = document . getElementById ( "move-path-input" ) ;
422+
423+ input . value = gamePath ;
424+ dialog . style . display = "flex" ;
425+
426+ // Focus and select the input text
427+ setTimeout ( ( ) => {
428+ input . focus ( ) ;
429+ input . select ( ) ;
430+ } , 100 ) ;
431+ }
432+
433+ function cancelMove ( ) {
434+ const dialog = document . getElementById ( "move-dialog" ) ;
435+ dialog . style . display = "none" ;
436+ currentMovePath = "" ;
437+ }
438+
439+ function confirmMove ( ) {
440+ const input = document . getElementById ( "move-path-input" ) ;
441+ const newPath = input . value . trim ( ) ;
442+
443+ if ( ! newPath ) {
444+ alert ( "Please enter a valid path" ) ;
445+ return ;
446+ }
447+
448+ if ( newPath === currentMovePath ) {
449+ cancelMove ( ) ;
450+ return ;
451+ }
452+
453+ // Send move request to server
454+ fetch ( "/move-folder" , {
455+ method : "POST" ,
456+ headers : {
457+ "Content-Type" : "application/json" ,
458+ } ,
459+ body : JSON . stringify ( {
460+ old_path : currentMovePath ,
461+ new_path : newPath ,
462+ } ) ,
463+ } )
464+ . then ( ( response ) => response . json ( ) )
465+ . then ( ( data ) => {
466+ if ( data . success ) {
467+ showCopyMessage ( `Moved folder to: ${ newPath } ` ) ;
468+ // Refresh the page to show updated folder structure
469+ setTimeout ( ( ) => window . location . reload ( ) , 1500 ) ;
470+ } else {
471+ alert ( "Failed to move folder: " + data . error ) ;
472+ }
473+ } )
474+ . catch ( ( err ) => {
475+ console . error ( "Failed to move folder: " , err ) ;
476+ alert ( "Failed to move folder. Please try again." ) ;
477+ } ) ;
478+
479+ cancelMove ( ) ;
480+ }
481+
482+ // Close dialog on Escape key
483+ document . addEventListener ( "keydown" , function ( event ) {
484+ if ( event . key === "Escape" ) {
485+ const dialog = document . getElementById ( "move-dialog" ) ;
486+ if ( dialog . style . display === "flex" ) {
487+ cancelMove ( ) ;
488+ }
489+ }
490+ } ) ;
491+
492+ // Close dialog when clicking outside the dialog content
493+ document
494+ . getElementById ( "move-dialog" )
495+ . addEventListener ( "click" , function ( event ) {
496+ if ( event . target === this ) {
497+ cancelMove ( ) ;
498+ }
499+ } ) ;
500+
415501// Initialize theme and other functionality on page load
416502document . addEventListener ( "DOMContentLoaded" , function ( ) {
417503 initializeTheme ( ) ;
@@ -420,4 +506,5 @@ document.addEventListener("DOMContentLoaded", function () {
420506 console . log ( "Available keyboard shortcuts:" ) ;
421507 console . log ( " Ctrl/Cmd + D: Toggle dark mode" ) ;
422508 console . log ( " Shift + Click: Range select checkboxes" ) ;
509+ console . log ( " Escape: Close move dialog" ) ;
423510} ) ;
0 commit comments