| @@ -1,11 +1,9 @@ | ||
| 1 | 1 | /* global prompt */ |
| 2 | 2 | /* global visualizer */ |
| 3 | 3 | /* global alert */ |
| 4 | -/* global confirm */ | |
| 5 | 4 | /* global ajaxurl */ |
| 6 | 5 | /* global CodeMirror */ |
| 7 | -/* global vizHaveSettingsChanged */ | |
| 8 | 6 | |
| 9 | 7 | (function ($) { |
| 10 | 8 | $(window).on('load', function(){ |
| 11 | 9 | // scroll to the selected chart type. |
| @@ -14,30 +12,8 @@ | ||
| 14 | 12 | } |
| 15 | 13 | }); |
| 16 | 14 | |
| 17 | 15 | $(document).ready(function () { |
| 18 | - onReady(); | |
| 19 | - }); | |
| 20 | - | |
| 21 | - function initTabs(){ | |
| 22 | - $( "#sidebar" ).lock(); | |
| 23 | - $( "#viz-tabs" ).tabs({ | |
| 24 | - create: function( event, ui ) { | |
| 25 | - $(this).addClass('done'); | |
| 26 | - $( "#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.find( 'a' ).attr( 'id' ).includes('viz-tab-basic')){ | |
| 31 | - return confirm(visualizer.l10n.save_settings); | |
| 32 | - } | |
| 33 | - } | |
| 34 | - }); | |
| 35 | - } | |
| 36 | - | |
| 37 | - function onReady() { | |
| 38 | - initTabs(); | |
| 39 | - | |
| 40 | 16 | // open the correct source tab/sub-tab. |
| 41 | 17 | var source = $('#visualizer-chart-id').attr('data-chart-source'); |
| 42 | 18 | $('li.viz-group.' + source).addClass('open'); |
| 43 | 19 | $('li.viz-group.' + source + ' span.viz-section-title.' + source).addClass('open'); |
| @@ -73,10 +49,22 @@ | ||
| 73 | 49 | $('.type-label-selected').removeClass('type-label-selected'); |
| 74 | 50 | $(this).parent().addClass('type-label-selected'); |
| 75 | 51 | }); |
| 76 | 52 | |
| 77 | - // collapse other open sections of this group | |
| 78 | - $(document).on('click', '.viz-group-title', function () { | |
| 53 | + $('#vz-chart-settings h2').click(function () { | |
| 54 | + $("#vz-chart-source").hide(); | |
| 55 | + $("#vz-chart-permissions").removeClass('open').addClass('bottom-fixed'); | |
| 56 | + $(this).parent().removeClass('bottom-fixed').addClass('open'); | |
| 57 | + $("#vz-chart-permissions .viz-group-header").hide(); | |
| 58 | + return false; | |
| 59 | + }); | |
| 60 | + $('#vz-chart-settings .customize-section-back').click(function () { | |
| 61 | + $("#vz-chart-source").show(); | |
| 62 | + $(this).parent().parent().removeClass('open').addClass('bottom-fixed'); | |
| 63 | + | |
| 64 | + return false; | |
| 65 | + }); | |
| 66 | + $('.viz-group-title').click(function () { | |
| 79 | 67 | var parent = $(this).parent(); |
| 80 | 68 | |
| 81 | 69 | if (parent.hasClass('open')) { |
| 82 | 70 | parent.removeClass('open'); |
| @@ -83,32 +71,14 @@ | ||
| 83 | 71 | } else { |
| 84 | 72 | parent.parent().find('.viz-group.open').removeClass('open'); |
| 85 | 73 | parent.addClass('open'); |
| 86 | 74 | } |
| 87 | - | |
| 88 | - /* | |
| 89 | - * if the user wants to perform an action and click that tab to change the source | |
| 90 | - * and the chart is no longer showing because that particular LHS screen is showing | |
| 91 | - * e.g. create parameters, import json, db query box etc. | |
| 92 | - * we need to make sure we cancel the current process WITHOUT saving | |
| 93 | - * and then show the chart as it was | |
| 94 | - * let's close the LHS window and show the chart that is hidden | |
| 95 | - */ | |
| 96 | - $('body').trigger('visualizer:change:action'); | |
| 97 | 75 | }); |
| 98 | - | |
| 99 | - // collapse other open subsections of this section | |
| 100 | - $(document).on('click', '.viz-section-title', function () { | |
| 101 | - var grandparent = $(this).parent().parent(); | |
| 102 | - grandparent.find('.viz-section-title.open ~ .viz-section-items').hide(); | |
| 103 | - grandparent.find('.viz-section-title.open').removeClass('open'); | |
| 104 | - }); | |
| 105 | - | |
| 106 | 76 | $('#view-remote-file').click(function () { |
| 107 | - var url = $(this).parent().find('#vz-schedule-url').val(); | |
| 77 | + var url = $(this).parent().find('#remote-data').val(); | |
| 108 | 78 | |
| 109 | 79 | if (url !== '') { |
| 110 | - if (url.indexOf('localhost') !== -1 || /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url)) { | |
| 80 | + if (/^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url)) { | |
| 111 | 81 | if (url.substr(url.length - 8) === '/pubhtml') { |
| 112 | 82 | url = url.substring(0, url.length - 8) + '/export?format=csv'; |
| 113 | 83 | } |
| 114 | 84 | |
| @@ -127,17 +97,17 @@ | ||
| 127 | 97 | $(this).parent().submit(); |
| 128 | 98 | } |
| 129 | 99 | }); |
| 130 | 100 | |
| 131 | - $( window ).on( 'load', function() { | |
| 101 | + $('#thehole').load(function () { | |
| 132 | 102 | $('#canvas').unlock(); |
| 133 | - } ); | |
| 103 | + }); | |
| 134 | 104 | |
| 135 | - $(document).on('click', '.viz-section-title', function () { | |
| 105 | + $('.viz-section-title').click(function () { | |
| 136 | 106 | $(this).toggleClass('open').parent().find('.viz-section-items').toggle(); |
| 137 | 107 | }); |
| 138 | 108 | |
| 139 | - $(document).on('click', '.more-info', function () { | |
| 109 | + $('.more-info').click(function () { | |
| 140 | 110 | $(this).parent().find('.viz-section-description:first').toggle(); |
| 141 | 111 | return false; |
| 142 | 112 | }); |
| 143 | 113 | |
| @@ -144,41 +114,40 @@ | ||
| 144 | 114 | $('#cancel-button').click(function () { |
| 145 | 115 | $('#cancel-form').submit(); |
| 146 | 116 | }); |
| 147 | 117 | |
| 148 | - init_type_vs_library(); | |
| 118 | + }); | |
| 149 | 119 | |
| 150 | - $('.viz-abort').on('click', function(e){ | |
| 151 | - e.preventDefault(); | |
| 152 | - window.parent.postMessage('visualizer:mediaframe:close', '*'); | |
| 153 | - }); | |
| 120 | + function init_permissions(){ | |
| 121 | + $('#vz-chart-permissions h2').click(function () { | |
| 122 | + $("#vz-chart-source").hide(); | |
| 123 | + $("#vz-chart-permissions .viz-group-header").show(); | |
| 124 | + $("#vz-chart-settings").removeClass('open').addClass('bottom-fixed'); | |
| 154 | 125 | |
| 155 | - } | |
| 126 | + $('#settings-button').click(function(e) { | |
| 127 | + e.preventDefault(); | |
| 128 | + $('#permissions-form').submit(); | |
| 129 | + $('#settings-form').submit(); | |
| 130 | + }); | |
| 156 | 131 | |
| 157 | - function init_type_vs_library() { | |
| 158 | - var $data = $('select.viz-select-library').attr('data-type-vs-library'); | |
| 159 | - if(typeof $data === 'undefined' || $data.length === 0){ | |
| 160 | - return; | |
| 161 | - } | |
| 162 | - var $typeVsLibrary = JSON.parse( $('select.viz-select-library').attr('data-type-vs-library') ); | |
| 163 | - // disable all unsupported libraries for the chart type. | |
| 164 | - $('input.type-radio').on('click', function(){ | |
| 165 | - enable_libraries_for($(this).val(), $typeVsLibrary); | |
| 132 | + $(this).parent().removeClass('bottom-fixed').addClass('open'); | |
| 133 | + | |
| 134 | + return false; | |
| 166 | 135 | }); |
| 136 | + $('#vz-chart-permissions .customize-section-back').click(function () { | |
| 137 | + $("#vz-chart-source").show(); | |
| 167 | 138 | |
| 168 | - enable_libraries_for($('input.type-radio:checked').val(), $typeVsLibrary); | |
| 169 | - } | |
| 139 | + $("#vz-chart-permissions .viz-group-header").hide(); | |
| 140 | + $('#settings-button').click(function(e) { | |
| 141 | + e.preventDefault(); | |
| 142 | + $('#settings-form').submit(); | |
| 143 | + }); | |
| 170 | 144 | |
| 171 | - function enable_libraries_for($type, $typeVsLibrary) { | |
| 172 | - $('select.viz-select-library option').addClass('disabled').attr('disabled', 'disabled'); | |
| 173 | - var $libs = $typeVsLibrary[$type]; | |
| 174 | - $.each($libs, function( i, $lib ) { | |
| 175 | - $('select.viz-select-library option[value="' + $lib + '"]').removeClass('disabled').removeAttr('disabled'); | |
| 145 | + $(this).parent().parent().removeClass('open').addClass('bottom-fixed'); | |
| 146 | + | |
| 147 | + return false; | |
| 176 | 148 | }); |
| 177 | - $('select.viz-select-library').val( $('select.viz-select-library option:not(.disabled)').val() ); | |
| 178 | - } | |
| 179 | 149 | |
| 180 | - function init_permissions(){ | |
| 181 | 150 | $('.visualizer-permission').chosen({ |
| 182 | 151 | width : '50%', |
| 183 | 152 | search_contains : true |
| 184 | 153 | }); |
| @@ -256,20 +225,8 @@ | ||
| 256 | 225 | // from the editor. Let's force this. |
| 257 | 226 | $('body').on('visualizer:db:query:update', function(event, data){ |
| 258 | 227 | cm.save(); |
| 259 | 228 | }); |
| 260 | - | |
| 261 | - // clear the editor. | |
| 262 | - $('body').on('visualizer:db:query:setvalue', function(event, data){ | |
| 263 | - cm.setValue(data.value); | |
| 264 | - cm.clearHistory(); | |
| 265 | - cm.refresh(); | |
| 266 | - }); | |
| 267 | - | |
| 268 | - // set an option at runtime? | |
| 269 | - $('body').on('visualizer:db:query:changeoption', function(event, data){ | |
| 270 | - cm.setOption(data.name, data.value); | |
| 271 | - }); | |
| 272 | 229 | } |
| 273 | 230 | |
| 274 | 231 | function init_filter_import() { |
| 275 | 232 | $( '#db-filter-save-button' ).on( 'click', function(){ |
| @@ -316,18 +273,8 @@ | ||
| 316 | 273 | }); |
| 317 | 274 | }); |
| 318 | 275 | |
| 319 | 276 | $( '#db-chart-button' ).on( 'click', function(){ |
| 320 | - | |
| 321 | - $('body').off('visualizer:change:action').on('visualizer:change:action', function(e){ | |
| 322 | - var filter_button = $( '#db-chart-button' ); | |
| 323 | - $( '#visualizer-db-query' ).css("z-index", "-1").hide(); | |
| 324 | - filter_button.val( filter_button.attr( 'data-t-chart' ) ); | |
| 325 | - filter_button.html( filter_button.attr( 'data-t-chart' ) ); | |
| 326 | - filter_button.attr( 'data-current', 'chart' ); | |
| 327 | - $( '#canvas' ).css("z-index", "1").show(); | |
| 328 | - }); | |
| 329 | - | |
| 330 | 277 | $('#content').css('width', 'calc(100% - 300px)'); |
| 331 | 278 | if( $(this).attr( 'data-current' ) === 'chart'){ |
| 332 | 279 | $(this).val( $(this).attr( 'data-t-filter' ) ); |
| 333 | 280 | $(this).html( $(this).attr( 'data-t-filter' ) ); |
| @@ -348,23 +295,14 @@ | ||
| 348 | 295 | } |
| 349 | 296 | } ); |
| 350 | 297 | |
| 351 | 298 | $( '#db-chart-save-button' ).on( 'click', function(){ |
| 352 | - // submit only if a query has been provided. | |
| 353 | - if($('#db-query-form .visualizer-db-query').val().length > 0){ | |
| 354 | - $('#viz-db-wizard-params').val($('#db-query-form').serialize()); | |
| 355 | - $('#vz-db-wizard').submit(); | |
| 356 | - }else{ | |
| 357 | - $('#canvas').unlock(); | |
| 358 | - } | |
| 299 | + $('#viz-db-wizard-params').val($('#db-query-form').serialize()); | |
| 300 | + $('#vz-db-wizard').submit(); | |
| 359 | 301 | }); |
| 360 | 302 | } |
| 361 | 303 | |
| 362 | 304 | function init_json_import(){ |
| 363 | - if(typeof visualizer === 'undefined'){ | |
| 364 | - return; | |
| 365 | - } | |
| 366 | - | |
| 367 | 305 | var regex = new RegExp(visualizer.json_tag_separator, 'g'); |
| 368 | 306 | |
| 369 | 307 | $( '#visualizer-json-screen' ).css("z-index", "-1").hide(); |
| 370 | 308 | $('.visualizer-json-form').accordion({ |
| @@ -370,73 +308,31 @@ | ||
| 370 | 308 | $('.visualizer-json-form').accordion({ |
| 371 | 309 | heightStyle: 'content', |
| 372 | 310 | active: 0 |
| 373 | 311 | }); |
| 374 | - $('.visualizer-json-subform').accordion({ | |
| 375 | - heightStyle: 'content', | |
| 376 | - active: false, | |
| 377 | - collapsible: true | |
| 378 | - }); | |
| 379 | - | |
| 380 | - // open the accordions by default if they are indicated with the 'open' class. | |
| 381 | - $('.visualizer-json-subform .viz-substep.open').each(function(i, e){ | |
| 382 | - $('.visualizer-json-subform').accordion( "option", "active", i ); | |
| 383 | - }); | |
| 384 | 312 | |
| 385 | 313 | // toggle between chart and create/modify parameters |
| 386 | - $( '#json-chart-button, #woo-chart-button' ).on( 'click', function(){ | |
| 387 | - | |
| 388 | - $('body').off('visualizer:change:action').on('visualizer:change:action', function(e){ | |
| 389 | - var filter_button = $( '#json-chart-button, #woo-chart-button' ); | |
| 390 | - $( '#visualizer-json-screen' ).css("z-index", "-1").hide(); | |
| 391 | - filter_button.val( filter_button.attr( 'data-t-chart' ) ); | |
| 392 | - filter_button.html( filter_button.attr( 'data-t-chart' ) ); | |
| 393 | - filter_button.attr( 'data-current', 'chart' ); | |
| 394 | - $( '#canvas' ).css("z-index", "1").show(); | |
| 395 | - $( '#vz-import-woo-report' ).find( 'select, input' ).removeAttr( 'disabled' ); | |
| 396 | - }); | |
| 397 | - | |
| 398 | - if ( 'json-chart-button' === $( this ).attr( 'id' ) ) { | |
| 399 | - $( '#vz-import-woo-report' ).find( 'select, input' ).attr( 'disabled', true ); | |
| 400 | - } else { | |
| 401 | - $( '#vz-import-woo-report' ).find( 'select, input' ).removeAttr( 'disabled' ); | |
| 402 | - } | |
| 403 | - $('#content').css('width', 'calc(100% - 100px)'); | |
| 314 | + $( '#json-chart-button' ).on( 'click', function(){ | |
| 315 | + $('#content').css('width', 'calc(100% - 300px)'); | |
| 404 | 316 | if( $(this).attr( 'data-current' ) === 'chart'){ |
| 405 | - // toggle from chart to LHS form | |
| 406 | 317 | $(this).val( $(this).attr( 'data-t-filter' ) ); |
| 407 | 318 | $(this).html( $(this).attr( 'data-t-filter' ) ); |
| 408 | 319 | $(this).attr( 'data-current', 'filter' ); |
| 409 | 320 | $( '.visualizer-editor-lhs' ).hide(); |
| 410 | 321 | $( '#visualizer-json-screen' ).css("z-index", "9999").show(); |
| 411 | - if ( 'woo-chart-button' === $( this ).attr( 'id' ) && '' !== $( '#vz-woo-source:visible' ).val() ) { | |
| 412 | - $( '#vz-import-json-url' ).val( visualizer.rest_base + $( '#vz-woo-source' ).val() ).attr( 'readonly', true ); | |
| 413 | - } else { | |
| 414 | - if ( 'undefined' !== $( '#vz-import-json-url' ).attr( 'readonly' ) ) { | |
| 415 | - $( '#vz-import-json-url' ).val( '' ).removeAttr( 'readonly' ).removeAttr( 'value' ); | |
| 416 | - $('#json-endpoint-form')[0].reset(); | |
| 417 | - $('.visualizer-json-form h3.viz-step:not(.step1)').addClass('ui-state-disabled'); | |
| 418 | - } | |
| 419 | - } | |
| 420 | 322 | $( '#canvas' ).hide(); |
| 421 | 323 | }else{ |
| 422 | - // toggle from LHS form to chart | |
| 423 | - $( '#json-conclude-form' ).trigger('submit'); | |
| 324 | + var filter_button = $(this); | |
| 325 | + $( '#visualizer-json-screen' ).css("z-index", "-1").hide(); | |
| 326 | + $('#canvas').lock(); | |
| 327 | + filter_button.val( filter_button.attr( 'data-t-chart' ) ); | |
| 328 | + filter_button.html( filter_button.attr( 'data-t-chart' ) ); | |
| 329 | + filter_button.attr( 'data-current', 'chart' ); | |
| 330 | + $( '#canvas' ).css("z-index", "1").show(); | |
| 331 | + $('#canvas').unlock(); | |
| 424 | 332 | } |
| 425 | 333 | } ); |
| 426 | 334 | |
| 427 | - $('body').on('visualizer:json:form:submit', function() { | |
| 428 | - var filter_button = $( '#json-chart-button, #woo-chart-button' ); | |
| 429 | - $( '#visualizer-json-screen' ).css("z-index", "-1").hide(); | |
| 430 | - $('#canvas').lock(); | |
| 431 | - filter_button.val( filter_button.attr( 'data-t-chart' ) ); | |
| 432 | - filter_button.html( filter_button.attr( 'data-t-chart' ) ); | |
| 433 | - filter_button.attr( 'data-current', 'chart' ); | |
| 434 | - end_ajax( $( '#visualizer-json-screen' ) ); | |
| 435 | - $( '#canvas' ).removeClass('visualizer-chart-loaded').css("z-index", "1").show(); | |
| 436 | - }); | |
| 437 | - | |
| 438 | - | |
| 439 | 335 | // fetch the roots for the provided endpoint |
| 440 | 336 | $( '#visualizer-json-fetch' ).on( 'click', function(e){ |
| 441 | 337 | e.preventDefault(); |
| 442 | 338 | $('.visualizer-json-form').accordion( 'option', 'active', 0 ); |
| @@ -452,8 +348,9 @@ | ||
| 452 | 348 | 'params' : $('#json-endpoint-form').serialize() |
| 453 | 349 | }, |
| 454 | 350 | success : function(data){ |
| 455 | 351 | if(data.success){ |
| 352 | + $('#json-root-form [name="url"]').val(data.data.url); | |
| 456 | 353 | $('#vz-import-json-root').empty(); |
| 457 | 354 | $.each(data.data.roots, function(i, name){ |
| 458 | 355 | $('#vz-import-json-root').append('<option value="' + name + '">' + name.replace(regex, visualizer.json_tag_separator_view) + '</option>'); |
| 459 | 356 | }); |
| @@ -459,9 +356,9 @@ | ||
| 459 | 356 | }); |
| 460 | 357 | $('#json-root-form').fadeIn('medium'); |
| 461 | 358 | json_accordion_activate(1, true); |
| 462 | 359 | }else{ |
| 463 | - alert(data.data.msg); | |
| 360 | + alert(visualizer.l10n.json_error); | |
| 464 | 361 | } |
| 465 | 362 | }, |
| 466 | 363 | complete: function(){ |
| 467 | 364 | end_ajax($('#visualizer-json-screen')); |
| @@ -480,9 +377,9 @@ | ||
| 480 | 377 | method : 'post', |
| 481 | 378 | data : { |
| 482 | 379 | 'action' : visualizer.ajax['actions']['json_get_data'], |
| 483 | 380 | 'security' : visualizer.ajax['nonces']['json_get_data'], |
| 484 | - 'params' : $('#json-root-form, #json-endpoint-form').serialize() | |
| 381 | + 'params' : $('#json-root-form').serialize() | |
| 485 | 382 | }, |
| 486 | 383 | success : function(data){ |
| 487 | 384 | if(data.success){ |
| 488 | 385 | $('#vz-import-json-paging option:not(.static)').remove(); |
| @@ -494,8 +391,10 @@ | ||
| 494 | 391 | $('#vz-import-json-paging').append('<option value="' + name + '">' + display + '</option>'); |
| 495 | 392 | }); |
| 496 | 393 | $('.json-pagination').show(); |
| 497 | 394 | } |
| 395 | + $('#json-conclude-form [name="url"]').val(data.data.url); | |
| 396 | + $('#json-conclude-form [name="root"]').val(data.data.root); | |
| 498 | 397 | $('#json-conclude-form .json-table').html(data.data.table); |
| 499 | 398 | |
| 500 | 399 | var $table = create_editor_table( '#json-conclude-form' ); |
| 501 | 400 | |
| @@ -502,9 +401,9 @@ | ||
| 502 | 401 | json_accordion_activate(3, true); |
| 503 | 402 | json_accordion_activate(2, false); |
| 504 | 403 | $table.columns.adjust().draw(); |
| 505 | 404 | }else{ |
| 506 | - alert(data.data.msg); | |
| 405 | + alert(visualizer.l10n.json_error); | |
| 507 | 406 | } |
| 508 | 407 | }, |
| 509 | 408 | complete: function(){ |
| 510 | 409 | end_ajax($('#visualizer-json-screen')); |
| @@ -513,33 +412,20 @@ | ||
| 513 | 412 | }); |
| 514 | 413 | |
| 515 | 414 | // when the data is set and the chart is updated, toggle the screen so that the chart is shown |
| 516 | 415 | $('#json-conclude-form').on( 'submit', function(e){ |
| 517 | - // at least one column has to be selected as non-excluded. | |
| 518 | - var count_selected = 0; | |
| 519 | - $('select.viz-select-data-type').each(function(i, element){ | |
| 520 | - if($(element).prop('selectedIndex') > 0){ | |
| 521 | - count_selected++; | |
| 522 | - } | |
| 523 | - }); | |
| 524 | - if(count_selected === 0){ | |
| 525 | - alert(visualizer.l10n.select_columns); | |
| 526 | - return false; | |
| 527 | - } | |
| 528 | - | |
| 529 | - // populate the form elements that are in the other tabs. | |
| 530 | - $('#json-conclude-form-helper .json-form-element, #json-endpoint-form .json-form-element, #json-root-form .json-form-element, #vz-import-json .json-form-element, #vz-import-woo-report .json-form-element:not(:disabled)').each(function(x, y){ | |
| 416 | + // populate the form elements that are in the misc tab. | |
| 417 | + $('#json-conclude-form-helper .json-form-element').each(function(x, y){ | |
| 531 | 418 | $('#json-conclude-form').append('<input type="hidden" name="' + y.name + '" value="' + y.value + '">'); |
| 532 | 419 | }); |
| 533 | - | |
| 534 | - $('body').trigger('visualizer:json:form:submit'); | |
| 420 | + $( '#json-chart-button' ).trigger('click'); | |
| 421 | + $('#canvas').lock(); | |
| 535 | 422 | }); |
| 536 | 423 | |
| 537 | 424 | // update the schedule |
| 538 | - $('#json-chart-save-button, #woo-chart-save-button').on('click', function(e){ | |
| 425 | + $('#json-chart-save-button').on('click', function(e){ | |
| 539 | 426 | e.preventDefault(); |
| 540 | 427 | $('#canvas').lock(); |
| 541 | - var btnID = jQuery( this ).attr( 'id' ); | |
| 542 | 428 | $.ajax({ |
| 543 | 429 | url : ajaxurl, |
| 544 | 430 | method : 'post', |
| 545 | 431 | data : { |
| @@ -544,11 +430,10 @@ | ||
| 544 | 430 | method : 'post', |
| 545 | 431 | data : { |
| 546 | 432 | 'action' : visualizer.ajax['actions']['json_set_schedule'], |
| 547 | 433 | 'security' : visualizer.ajax['nonces']['json_set_schedule'], |
| 548 | - 'chart' : $('#vz-json-time, #vz-woo-time').attr('data-chart'), | |
| 549 | - 'time' : $('#vz-json-time, #vz-woo-time').val(), | |
| 550 | - 'is_woocommerce_report': 'woo-chart-save-button' === btnID, | |
| 434 | + 'chart' : $('#vz-json-time').attr('data-chart'), | |
| 435 | + 'time' : $('#vz-json-time').val() | |
| 551 | 436 | }, |
| 552 | 437 | success : function(data){ |
| 553 | 438 | // do nothing. |
| 554 | 439 | }, |
| @@ -557,25 +442,13 @@ | ||
| 557 | 442 | } |
| 558 | 443 | }); |
| 559 | 444 | }); |
| 560 | 445 | |
| 561 | - // Select WooCommerce report endpoint. | |
| 562 | - $( '#vz-woo-source' ).on( 'click', function( e ) { | |
| 563 | - // Trigger change action. | |
| 564 | - $( 'body' ).trigger( 'visualizer:change:action' ); | |
| 565 | - | |
| 566 | - if ( '' !== $( this ).val() ) { | |
| 567 | - $( '#woo-chart-button, #woo-chart-save-button' ).removeAttr( 'disabled' ); | |
| 568 | - } else { | |
| 569 | - $( '#woo-chart-button, #woo-chart-save-button' ).attr( 'disabled', true ); | |
| 570 | - } | |
| 571 | - } ); | |
| 572 | - | |
| 573 | 446 | } |
| 574 | 447 | |
| 575 | 448 | function init_editor_table() { |
| 576 | 449 | $('body').on('visualizer:db:editor:table:init', function(event, data){ |
| 577 | - var $table = create_editor_table('.viz-table-editor', data.config); | |
| 450 | + var $table = create_editor_table('.viz-table-editor'); | |
| 578 | 451 | $('body').on('visualizer:db:editor:table:redraw', function(event, data){ |
| 579 | 452 | $table.draw(); |
| 580 | 453 | }); |
| 581 | 454 | }); |
| @@ -580,9 +453,9 @@ | ||
| 580 | 453 | }); |
| 581 | 454 | }); |
| 582 | 455 | } |
| 583 | 456 | |
| 584 | - function create_editor_table(element, config) { | |
| 457 | + function create_editor_table(element) { | |
| 585 | 458 | var settings = { |
| 586 | 459 | paging: false, |
| 587 | 460 | searching: false, |
| 588 | 461 | ordering: false, |
| @@ -607,13 +480,11 @@ | ||
| 607 | 480 | } |
| 608 | 481 | ] |
| 609 | 482 | } ); |
| 610 | 483 | } |
| 611 | - if(config){ | |
| 612 | - $.extend( settings, config ); | |
| 613 | - } | |
| 614 | 484 | |
| 615 | - var $table = $(element + ' .viz-editor-table').DataTable(settings); | |
| 485 | + $.extend( $.fn.dataTable.defaults, settings ); | |
| 486 | + var $table = $(element + ' .viz-editor-table').DataTable(); | |
| 616 | 487 | return $table; |
| 617 | 488 | } |
| 618 | 489 | |
| 619 | 490 | function json_accordion_activate($step, $activate){ |