- bug TRA-68 solved - bug in javascript code did not pass changed json content.
This commit is contained in:
@@ -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 = `<div class="alert alert-danger p-3"><strong>Error loading JSON data:</strong><br>${e.message}</div>`;
|
||||
}
|
||||
});
|
||||
|
||||
// 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');
|
||||
|
||||
@@ -77,122 +77,42 @@
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const textareaElement = document.getElementById('json_content');
|
||||
let currentEditor = null;
|
||||
|
||||
// Wacht even en probeer dan de editor te krijgen via de EveAI namespace
|
||||
setTimeout(function() {
|
||||
currentEditor = window.EveAI?.JsonEditors?.get('json_content-editor');
|
||||
if (currentEditor) {
|
||||
console.log('JSON Editor gevonden en gekoppeld');
|
||||
} else {
|
||||
console.log('JSON Editor nog niet beschikbaar, probeer handmatige initialisatie');
|
||||
|
||||
// Probeer handmatige initialisatie als fallback
|
||||
if (window.EveAI?.JsonEditors?.initialize) {
|
||||
try {
|
||||
const initialContent = JSON.parse(textareaElement.value);
|
||||
currentEditor = window.EveAI.JsonEditors.initialize('json_content-editor', initialContent, {
|
||||
mode: 'tree',
|
||||
readOnly: false,
|
||||
mainMenuBar: true,
|
||||
navigationBar: false,
|
||||
statusBar: true,
|
||||
onChange: (updatedContent, previousContent, { contentErrors, patchResult }) => {
|
||||
console.log('Editor content changed');
|
||||
// Automatisch de textarea updaten bij wijzigingen
|
||||
syncEditorToTextarea();
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Error bij handmatige initialisatie:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
|
||||
// Functie om editor inhoud naar textarea te synchroniseren
|
||||
function syncEditorToTextarea() {
|
||||
if (currentEditor && currentEditor.get) {
|
||||
const editor = window.EveAI?.JsonEditors?.get('json_content-editor');
|
||||
if (editor && editor.get) {
|
||||
try {
|
||||
const content = currentEditor.get();
|
||||
const content = editor.get();
|
||||
if (content.json !== undefined) {
|
||||
textareaElement.value = JSON.stringify(content.json, null, 2);
|
||||
} else if (content.text !== undefined) {
|
||||
textareaElement.value = content.text;
|
||||
}
|
||||
console.log('Editor content gesynchroniseerd naar textarea');
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error('Error bij synchronisatie:', e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sync knop
|
||||
document.getElementById('getEditorContentBtn').addEventListener('click', function() {
|
||||
syncEditorToTextarea();
|
||||
alert('Editor inhoud gesynchroniseerd naar textarea');
|
||||
});
|
||||
|
||||
// Validate JSON button
|
||||
document.getElementById('validateJsonBtn').addEventListener('click', function() {
|
||||
// Eerst synchroniseren
|
||||
syncEditorToTextarea();
|
||||
|
||||
try {
|
||||
const content = textareaElement.value;
|
||||
JSON.parse(content);
|
||||
|
||||
// Show success message
|
||||
if (typeof Swal !== 'undefined') {
|
||||
Swal.fire({
|
||||
title: 'Geldig JSON',
|
||||
text: 'De JSON syntax is correct!',
|
||||
icon: 'success',
|
||||
timer: 2000,
|
||||
showConfirmButton: false
|
||||
});
|
||||
} else {
|
||||
alert('De JSON syntax is correct!');
|
||||
}
|
||||
} catch (e) {
|
||||
// Show error message
|
||||
if (typeof Swal !== 'undefined') {
|
||||
Swal.fire({
|
||||
title: 'Ongeldig JSON',
|
||||
text: 'JSON syntax fout: ' + e.message,
|
||||
icon: 'error',
|
||||
confirmButtonText: 'OK'
|
||||
});
|
||||
} else {
|
||||
alert('JSON syntax fout: ' + e.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Form submission validation
|
||||
// Form submission validation en synchronisatie
|
||||
document.getElementById('editAssetForm').addEventListener('submit', function(e) {
|
||||
// Eerst de editor content synchroniseren
|
||||
syncEditorToTextarea();
|
||||
if (!syncEditorToTextarea()) {
|
||||
console.warn('Synchronisatie gefaald, maar probeer toch door te gaan');
|
||||
}
|
||||
|
||||
try {
|
||||
const content = textareaElement.value;
|
||||
JSON.parse(content);
|
||||
|
||||
// JSON is valid, allow submission
|
||||
return true;
|
||||
return true; // JSON is valid, allow submission
|
||||
} catch (error) {
|
||||
e.preventDefault();
|
||||
|
||||
if (typeof Swal !== 'undefined') {
|
||||
Swal.fire({
|
||||
title: 'Ongeldig JSON',
|
||||
text: 'Kan het formulier niet verzenden: JSON syntax fout - ' + error.message,
|
||||
icon: 'error',
|
||||
confirmButtonText: 'OK'
|
||||
});
|
||||
} else {
|
||||
alert('Kan het formulier niet verzenden: JSON syntax fout - ' + error.message);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -870,8 +870,11 @@ def edit_asset(asset_id):
|
||||
try:
|
||||
# Haal de bewerkte JSON data op uit het formulier
|
||||
json_data = request.form.get('json_content')
|
||||
current_app.logger.debug(f"Raw JSON data received for asset {asset_id}: {json_data[:200] if json_data else 'None'}...")
|
||||
current_app.logger.debug(f"JSON data length: {len(json_data) if json_data else 0}")
|
||||
|
||||
if not json_data:
|
||||
current_app.logger.error(f"No JSON data received for asset {asset_id}")
|
||||
flash('Geen JSON data ontvangen', 'error')
|
||||
return redirect(prefixed_url_for('interaction_bp.edit_asset', asset_id=asset_id))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user