fix: [dashboard:widgetAdd] Improved error handling for invalid JSON config

pull/9677/head
Sami Mokaddem 2024-04-08 11:36:51 +02:00
parent 5495dccb31
commit b54eec95c1
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 12 additions and 6 deletions

View File

@ -5385,6 +5385,18 @@ function submitDashboardAddWidget() {
var height = $('#DashboardHeight').val();
var el = null;
var k = $('#last-element-counter').data('element-counter');
if (config === '') {
config = '[]'
}
try {
config = JSON.parse(config);
} catch (error) {
showMessage('fail', error.message)
return
}
config = JSON.stringify(config);
$.ajax({
url: baseurl + '/dashboards/getEmptyWidget/' + widget + '/' + (k+1),
type: 'GET',
@ -5398,12 +5410,6 @@ function submitDashboardAddWidget() {
"autoposition": 1
}
);
if (config !== '') {
config = JSON.parse(config);
config = JSON.stringify(config);
} else {
config = '[]';
}
$('#widget_' + (k+1)).attr('config', config);
saveDashboardState();
$('#last-element-counter').data('element-counter', (k+1));