- bug TRA-68 solved - bug in javascript code did not pass changed json content.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
alert('Kan het formulier niet verzenden: JSON syntax fout - ' + error.message);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user