From db0471726d5555ded12164d2e1cd654cf6570cc7 Mon Sep 17 00:00:00 2001 From: AlexC <40072887+alexdcrane@users.noreply.github.com> Date: Tue, 30 Nov 2021 08:36:00 -0700 Subject: [PATCH] Add alert for unsaved changes in dashboard edit. (#6159) Also fixed bug for re-rendering the chart. --- core/dashboard/index.php | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/core/dashboard/index.php b/core/dashboard/index.php index 4c0c2f0eec..af98b4053f 100644 --- a/core/dashboard/index.php +++ b/core/dashboard/index.php @@ -170,7 +170,7 @@ \n"; + echo "
\n"; echo "
\n"; echo "
".$text['title-dashboard']."
\n"; echo "
\n"; @@ -313,16 +313,15 @@ preventOnFilter: true, ghostClass: 'ghost', onChange: function (evt) { - //re-render chart when dragged - if (evt.item.id != 'ring_group_forward' && evt.item.id != 'call_forward') { - let chart = eval(evt.item.id + "_chart"); + //check if chart exists + let chart_status = Chart.getChart(evt.item.id + "_chart"); + if(chart_status !== undefined && chart_status !== null) { let context = eval(evt.item.id + "_chart_context"); + let chart = Chart.getChart(context); let config = eval(evt.item.id + "_chart_config"); - - let chart_status = Chart.getChart(context); - if (chart_status != undefined) { - chart_status.destroy(); - } + + //re render the chart + chart.destroy(); chart.options.animation = { duration: 0 }; chart = new Chart(context, config); } @@ -336,6 +335,22 @@ document.getElementById('widget_order').value = widget_ids_list; }, }); + + var formSubmitting = false; + var setFormSubmitting = function() { formSubmitting = true; }; + + window.onload = function() { + window.addEventListener("beforeunload", function (e) { + var confirmationMessage = 'You have unsaved changes which will not be saved.'; + + if (formSubmitting) { + return undefined; + } + + (e || window.event).returnValue = confirmationMessage; + return confirmationMessage; + }); + };