Skip to content

Commit ec4c11b

Browse files
When new data is imported using csv/url, the manual editor still shows old data
1 parent 90b36b1 commit ec4c11b

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@ public function __construct( Visualizer_Plugin $plugin ) {
6969

7070
$this->_addAjaxAction( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY, 'saveFilter' );
7171

72+
$this->_addFilter( 'visualizer_get_sidebar', 'getSidebar', 10, 2 );
73+
74+
}
75+
76+
/**
77+
* Generates the HTML of the sidebar for the chart.
78+
*
79+
* @since ?
80+
*
81+
* @access public
82+
*/
83+
public function getSidebar( $sidebar, $chart_id ) {
84+
$chart = get_post( $chart_id );
85+
$data = $this->_getChartArray( $chart );
86+
$sidebar = '';
87+
$sidebar_class = $this->load_chart_class_name( $chart_id );
88+
if ( class_exists( $sidebar_class, true ) ) {
89+
$sidebar = new $sidebar_class( $data['settings'] );
90+
$sidebar->__series = $data['series'];
91+
$sidebar->__data = $data['data'];
92+
} else {
93+
$sidebar = apply_filters( 'visualizer_pro_chart_type_sidebar', '', $data );
94+
if ( $sidebar !== '' ) {
95+
$sidebar->__series = $data['series'];
96+
$sidebar->__data = $data['data'];
97+
}
98+
}
99+
return str_replace( "'", '"', $sidebar->__toString() );
72100
}
73101

74102
/**

classes/Visualizer/Render/Page/Update.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ protected function _toHTML() {
5252
echo 'win.visualizer.charts.canvas.settings = ', $this->settings, ';';
5353
}
5454
echo 'win.visualizer.update();';
55+
56+
echo $this->updateEditorAndSettings();
57+
5558
echo '}';
5659

5760
do_action( 'visualizer_add_update_hook', $this->series, $this->data );
@@ -70,4 +73,21 @@ protected function _toHTML() {
7073
echo '</html>';
7174
}
7275

76+
77+
/**
78+
* Update the hidden content in the LHS and the advanced settings
79+
*/
80+
private function updateEditorAndSettings() {
81+
$editor = '';
82+
if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) {
83+
ob_start();
84+
Visualizer_Render_Layout::show( 'simple-editor-screen', $this->id );
85+
$editor = ob_get_clean();
86+
}
87+
88+
$sidebar = apply_filters( 'visualizer_get_sidebar', '', $this->id );
89+
90+
return 'win.updateHTML(\'' . json_encode( $editor ) . '\', \'' . json_encode( $sidebar ) . '\');';
91+
}
92+
7393
}

js/frame.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
});
7070

7171
// collapse other open sections of this group
72-
$('.viz-group-title').click(function () {
72+
$(document).on('click', '.viz-group-title', function () {
7373
var parent = $(this).parent();
7474

7575
if (parent.hasClass('open')) {
@@ -89,7 +89,7 @@
8989
});
9090

9191
// collapse other open subsections of this section
92-
$('.viz-section-title').click(function () {
92+
$(document).on('click', '.viz-section-title', function () {
9393
var grandparent = $(this).parent().parent();
9494
grandparent.find('.viz-section-title.open ~ .viz-section-items').hide();
9595
grandparent.find('.viz-section-title.open').removeClass('open');
@@ -124,11 +124,11 @@
124124
$('#canvas').unlock();
125125
});
126126

127-
$('.viz-section-title').click(function () {
127+
$(document).on('click', '.viz-section-title', function () {
128128
$(this).toggleClass('open').parent().find('.viz-section-items').toggle();
129129
});
130130

131-
$('.more-info').click(function () {
131+
$(document).on('click', '.more-info', function () {
132132
$(this).parent().find('.viz-section-description:first').toggle();
133133
return false;
134134
});

js/preview.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
var timeout;
55

66
$(document).ready(function() {
7+
// when data is impported using csv/url, update the hidden data and the advanced settings sidebar.
8+
window.updateHTML = function( editor, sidebar ) {
9+
$('.viz-simple-editor').remove();
10+
$('#content').append(editor);
11+
$('#settings-form .viz-group').remove();
12+
$('#settings-form').append(sidebar);
13+
14+
$('#settings-form .control-text').change(updateChart).keyup(updateChart);
15+
$('#settings-form .control-select, #settings-form .control-checkbox, #settings-form .control-check').change(updateChart);
16+
$('#settings-form .color-picker-hex').wpColorPicker({
17+
change: updateChart,
18+
clear: updateChart
19+
});
20+
$('#settings-form textarea[name="manual"]').change(validateJSON).keyup(validateJSON);
21+
};
22+
723
$('#settings-button').click(function() {
824
$('#settings-form').submit();
925
});

0 commit comments

Comments
 (0)