From b38027d7ad3cc6084e56f04f7ef4a74c75a36940 Mon Sep 17 00:00:00 2001 From: Chuck Date: Mon, 5 Jan 2026 14:16:52 -0500 Subject: [PATCH] Fix: Wrap array-of-objects functions in window check and move outside IIFE Ensure functions are available globally by wrapping them in a window check and ensuring they're defined outside any IIFE scope. Also fix internal function calls to use window.updateArrayObjectData for consistency. --- web_interface/static/v3/plugins_manager.js | 39 ++++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/web_interface/static/v3/plugins_manager.js b/web_interface/static/v3/plugins_manager.js index 9ebb7342..fcaa0859 100644 --- a/web_interface/static/v3/plugins_manager.js +++ b/web_interface/static/v3/plugins_manager.js @@ -3439,7 +3439,9 @@ window.updateKeyValuePairData = function(fieldId, fullKey) { }; // Functions to handle array-of-objects -window.addArrayObjectItem = function(fieldId, fullKey, maxItems) { +// Define these at the top level (outside any IIFE) to ensure they're always available +if (typeof window !== 'undefined') { + window.addArrayObjectItem = function(fieldId, fullKey, maxItems) { const itemsContainer = document.getElementById(fieldId + '_items'); const hiddenInput = document.getElementById(fieldId + '_data'); if (!itemsContainer || !hiddenInput) return; @@ -3472,7 +3474,7 @@ window.addArrayObjectItem = function(fieldId, fullKey, maxItems) { const newIndex = currentItems.length; const itemHtml = renderArrayObjectItem(fieldId, fullKey, itemsSchema.properties, {}, newIndex, itemsSchema); itemsContainer.insertAdjacentHTML('beforeend', itemHtml); - updateArrayObjectData(fieldId); + window.updateArrayObjectData(fieldId); // Update add button state const addButton = itemsContainer.nextElementSibling; @@ -3481,9 +3483,9 @@ window.addArrayObjectItem = function(fieldId, fullKey, maxItems) { addButton.style.opacity = '0.5'; addButton.style.cursor = 'not-allowed'; } -}; + }; -window.removeArrayObjectItem = function(fieldId, index) { + window.removeArrayObjectItem = function(fieldId, index) { const itemsContainer = document.getElementById(fieldId + '_items'); if (!itemsContainer) return; @@ -3512,7 +3514,7 @@ window.removeArrayObjectItem = function(fieldId, index) { } }); }); - updateArrayObjectData(fieldId); + window.updateArrayObjectData(fieldId); // Update add button state const addButton = itemsContainer.nextElementSibling; @@ -3525,9 +3527,9 @@ window.removeArrayObjectItem = function(fieldId, index) { } } } -}; + }; -window.updateArrayObjectData = function(fieldId) { + window.updateArrayObjectData = function(fieldId) { const itemsContainer = document.getElementById(fieldId + '_items'); const hiddenInput = document.getElementById(fieldId + '_data'); if (!itemsContainer || !hiddenInput) return; @@ -3572,18 +3574,19 @@ window.updateArrayObjectData = function(fieldId) { hiddenInput.value = JSON.stringify(items); }; -window.handleArrayObjectFileUpload = function(event, fieldId, itemIndex, propKey, pluginId) { - // TODO: Implement file upload handling for array object items - // This is a placeholder - file upload in nested objects needs special handling - console.log('File upload for array object item:', { fieldId, itemIndex, propKey, pluginId }); - updateArrayObjectData(fieldId); -}; + window.handleArrayObjectFileUpload = function(event, fieldId, itemIndex, propKey, pluginId) { + // TODO: Implement file upload handling for array object items + // This is a placeholder - file upload in nested objects needs special handling + console.log('File upload for array object item:', { fieldId, itemIndex, propKey, pluginId }); + window.updateArrayObjectData(fieldId); + }; -window.removeArrayObjectFile = function(fieldId, itemIndex, propKey) { - // TODO: Implement file removal for array object items - console.log('File removal for array object item:', { fieldId, itemIndex, propKey }); - updateArrayObjectData(fieldId); -}; + window.removeArrayObjectFile = function(fieldId, itemIndex, propKey) { + // TODO: Implement file removal for array object items + console.log('File removal for array object item:', { fieldId, itemIndex, propKey }); + window.updateArrayObjectData(fieldId); + }; +} // Function to toggle nested sections window.toggleNestedSection = function(sectionId, event) {