@@ -6901,78 +6901,61 @@ console.log("🛡️ ContextForge MCP Gateway admin.js initialized");
69016901
69026902
69036903// ===================================================================
6904- // BULK IMPORT TOOLS — MODAL WIRING
6904+ // BULK IMPORT MODAL WIRING
69056905// ===================================================================
69066906
6907- ( function initBulkImportModal ( ) {
6908- // ensure it runs after the DOM is ready
6909- window . addEventListener ( "DOMContentLoaded" , function ( ) {
6910- const openBtn = safeGetElement ( "open-bulk-import" , true ) ;
6911- const modalId = "bulk-import-modal" ;
6912- const modal = safeGetElement ( modalId , true ) ;
6913-
6914- if ( ! openBtn || ! modal ) {
6915- console . warn ( "Bulk Import modal wiring skipped (missing button or modal)." ) ;
6916- return ;
6917- }
6918-
6919- // avoid double-binding if admin.js gets evaluated more than once
6920- if ( openBtn . dataset . wired === "1" ) return ;
6921- openBtn . dataset . wired = "1" ;
6922-
6923- const closeBtn = safeGetElement ( "close-bulk-import" , true ) ;
6924- const backdrop = safeGetElement ( "bulk-import-backdrop" , true ) ;
6907+ function clearBulkImportResult ( ) {
69256908 const resultEl = safeGetElement ( "import-result" , true ) ;
6909+ if ( resultEl ) resultEl . innerHTML = "" ;
6910+ const indicator = safeGetElement ( "import-indicator" , true ) ;
6911+ if ( indicator ) indicator . classList . add ( "hidden" ) ;
6912+ }
69266913
6927- const focusTarget =
6928- modal . querySelector ( "#tools_json" ) ||
6929- modal . querySelector ( "#tools_file" ) ||
6930- modal . querySelector ( "[data-autofocus]" ) ;
6931-
6932- // helpers
6933- const open = ( e ) => {
6934- if ( e ) e . preventDefault ( ) ;
6935- // clear previous results each time we open
6936- if ( resultEl ) resultEl . innerHTML = "" ;
6937- openModal ( modalId ) ;
6938- // prevent background scroll
6939- document . documentElement . classList . add ( "overflow-hidden" ) ;
6940- document . body . classList . add ( "overflow-hidden" ) ;
6941- if ( focusTarget ) setTimeout ( ( ) => focusTarget . focus ( ) , 0 ) ;
6942- return false ;
6943- } ;
6914+ function setupBulkImportModal ( ) {
6915+ const openBtn = safeGetElement ( "open-bulk-import" , true ) ;
6916+ const modal = safeGetElement ( "bulk-import-modal" , true ) ;
6917+ const backdrop = safeGetElement ( "bulk-import-backdrop" , true ) ;
6918+ const closeBtn = safeGetElement ( "close-bulk-import" , true ) ;
69446919
6945- const close = ( ) => {
6946- // also clear results on close to keep things tidy
6947- closeModal ( modalId , "import-result" ) ;
6948- document . documentElement . classList . remove ( "overflow-hidden" ) ;
6949- document . body . classList . remove ( "overflow-hidden" ) ;
6950- } ;
6920+ if ( ! openBtn || ! modal ) return ;
6921+ if ( openBtn . dataset . wired === "1" ) return ; // prevent double wiring
6922+ openBtn . dataset . wired = "1" ;
69516923
6952- // wire events
6953- openBtn . addEventListener ( "click" , open ) ;
6924+ // OPEN → clear results, open modal, focus JSON/FILE
6925+ openBtn . addEventListener ( "click" , ( e ) => {
6926+ e . preventDefault ( ) ;
6927+ clearBulkImportResult ( ) ;
6928+ openModal ( "bulk-import-modal" ) ;
6929+ setTimeout ( ( ) => {
6930+ const ta = modal . querySelector ( 'textarea[name="tools_json"]' ) ;
6931+ const file = modal . querySelector ( 'input[type="file"]' ) ;
6932+ ( ta || file ) ?. focus ?. ( ) ;
6933+ } , 0 ) ;
6934+ } ) ;
69546935
6936+ // CLOSE BUTTON → close & clear
69556937 if ( closeBtn ) {
6956- closeBtn . addEventListener ( "click" , ( e ) => {
6957- e . preventDefault ( ) ;
6958- close ( ) ;
6959- } ) ;
6938+ closeBtn . addEventListener ( "click" , ( e ) => {
6939+ e . preventDefault ( ) ;
6940+ closeModal ( "bulk-import-modal" , "import-result" ) ;
6941+ } ) ;
69606942 }
69616943
6962- // click on backdrop only (not the dialog content) closes the modal
6944+ // BACKDROP → close & clear
69636945 if ( backdrop ) {
6964- backdrop . addEventListener ( "click" , ( e ) => {
6965- if ( e . target === backdrop ) close ( ) ;
6966- } ) ;
6946+ backdrop . addEventListener ( "click" , ( ) => {
6947+ closeModal ( "bulk-import-modal" , "import-result" ) ;
6948+ } ) ;
69676949 }
69686950
6969- // ESC to close
6970- modal . addEventListener ( "keydown" , ( e ) => {
6971- if ( e . key === "Escape" ) {
6972- e . stopPropagation ( ) ;
6973- close ( ) ;
6974- }
6951+ // ESC → close & clear
6952+ document . addEventListener ( "keydown" , ( e ) => {
6953+ if ( e . key === "Escape" && AppState . isModalActive ( "bulk-import-modal" ) ) {
6954+ closeModal ( "bulk-import-modal" , "import-result" ) ;
6955+ }
69756956 } ) ;
6957+ }
69766958
6977- } ) ;
6978- } ) ( ) ;
6959+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
6960+ try { setupBulkImportModal ( ) ; } catch ( _ ) { /* no-op */ }
6961+ } ) ;
0 commit comments