Add alert for unsaved changes in dashboard edit. (#6159)

Also fixed bug for re-rendering the chart.
This commit is contained in:
AlexC
2021-11-30 08:36:00 -07:00
committed by GitHub
parent 70b876f5da
commit db0471726d
+23 -8
View File
@@ -170,7 +170,7 @@
<?php <?php
//show the content //show the content
echo "<form id='dashboard' method='POST'>\n"; echo "<form id='dashboard' method='POST' onsubmit='setFormSubmitting()'>\n";
echo "<div class='action_bar' id='action_bar'>\n"; echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-dashboard']."</b></div>\n"; echo " <div class='heading'><b>".$text['title-dashboard']."</b></div>\n";
echo " <div class='actions'>\n"; echo " <div class='actions'>\n";
@@ -313,16 +313,15 @@
preventOnFilter: true, preventOnFilter: true,
ghostClass: 'ghost', ghostClass: 'ghost',
onChange: function (evt) { onChange: function (evt) {
//re-render chart when dragged //check if chart exists
if (evt.item.id != 'ring_group_forward' && evt.item.id != 'call_forward') { let chart_status = Chart.getChart(evt.item.id + "_chart");
let chart = eval(evt.item.id + "_chart"); if(chart_status !== undefined && chart_status !== null) {
let context = eval(evt.item.id + "_chart_context"); let context = eval(evt.item.id + "_chart_context");
let chart = Chart.getChart(context);
let config = eval(evt.item.id + "_chart_config"); let config = eval(evt.item.id + "_chart_config");
let chart_status = Chart.getChart(context); //re render the chart
if (chart_status != undefined) { chart.destroy();
chart_status.destroy();
}
chart.options.animation = { duration: 0 }; chart.options.animation = { duration: 0 };
chart = new Chart(context, config); chart = new Chart(context, config);
} }
@@ -336,6 +335,22 @@
document.getElementById('widget_order').value = widget_ids_list; 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;
});
};
</script> </script>
<?php <?php
} //end edit } //end edit