Skip to content

Commit

Permalink
Handle settings the same way as the normal widget
Browse files Browse the repository at this point in the history
  • Loading branch information
murrant committed May 22, 2024
1 parent 0e4803a commit 63fd753
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
27 changes: 10 additions & 17 deletions resources/views/overview/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
} else {
obj.data('settings','1');
}
widget_reload(obj.attr('id'),obj.data('type'));
widget_reload(obj.attr('id'), obj.data('type'), true);
});
Expand Down Expand Up @@ -582,19 +582,14 @@ function widget_settings(data) {
return false;
}
function widget_reload(id, data_type, forceDomInject) {
function widget_reload(id, data_type, forceDomInject = false) {
const $widget_body = $('#widget_body_' + id);
const settings = $widget_body.parent().data('settings') == 1 ? 1 : 0;
const $widget = $widget_body.children().first();
const reload = $widget.data('reload'); // should this function reload widget html?
if (settings === 1 || forceDomInject) {
$widget.trigger('destroy', $widget); // send destroy event
} else {
// skip html reload and sned refresh event instead
if (!forceDomInject && $widget.data('reload') === false) {
$widget.trigger('refresh', $widget); // send refresh event
if (reload === false) {
return; // skip html reload
}
return; // skip html reload
}
$.ajax({
Expand All @@ -603,13 +598,15 @@ function widget_reload(id, data_type, forceDomInject) {
data: {
id: id,
dimensions: {x: $widget_body.width(), y: $widget_body.height()},
settings: settings
settings: $widget_body.parent().data('settings') == 1 ? 1 : 0
},
dataType: 'json',
success: function (data) {
if (data.status === 'ok') {
$('#widget_title_' + id).html(data.title);
$widget.trigger('destroy', $widget); // send destroy event
$widget_body.children().unbind().html("").remove(); // clear old contents and unbind events
$('#widget_title_' + id).html(data.title);
$widget_body.html(data.html);
$widget_body.parent().data('settings', data.show_settings).data('refresh', data.settings.refresh);
} else {
Expand All @@ -623,11 +620,7 @@ function widget_reload(id, data_type, forceDomInject) {
}
function grab_data(id, data_type) {
const $parent = $('#widget_body_' + id).parent();
if($parent.data('settings') == 0) {
widget_reload(id, data_type);
}
widget_reload(id, data_type);
setTimeout(function () {
grab_data(id, data_type);
Expand Down
2 changes: 1 addition & 1 deletion resources/views/widgets/settings/base.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form role="form" class="dashboard-widget-settings" onsubmit="widget_settings(this); return false;">
<form role="form" class="dashboard-widget-settings" onsubmit="widget_settings(this); return false;" data-reload="false">
@csrf
@yield('form')

Expand Down

0 comments on commit 63fd753

Please sign in to comment.