Skip to content

Commit d7a72ef

Browse files
Merge sidebars from step 2 and step 3 into 1
1. Merge sidebars from step 2 and step 3 into 1. 2. Stop form from being submitted when the Enter button is pressed.
1 parent e543933 commit d7a72ef

File tree

4 files changed

+113
-20
lines changed

4 files changed

+113
-20
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,9 @@ public function renderChartPages() {
252252
// dispatch pages
253253
$this->_chart = $chart;
254254
switch ( filter_input( INPUT_GET, 'tab' ) ) {
255-
case 'data':
256-
$this->_handleDataPage();
257-
break;
258255
case 'settings':
259-
$this->_handleSettingsPage();
256+
// changed by Ash/Upwork
257+
$this->_handleDataAndSettingsPage();
260258
break;
261259
case 'type':
262260
default:
@@ -294,7 +292,8 @@ private function _handleTypesPage() {
294292
}
295293

296294
// redirect to next tab
297-
wp_redirect( add_query_arg( 'tab', 'data' ) );
295+
// changed by Ash/Upwork
296+
wp_redirect( add_query_arg( 'tab', 'settings' ) );
298297
return;
299298
}
300299
}
@@ -411,6 +410,76 @@ private function _handleSettingsPage() {
411410
wp_iframe( array( $render, 'render') );
412411
}
413412

413+
414+
// changed by Ash/Upwork
415+
private function _handleDataAndSettingsPage(){
416+
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ) ) ) {
417+
if ( $this->_chart->post_status == 'auto-draft' ) {
418+
$this->_chart->post_status = 'publish';
419+
wp_update_post( $this->_chart->to_array() );
420+
}
421+
422+
update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST );
423+
424+
$render = new Visualizer_Render_Page_Send();
425+
$render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID );
426+
427+
wp_iframe( array( $render, 'render') );
428+
return;
429+
}
430+
431+
$data = $this->_getChartArray();
432+
433+
$sidebar = '';
434+
$sidebar_class = 'Visualizer_Render_Sidebar_Type_' . ucfirst( $data['type'] );
435+
if ( class_exists( $sidebar_class, true ) ) {
436+
$sidebar = new $sidebar_class( $data['settings'] );
437+
$sidebar->__series = $data['series'];
438+
$sidebar->__data = $data['data'];
439+
}
440+
441+
unset( $data['settings']['width'], $data['settings']['height'] );
442+
443+
wp_enqueue_style( 'visualizer-frame' );
444+
wp_enqueue_style( 'wp-color-picker' );
445+
wp_enqueue_style( 'visualizer-frame' );
446+
447+
wp_enqueue_script( 'visualizer-preview' );
448+
wp_enqueue_script( 'visualizer-render' );
449+
wp_localize_script( 'visualizer-render', 'visualizer', array(
450+
'l10n' => array(
451+
'remotecsv_prompt' => esc_html__( 'Please, enter the URL of CSV file:', Visualizer_Plugin::NAME ),
452+
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', Visualizer_Plugin::NAME ),
453+
),
454+
'charts' => array(
455+
'canvas' => $data,
456+
),
457+
) );
458+
459+
$render = new Visualizer_Render_Page_Data();
460+
$render->chart = $this->_chart;
461+
$render->type = $data['type'];
462+
463+
$render->sidebar = $sidebar;
464+
if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) {
465+
$render->button = filter_input( INPUT_GET, 'action' ) == Visualizer_Plugin::ACTION_EDIT_CHART
466+
? esc_html__( 'Save Chart', Visualizer_Plugin::NAME )
467+
: esc_html__( 'Create Chart', Visualizer_Plugin::NAME );
468+
} else {
469+
$render->button = esc_attr__( 'Insert Chart', Visualizer_Plugin::NAME );
470+
}
471+
472+
if( defined( 'Visualizer_Pro' ) ){
473+
global $Visualizer_Pro;
474+
$Visualizer_Pro->_enqueueScriptsAndStyles($data);
475+
}
476+
477+
$this->_addAction( 'admin_head', 'renderFlattrScript' );
478+
479+
wp_iframe( array( $render, 'render') );
480+
}
481+
// changed by Ash/Upwork
482+
414483
/**
415484
* Renders flattr script in the iframe <head>
416485
*

classes/Visualizer/Render/Page/Data.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,7 @@ protected function _renderSidebarContent() {
7171
echo '<iframe id="thehole" name="thehole"></iframe>';
7272

7373
echo '<p class="group-description">';
74-
esc_html_e( "Select and upload your data CSV file here. The first row of the CSV file should contain the column headings. The second one should contain series type (string, number, boolean, date, datetime, timeofday).", Visualizer_Plugin::NAME );
75-
echo '</p>';
76-
77-
echo '<p class="group-description">';
78-
esc_html_e( 'If you are unsure about how to format your data CSV then please take a look at this sample:', Visualizer_Plugin::NAME );
79-
echo ' <a href="', VISUALIZER_ABSURL, 'samples/', $this->type, '.csv" target="_blank">', $this->type, '.csv</a> ';
80-
printf( esc_html__( 'or read how you can add Google spreadsheet in following %sarticle%s.', Visualizer_Plugin::NAME ), '<a href="https://github.com/madpixelslabs/visualizer/wiki/How-can-I-populate-data-from-Google-Spreadsheet%3F" target="_blank">', '</a>' );
74+
echo '<a href="">something here</a>';
8175
echo '</p>';
8276

8377
echo '<div>';
@@ -117,6 +111,12 @@ protected function _renderSidebarContent() {
117111
echo '</div>';
118112
echo '</div>';
119113
echo '</li>';
114+
115+
// changed by Ash/Upwork
116+
echo '<form id="settings-form" action="', add_query_arg( 'nonce', wp_create_nonce() ), '" method="post">';
117+
echo $this->sidebar;
118+
echo '</form>';
119+
// changed by Ash/Upwork
120120
}
121121

122122
/**
@@ -127,12 +127,23 @@ protected function _renderSidebarContent() {
127127
* @access protected
128128
*/
129129
protected function _renderToolbar() {
130-
echo '<a class="button button-large" href="', add_query_arg( 'tab', false ), '">';
130+
// changed by Ash/Upwork
131+
echo '<div class="toolbar-div">';
132+
echo '<a class="button button-large" href="', add_query_arg( 'tab', 'types' ), '">';
131133
esc_html_e( 'Back', Visualizer_Plugin::NAME );
132134
echo '</a>';
133-
echo '<a class="button button-large button-primary push-right" href="', add_query_arg( 'tab', 'settings' ), '">';
134-
esc_html_e( 'Next', Visualizer_Plugin::NAME );
135-
echo '</a>';
135+
echo '</div>';
136+
137+
echo '<div class="toolbar-div rate-the-plugin">';
138+
echo '<div><b>', esc_html__( 'Like the plugin? Show us your love!', Visualizer_Plugin::NAME ), '</b>';
139+
echo '<a id="rate-link" href="http://wordpress.org/support/view/plugin-reviews/visualizer" target="_blank">';
140+
esc_html_e( 'Rate it on WordPress.org', Visualizer_Plugin::NAME );
141+
echo '</a>';
142+
echo '</div>';
143+
echo '<div id="rate-stars">&nbsp;</div>';
144+
echo '</div>';
145+
146+
echo '<input type="submit" id="settings-button" class="button button-primary button-large push-right" value="', $this->button, '">';
136147
}
137148

