@@ -6899,63 +6899,73 @@ window.loadAuthHeaders = loadAuthHeaders;
68996899
69006900console . log ( "🛡️ ContextForge MCP Gateway admin.js initialized" ) ;
69016901
6902-
69036902// ===================================================================
69046903// BULK IMPORT MODAL WIRING
69056904// ===================================================================
69066905
69076906function clearBulkImportResult ( ) {
6908- 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" ) ;
6907+ const resultEl = safeGetElement ( "import-result" , true ) ;
6908+ if ( resultEl ) {
6909+ resultEl . innerHTML = "" ;
6910+ }
6911+ const indicator = safeGetElement ( "import-indicator" , true ) ;
6912+ if ( indicator ) {
6913+ indicator . classList . add ( "hidden" ) ;
6914+ }
69126915}
69136916
69146917function 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 ) ;
6919-
6920- if ( ! openBtn || ! modal ) return ;
6921- if ( openBtn . dataset . wired === "1" ) return ; // prevent double wiring
6922- openBtn . dataset . wired = "1" ;
6923-
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 ) ;
6918+ const openBtn = safeGetElement ( "open-bulk-import" , true ) ;
6919+ const modal = safeGetElement ( "bulk-import-modal" , true ) ;
6920+ const backdrop = safeGetElement ( "bulk-import-backdrop" , true ) ;
6921+ const closeBtn = safeGetElement ( "close-bulk-import" , true ) ;
6922+
6923+ if ( ! openBtn || ! modal ) {
6924+ return ;
6925+ }
6926+ if ( openBtn . dataset . wired === "1" ) {
6927+ return ; // prevent double wiring
6928+ }
6929+ openBtn . dataset . wired = "1" ;
6930+
6931+ // OPEN → clear results, open modal, focus JSON/FILE
6932+ openBtn . addEventListener ( "click" , ( e ) => {
6933+ e . preventDefault ( ) ;
6934+ clearBulkImportResult ( ) ;
6935+ openModal ( "bulk-import-modal" ) ;
6936+ setTimeout ( ( ) => {
6937+ const ta = modal . querySelector ( 'textarea[name="tools_json"]' ) ;
6938+ const file = modal . querySelector ( 'input[type="file"]' ) ;
6939+ ( ta || file ) ?. focus ?. ( ) ;
6940+ } , 0 ) ;
6941+ } ) ;
6942+
6943+ // CLOSE BUTTON → close & clear
6944+ if ( closeBtn ) {
6945+ closeBtn . addEventListener ( "click" , ( e ) => {
6946+ e . preventDefault ( ) ;
6947+ closeModal ( "bulk-import-modal" , "import-result" ) ;
69346948 } ) ;
6949+ }
69356950
6936- // CLOSE BUTTON → close & clear
6937- if ( closeBtn ) {
6938- closeBtn . addEventListener ( "click" , ( e ) => {
6939- e . preventDefault ( ) ;
6940- closeModal ( "bulk-import-modal" , "import-result" ) ;
6941- } ) ;
6942- }
6951+ // BACKDROP → close & clear
6952+ if ( backdrop ) {
6953+ backdrop . addEventListener ( "click" , ( ) => {
6954+ closeModal ( "bulk-import-modal" , "import-result" ) ;
6955+ } ) ;
6956+ }
69436957
6944- // BACKDROP → close & clear
6945- if ( backdrop ) {
6946- backdrop . addEventListener ( "click" , ( ) => {
6947- closeModal ( "bulk-import-modal" , "import-result" ) ;
6948- } ) ;
6958+ // ESC → close & clear
6959+ document . addEventListener ( "keydown" , ( e ) => {
6960+ if ( e . key === "Escape" && AppState . isModalActive ( "bulk-import-modal" ) ) {
6961+ closeModal ( "bulk-import-modal" , "import-result" ) ;
69496962 }
6950-
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- }
6956- } ) ;
6963+ } ) ;
69576964}
69586965
69596966document . addEventListener ( "DOMContentLoaded" , ( ) => {
6960- try { setupBulkImportModal ( ) ; } catch ( _ ) { /* no-op */ }
6967+ try {
6968+ setupBulkImportModal ( ) ;
6969+ } catch ( _ ) {
6970+ }
69616971} ) ;
0 commit comments