Skip to content

Commit c38cb8e

Browse files
Data changes cancel previous design changes
#509
1 parent 278c698 commit c38cb8e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ private function _handleDataAndSettingsPage() {
761761
'loading' => esc_html__( 'Loading...', 'visualizer' ),
762762
'json_error' => esc_html__( 'An error occured in fetching data.', 'visualizer' ),
763763
'select_columns' => esc_html__( 'Please select a few columns to include in the chart.', 'visualizer' ),
764+
'save_settings' => esc_html__( 'The settings seem to have changed. If you want to update your data, please save the chart first to save your settings. If you continue, you may lose your changes.', 'visualizer' ),
764765
),
765766
'charts' => array(
766767
'canvas' => $data,

js/frame.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* global prompt */
22
/* global visualizer */
33
/* global alert */
4+
/* global confirm */
45
/* global ajaxurl */
56
/* global CodeMirror */
7+
/* global vizHaveSettingsChanged */
68

79
(function ($) {
810
$(window).on('load', function(){
@@ -22,6 +24,12 @@
2224
create: function( event, ui ) {
2325
$(this).addClass('done');
2426
$( "#sidebar" ).unlock();
27+
},
28+
beforeActivate: function( event, ui ) {
29+
// if settings have changed in tab #2 and tab #1 is being activated, warn the user.
30+
if(vizHaveSettingsChanged() && $(ui.newTab.context).attr('id').includes('viz-tab-basic')){
31+
return confirm(visualizer.l10n.save_settings);
32+
}
2533
}
2634
});
2735
}

js/preview.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/* global visualizer */
22
/* global console */
3+
/* global vizSettingsHaveChanged */
4+
/* global vizHaveSettingsChanged */
5+
36
(function($, v) {
47
var timeout;
58

@@ -19,12 +22,25 @@
1922
clear: updateChart
2023
});
2124
$('#settings-form textarea[name="manual"]').change(validateJSON).keyup(validateJSON);
25+
vizSettingsHaveChanged(false);
2226
};
2327

2428
$('#settings-button').click(function() {
2529
$('#settings-form').submit();
2630
});
2731

32+
// this portion captures if the settings have changed so that tabs can handle that information.
33+
var viz_settings_have_changed = false;
34+
35+
window.vizHaveSettingsChanged = function(){
36+
return viz_settings_have_changed;
37+
};
38+
39+
window.vizSettingsHaveChanged = function(value){
40+
viz_settings_have_changed = value;
41+
};
42+
// this portion captures if the settings have changed so that tabs can handle that information.
43+
2844
function updateChart() {
2945
clearTimeout(timeout);
3046
timeout = setTimeout(function() {
@@ -35,6 +51,7 @@
3551

3652
v.charts.canvas.settings = settings;
3753
$('body').trigger('visualizer:render:currentchart:update', {visualizer: v});
54+
vizSettingsHaveChanged(true);
3855
}, 1000);
3956
}
4057

0 commit comments

Comments
 (0)