diff --git a/eveai_app/templates/eveai_json_editor.html b/eveai_app/templates/eveai_json_editor.html index b457a6d..b0c4fba 100644 --- a/eveai_app/templates/eveai_json_editor.html +++ b/eveai_app/templates/eveai_json_editor.html @@ -40,10 +40,10 @@ window.EveAI.JsonEditors = { mainMenuBar: options.mainMenuBar !== undefined ? options.mainMenuBar : true, navigationBar: options.navigationBar !== undefined ? options.navigationBar : false, statusBar: options.statusBar !== undefined ? options.statusBar : !isReadOnly, - onChange: (updatedContent, previousContent, { contentErrors, patchResult }) => { - // content is an object { json: unknown } | { text: string } - console.log('onChange', { updatedContent, previousContent, contentErrors, patchResult }) - } + onChange: options.onChange || ((updatedContent, previousContent, { contentErrors, patchResult }) => { + // Default onChange behavior - alleen loggen + console.log('onChange', { updatedContent, previousContent, contentErrors, patchResult }); + }) }; console.log('EditorProps', editorProps); @@ -107,13 +107,51 @@ document.addEventListener('DOMContentLoaded', function() { window.EveAI.JsonEditors.initialize(containerId, data, { mode: isReadOnly ? 'preview' : 'tree', readOnly: isReadOnly, - onChangeText: isReadOnly ? undefined : (jsonString) => { textarea.value = jsonString; } + onChange: isReadOnly ? undefined : (updatedContent, previousContent, { contentErrors, patchResult }) => { + // Automatische synchronisatie naar textarea bij elke wijziging + if (updatedContent.json !== undefined) { + textarea.value = JSON.stringify(updatedContent.json, null, 2); + } else if (updatedContent.text !== undefined) { + textarea.value = updatedContent.text; + } + console.log('Textarea automatisch bijgewerkt via onChange'); + } }); } catch (e) { console.error('Error parsing initial JSON for .json-editor:', e); container.innerHTML = `
Error loading JSON data:
${e.message}
`; } }); + + // Real-time synchronisatie als extra beveiliging + setInterval(function() { + document.querySelectorAll('.json-editor').forEach(function(textarea) { + if (textarea.style.display === 'none') { // Alleen voor verborgen textareas (zoals in edit forms) + const containerId = textarea.id + '-editor'; + const editor = window.EveAI?.JsonEditors?.get(containerId); + if (editor && editor.get) { + try { + const content = editor.get(); + let newValue = ''; + if (content.json !== undefined) { + newValue = JSON.stringify(content.json, null, 2); + } else if (content.text !== undefined) { + newValue = content.text; + } + + // Alleen updaten als de waarde daadwerkelijk is veranderd + if (textarea.value !== newValue) { + textarea.value = newValue; + console.log('Real-time sync uitgevoerd voor', textarea.id); + } + } catch (e) { + // Stil falen - geen console spam + } + } + } + }); + }, 1000); // Elke seconde controleren + // Alleen-lezen containers document.querySelectorAll('.json-viewer').forEach(function(container) { const dataElement = document.getElementById(container.id + '-data'); diff --git a/eveai_app/templates/interaction/edit_asset.html b/eveai_app/templates/interaction/edit_asset.html index f0f3444..8a8d35d 100644 --- a/eveai_app/templates/interaction/edit_asset.html +++ b/eveai_app/templates/interaction/edit_asset.html @@ -77,122 +77,42 @@