138149
}

css/frame.css

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,13 @@ div.group-content .group-description {
260260
border-top: 1px dashed #ddd;
261261
}
262262

263+
.rate-the-plugin{
264+
text-align: center;
265+
width: 40% !important;
266+
}
267+
263268
#rate-stars {
264-
margin: 10px 0px 10px 55px;
269+
margin: 10px 0px 10px 40%;
265270
width: 100px;
266271
height: 20px;
267272
background-image: url('../images/star.png');
@@ -271,11 +276,9 @@ div.group-content .group-description {
271276

272277
#rate-link {
273278
text-decoration: none;
274-
display: block;
275-
margin-top: 3px;
276-
margin-left: 35px;
277279
font-family: "Montserrat",sans-serif;
278280
font-weight: 300;
281+
margin: 0px 0px 0px 20px;
279282
}
280283

281284
#flattr {
@@ -305,6 +308,12 @@ div.group-content .group-description {
305308
float: right;
306309
}
307310

311+
.toolbar-div{
312+
display: inline-block;
313+
vertical-align: top;
314+
width: 30%;
315+
}
316+
308317
/******************************************************************************/
309318
/******************************** TYPE PICKER ******************************/
310319
/******************************************************************************/

js/preview.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
var timeout;
33

44
$(document).ready(function() {
5+
$('#settings-button').click(function() {
6+
$('#settings-form').submit();
7+
});
8+
59
function updateChart() {
610
clearTimeout(timeout);
711
timeout = setTimeout(function() {

0 commit comments

Comments
 (0)