| @@ -1,9 +1,11 @@ | ||
| 1 | 1 | /* global prompt */ |
| 2 | 2 | /* global visualizer */ |
| 3 | 3 | /* global alert */ |
| 4 | +/* global confirm */ | |
| 4 | 5 | /* global ajaxurl */ |
| 5 | 6 | /* global CodeMirror */ |
| 7 | +/* global vizHaveSettingsChanged */ | |
| 6 | 8 | |
| 7 | 9 | (function ($) { |
| 8 | 10 | $(window).on('load', function(){ |
| 9 | 11 | // scroll to the selected chart type. |
| @@ -12,11 +14,35 @@ | ||
| 12 | 14 | } |
| 13 | 15 | }); |
| 14 | 16 | |
| 15 | 17 | $(document).ready(function () { |
| 16 | - // open the correct source tab. | |
| 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.context).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 | + // open the correct source tab/sub-tab. | |
| 17 | 41 | var source = $('#visualizer-chart-id').attr('data-chart-source'); |
| 18 | 42 | $('li.viz-group.' + source).addClass('open'); |
| 43 | + $('li.viz-group.' + source + ' span.viz-section-title.' + source).addClass('open'); | |
| 44 | + $('li.viz-group.' + source + ' span.viz-section-title.' + source + '.open').parent().find('div.viz-section-items').show(); | |
| 19 | 45 | |
| 20 | 46 | init_permissions(); |
| 21 | 47 | |
| 22 | 48 | if(typeof visualizer !== 'undefined' && visualizer.is_pro) { |
| @@ -23,8 +49,12 @@ | ||
| 23 | 49 | init_db_import(); |
| 24 | 50 | init_filter_import(); |
| 25 | 51 | } |
| 26 | 52 | |
| 53 | + init_json_import(); | |
| 54 | + | |
| 55 | + init_editor_table(); | |
| 56 | + | |
| 27 | 57 | // update the manual configuation link to point to the correct chart type. |
| 28 | 58 | var type = $('#visualizer-chart-id').attr('data-chart-type'); |
| 29 | 59 | var chart_type_in_api_link = type + 'chart'; |
| 30 | 60 | switch (type) { |
| @@ -43,22 +73,10 @@ | ||
| 43 | 73 | $('.type-label-selected').removeClass('type-label-selected'); |
| 44 | 74 | $(this).parent().addClass('type-label-selected'); |
| 45 | 75 | }); |
| 46 | 76 | |
| 47 | - $('#vz-chart-settings h2').click(function () { | |
| 48 | - $("#vz-chart-source").hide(); | |
| 49 | - $("#vz-chart-permissions").removeClass('open').addClass('bottom-fixed'); | |
| 50 | - $(this).parent().removeClass('bottom-fixed').addClass('open'); | |
| 51 | - $("#vz-chart-permissions .viz-group-header").hide(); | |
| 52 | - return false; | |
| 53 | - }); | |
| 54 | - $('#vz-chart-settings .customize-section-back').click(function () { | |
| 55 | - $("#vz-chart-source").show(); | |
| 56 | - $(this).parent().parent().removeClass('open').addClass('bottom-fixed'); | |
| 57 | - | |
| 58 | - return false; | |
| 59 | - }); | |
| 60 | - $('.viz-group-title').click(function () { | |
| 77 | + // collapse other open sections of this group | |
| 78 | + $(document).on('click', '.viz-group-title', function () { | |
| 61 | 79 | var parent = $(this).parent(); |
| 62 | 80 | |
| 63 | 81 | if (parent.hasClass('open')) { |
| 64 | 82 | parent.removeClass('open'); |
| @@ -65,14 +83,32 @@ | ||
| 65 | 83 | } else { |
| 66 | 84 | parent.parent().find('.viz-group.open').removeClass('open'); |
| 67 | 85 | parent.addClass('open'); |
| 68 | 86 | } |
| 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'); | |
| 69 | 97 | }); |
| 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 | + | |
| 70 | 106 | $('#view-remote-file').click(function () { |
| 71 | - var url = $(this).parent().find('#remote-data').val(); | |
| 107 | + var url = $(this).parent().find('#vz-schedule-url').val(); | |
| 72 | 108 | |
| 73 | 109 | if (url !== '') { |
| 74 | - 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)) { | |
| 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)) { | |
| 75 | 111 | if (url.substr(url.length - 8) === '/pubhtml') { |
| 76 | 112 | url = url.substring(0, url.length - 8) + '/export?format=csv'; |
| 77 | 113 | } |
| 78 | 114 | |
| @@ -95,13 +131,13 @@ | ||
| 95 | 131 | $('#thehole').load(function () { |
| 96 | 132 | $('#canvas').unlock(); |
| 97 | 133 | }); |
| 98 | 134 | |
| 99 | - $('.viz-section-title').click(function () { | |
| 135 | + $(document).on('click', '.viz-section-title', function () { | |
| 100 | 136 | $(this).toggleClass('open').parent().find('.viz-section-items').toggle(); |
| 101 | 137 | }); |
| 102 | 138 | |
| 103 | - $('.more-info').click(function () { | |
| 139 | + $(document).on('click', '.more-info', function () { | |
| 104 | 140 | $(this).parent().find('.viz-section-description:first').toggle(); |
| 105 | 141 | return false; |
| 106 | 142 | }); |
| 107 | 143 | |
| @@ -108,40 +144,41 @@ | ||
| 108 | 144 | $('#cancel-button').click(function () { |
| 109 | 145 | $('#cancel-form').submit(); |
| 110 | 146 | }); |
| 111 | 147 | |
| 112 | - }); | |
| 148 | + init_type_vs_library(); | |
| 113 | 149 | |
| 114 | - function init_permissions(){ | |
| 115 | - $('#vz-chart-permissions h2').click(function () { | |
| 116 | - $("#vz-chart-source").hide(); | |
| 117 | - $("#vz-chart-permissions .viz-group-header").show(); | |
| 118 | - $("#vz-chart-settings").removeClass('open').addClass('bottom-fixed'); | |
| 150 | + $('.viz-abort').on('click', function(e){ | |
| 151 | + e.preventDefault(); | |
| 152 | + window.parent.postMessage('visualizer:mediaframe:close', '*'); | |
| 153 | + }); | |
| 119 | 154 | |
| 120 | - $('#settings-button').click(function(e) { | |
| 121 | - e.preventDefault(); | |
| 122 | - $('#permissions-form').submit(); | |
| 123 | - $('#settings-form').submit(); | |
| 124 | - }); | |
| 155 | + } | |
| 125 | 156 | |
| 126 | - $(this).parent().removeClass('bottom-fixed').addClass('open'); | |
| 127 | - | |
| 128 | - return false; | |
| 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); | |
| 129 | 166 | }); |
| 130 | - $('#vz-chart-permissions .customize-section-back').click(function () { | |
| 131 | - $("#vz-chart-source").show(); | |
| 132 | 167 | |
| 133 | - $("#vz-chart-permissions .viz-group-header").hide(); | |
| 134 | - $('#settings-button').click(function(e) { | |
| 135 | - e.preventDefault(); | |
| 136 | - $('#settings-form').submit(); | |
| 137 | - }); | |
| 168 | + enable_libraries_for($('input.type-radio:checked').val(), $typeVsLibrary); | |
| 169 | + } | |
| 138 | 170 | |
| 139 | - $(this).parent().parent().removeClass('open').addClass('bottom-fixed'); | |
| 140 | - | |
| 141 | - return false; | |
| 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'); | |
| 142 | 176 | }); |
| 177 | + $('select.viz-select-library').val( $('select.viz-select-library option:not(.disabled)').val() ); | |
| 178 | + } | |
| 143 | 179 | |
| 180 | + function init_permissions(){ | |
| 144 | 181 | $('.visualizer-permission').chosen({ |
| 145 | 182 | width : '50%', |
| 146 | 183 | search_contains : true |
| 147 | 184 | }); |
| @@ -219,8 +256,20 @@ | ||
| 219 | 256 | // from the editor. Let's force this. |
| 220 | 257 | $('body').on('visualizer:db:query:update', function(event, data){ |
| 221 | 258 | cm.save(); |
| 222 | 259 | }); |
| 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 | + }); | |
| 223 | 272 | } |
| 224 | 273 | |
| 225 | 274 | function init_filter_import() { |
| 226 | 275 | $( '#db-filter-save-button' ).on( 'click', function(){ |
| @@ -267,8 +316,18 @@ | ||
| 267 | 316 | }); |
| 268 | 317 | }); |
| 269 | 318 | |
| 270 | 319 | $( '#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 | + | |
| 271 | 330 | $('#content').css('width', 'calc(100% - 300px)'); |
| 272 | 331 | if( $(this).attr( 'data-current' ) === 'chart'){ |
| 273 | 332 | $(this).val( $(this).attr( 'data-t-filter' ) ); |
| 274 | 333 | $(this).html( $(this).attr( 'data-t-filter' ) ); |
| @@ -289,11 +348,251 @@ | ||
| 289 | 348 | } |
| 290 | 349 | } ); |
| 291 | 350 | |
| 292 | 351 | $( '#db-chart-save-button' ).on( 'click', function(){ |
| 293 | - $('#viz-db-wizard-params').val($('#db-query-form').serialize()); | |
| 294 | - $('#vz-db-wizard').submit(); | |
| 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 | + } | |
| 295 | 359 | }); |
| 360 | + } | |
| 361 | + | |
| 362 | + function init_json_import(){ | |
| 363 | + if(typeof visualizer === 'undefined'){ | |
| 364 | + return; | |
| 365 | + } | |
| 366 | + | |
| 367 | + var regex = new RegExp(visualizer.json_tag_separator, 'g'); | |
| 368 | + | |
| 369 | + $( '#visualizer-json-screen' ).css("z-index", "-1").hide(); | |
| 370 | + $('.visualizer-json-form').accordion({ | |
| 371 | + heightStyle: 'content', | |
| 372 | + active: 0 | |
| 373 | + }); | |
| 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 | + | |
| 385 | + // toggle between chart and create/modify parameters | |
| 386 | + $( '#json-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' ); | |
| 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 | + }); | |
| 396 | + | |
| 397 | + $('#content').css('width', 'calc(100% - 100px)'); | |
| 398 | + if( $(this).attr( 'data-current' ) === 'chart'){ | |
| 399 | + // toggle from chart to LHS form | |
| 400 | + $(this).val( $(this).attr( 'data-t-filter' ) ); | |
| 401 | + $(this).html( $(this).attr( 'data-t-filter' ) ); | |
| 402 | + $(this).attr( 'data-current', 'filter' ); | |
| 403 | + $( '.visualizer-editor-lhs' ).hide(); | |
| 404 | + $( '#visualizer-json-screen' ).css("z-index", "9999").show(); | |
| 405 | + $( '#canvas' ).hide(); | |
| 406 | + }else{ | |
| 407 | + // toggle from LHS form to chart | |
| 408 | + $( '#json-conclude-form' ).trigger('submit'); | |
| 409 | + } | |
| 410 | + } ); | |
| 411 | + | |
| 412 | + $('body').on('visualizer:json:form:submit', function() { | |
| 413 | + var filter_button = $( '#json-chart-button' ); | |
| 414 | + $( '#visualizer-json-screen' ).css("z-index", "-1").hide(); | |
| 415 | + $('#canvas').lock(); | |
| 416 | + filter_button.val( filter_button.attr( 'data-t-chart' ) ); | |
| 417 | + filter_button.html( filter_button.attr( 'data-t-chart' ) ); | |
| 418 | + filter_button.attr( 'data-current', 'chart' ); | |
| 419 | + end_ajax( $( '#visualizer-json-screen' ) ); | |
| 420 | + $( '#canvas' ).css("z-index", "1").show(); | |
| 421 | + }); | |
| 422 | + | |
| 423 | + | |
| 424 | + // fetch the roots for the provided endpoint | |
| 425 | + $( '#visualizer-json-fetch' ).on( 'click', function(e){ | |
| 426 | + e.preventDefault(); | |
| 427 | + $('.visualizer-json-form').accordion( 'option', 'active', 0 ); | |
| 428 | + $('.visualizer-json-form h3.viz-step:not(.step1)').addClass('ui-state-disabled'); | |
| 429 | + $('.json-table').html(''); | |
| 430 | + start_ajax( $( '#visualizer-json-screen' ) ); | |
| 431 | + $.ajax({ | |
| 432 | + url : ajaxurl, | |
| 433 | + method : 'post', | |
| 434 | + data : { | |
| 435 | + 'action' : visualizer.ajax['actions']['json_get_roots'], | |
| 436 | + 'security' : visualizer.ajax['nonces']['json_get_roots'], | |
| 437 | + 'params' : $('#json-endpoint-form').serialize() | |
| 438 | + }, | |
| 439 | + success : function(data){ | |
| 440 | + if(data.success){ | |
| 441 | + $('#vz-import-json-root').empty(); | |
| 442 | + $.each(data.data.roots, function(i, name){ | |
| 443 | + $('#vz-import-json-root').append('<option value="' + name + '">' + name.replace(regex, visualizer.json_tag_separator_view) + '</option>'); | |
| 444 | + }); | |
| 445 | + $('#json-root-form').fadeIn('medium'); | |
| 446 | + json_accordion_activate(1, true); | |
| 447 | + }else{ | |
| 448 | + alert(data.data.msg); | |
| 449 | + } | |
| 450 | + }, | |
| 451 | + complete: function(){ | |
| 452 | + end_ajax($('#visualizer-json-screen')); | |
| 453 | + } | |
| 454 | + }); | |
| 455 | + }); | |
| 456 | + | |
| 457 | + // fetch the data for the chosen root | |
| 458 | + $( '#visualizer-json-parse' ).on( 'click', function(e){ | |
| 459 | + e.preventDefault(); | |
| 460 | + $('.visualizer-json-form h3.viz-step:not(.step1):not(.step2)').addClass('ui-state-disabled'); | |
| 461 | + $('.json-table').html(''); | |
| 462 | + start_ajax( $( '#visualizer-json-screen' ) ); | |
| 463 | + $.ajax({ | |
| 464 | + url : ajaxurl, | |
| 465 | + method : 'post', | |
| 466 | + data : { | |
| 467 | + 'action' : visualizer.ajax['actions']['json_get_data'], | |
| 468 | + 'security' : visualizer.ajax['nonces']['json_get_data'], | |
| 469 | + 'params' : $('#json-root-form, #json-endpoint-form').serialize() | |
| 470 | + }, | |
| 471 | + success : function(data){ | |
| 472 | + if(data.success){ | |
| 473 | + $('#vz-import-json-paging option:not(.static)').remove(); | |
| 474 | + if(data.data.paging.length > 0){ | |
| 475 | + var $template = $('#vz-import-json-paging').attr('data-template'); | |
| 476 | + $.each(data.data.paging, function(i, name){ | |
| 477 | + var display = name.replace(regex, visualizer.json_tag_separator_view); | |
| 478 | + display = $template.replace('?', display); | |
| 479 | + $('#vz-import-json-paging').append('<option value="' + name + '">' + display + '</option>'); | |
| 480 | + }); | |
| 481 | + $('.json-pagination').show(); | |
| 482 | + } | |
| 483 | + $('#json-conclude-form .json-table').html(data.data.table); | |
| 484 | + | |
| 485 | + var $table = create_editor_table( '#json-conclude-form' ); | |
| 486 | + | |
| 487 | + json_accordion_activate(3, true); | |
| 488 | + json_accordion_activate(2, false); | |
| 489 | + $table.columns.adjust().draw(); | |
| 490 | + }else{ | |
| 491 | + alert(data.data.msg); | |
| 492 | + } | |
| 493 | + }, | |
| 494 | + complete: function(){ | |
| 495 | + end_ajax($('#visualizer-json-screen')); | |
| 496 | + } | |
| 497 | + }); | |
| 498 | + }); | |
| 499 | + | |
| 500 | + // when the data is set and the chart is updated, toggle the screen so that the chart is shown | |
| 501 | + $('#json-conclude-form').on( 'submit', function(e){ | |
| 502 | + // at least one column has to be selected as non-excluded. | |
| 503 | + var count_selected = 0; | |
| 504 | + $('select.viz-select-data-type').each(function(i, element){ | |
| 505 | + if($(element).prop('selectedIndex') > 0){ | |
| 506 | + count_selected++; | |
| 507 | + } | |
| 508 | + }); | |
| 509 | + if(count_selected === 0){ | |
| 510 | + alert(visualizer.l10n.select_columns); | |
| 511 | + return false; | |
| 512 | + } | |
| 513 | + | |
| 514 | + // populate the form elements that are in the other tabs. | |
| 515 | + $('#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').each(function(x, y){ | |
| 516 | + $('#json-conclude-form').append('<input type="hidden" name="' + y.name + '" value="' + y.value + '">'); | |
| 517 | + }); | |
| 518 | + | |
| 519 | + $('body').trigger('visualizer:json:form:submit'); | |
| 520 | + }); | |
| 521 | + | |
| 522 | + // update the schedule | |
| 523 | + $('#json-chart-save-button').on('click', function(e){ | |
| 524 | + e.preventDefault(); | |
| 525 | + $('#canvas').lock(); | |
| 526 | + $.ajax({ | |
| 527 | + url : ajaxurl, | |
| 528 | + method : 'post', | |
| 529 | + data : { | |
| 530 | + 'action' : visualizer.ajax['actions']['json_set_schedule'], | |
| 531 | + 'security' : visualizer.ajax['nonces']['json_set_schedule'], | |
| 532 | + 'chart' : $('#vz-json-time').attr('data-chart'), | |
| 533 | + 'time' : $('#vz-json-time').val() | |
| 534 | + }, | |
| 535 | + success : function(data){ | |
| 536 | + // do nothing. | |
| 537 | + }, | |
| 538 | + complete: function(){ | |
| 539 | + $('#canvas').unlock(); | |
| 540 | + } | |
| 541 | + }); | |
| 542 | + }); | |
| 543 | + | |
| 544 | + } | |
| 545 | + | |
| 546 | + function init_editor_table() { | |
| 547 | + $('body').on('visualizer:db:editor:table:init', function(event, data){ | |
| 548 | + var $table = create_editor_table('.viz-table-editor', data.config); | |
| 549 | + $('body').on('visualizer:db:editor:table:redraw', function(event, data){ | |
| 550 | + $table.draw(); | |
| 551 | + }); | |
| 552 | + }); | |
| 553 | + } | |
| 554 | + | |
| 555 | + function create_editor_table(element, config) { | |
| 556 | + var settings = { | |
| 557 | + paging: false, | |
| 558 | + searching: false, | |
| 559 | + ordering: false, | |
| 560 | + select: false, | |
| 561 | + scrollX: "100%", | |
| 562 | + scrollY: "400px", | |
| 563 | + info: false, | |
| 564 | + colReorder: { | |
| 565 | + fixedColumnsLeft: 1 | |
| 566 | + } | |
| 567 | + }; | |
| 568 | + | |
| 569 | + // show column visibility button only when more than 6 columns are found (including the Label column) | |
| 570 | + if($(element + ' table.viz-editor-table thead tr th').length > 6){ | |
| 571 | + $.extend( settings, { | |
| 572 | + dom: 'Bt', | |
| 573 | + buttons: [ | |
| 574 | + { | |
| 575 | + extend: 'colvis', | |
| 576 | + columns: ':gt(0)', | |
| 577 | + collectionLayout: 'four-column' | |
| 578 | + } | |
| 579 | + ] | |
| 580 | + } ); | |
| 581 | + } | |
| 582 | + if(config){ | |
| 583 | + $.extend( settings, config ); | |
| 584 | + } | |
| 585 | + | |
| 586 | + var $table = $(element + ' .viz-editor-table').DataTable(settings); | |
| 587 | + return $table; | |
| 588 | + } | |
| 589 | + | |
| 590 | + function json_accordion_activate($step, $activate){ | |
| 591 | + $('.visualizer-json-form h3.viz-step.step' + ( $step + 1 )).removeClass('ui-state-disabled'); | |
| 592 | + if($activate){ | |
| 593 | + $('.visualizer-json-form').accordion( 'option', 'active', $step ); | |
| 594 | + } | |
| 296 | 595 | } |
| 297 | 596 | |
| 298 | 597 | function start_ajax(element){ |
| 299 | 598 | element.lock(); |