| @@ -1,18 +1,15 @@ | ||
| 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 | - let chart_select = $('#chart-select'); | |
| 12 | - if(chart_select.length > 0){ | |
| 13 | - // scroll to the selected chart type. | |
| 14 | - $('#chart-select')[0].scrollIntoView(); | |
| 9 | + // scroll to the selected chart type. | |
| 10 | + if($('label.type-label.type-label-selected').length > 0) { | |
| 11 | + $('label.type-label.type-label-selected')[0].scrollIntoView(); | |
| 15 | 12 | } |
| 16 | 13 | }); |
| 17 | 14 | |
| 18 | 15 | $(document).ready(function () { |
| @@ -18,28 +15,9 @@ | ||
| 18 | 15 | $(document).ready(function () { |
| 19 | 16 | onReady(); |
| 20 | 17 | }); |
| 21 | 18 | |
| 22 | - function initTabs(){ | |
| 23 | - $( "#sidebar" ).lock(); | |
| 24 | - $( "#viz-tabs" ).tabs({ | |
| 25 | - create: function( event, ui ) { | |
| 26 | - $(this).addClass('done'); | |
| 27 | - $( "#sidebar" ).unlock(); | |
| 28 | - }, | |
| 29 | - beforeActivate: function( event, ui ) { | |
| 30 | - // if settings have changed in tab #2 and tab #1 is being activated, warn the user. | |
| 31 | - if(vizHaveSettingsChanged() && ui.newTab.find( 'a' ).attr( 'id' ).includes('viz-tab-basic')){ | |
| 32 | - return confirm(visualizer.l10n.save_settings); | |
| 33 | - } | |
| 34 | - } | |
| 35 | - }); | |
| 36 | - } | |
| 37 | - | |
| 38 | 19 | function onReady() { |
| 39 | - initAccessibility(); | |
| 40 | - initTabs(); | |
| 41 | - | |
| 42 | 20 | // open the correct source tab/sub-tab. |
| 43 | 21 | var source = $('#visualizer-chart-id').attr('data-chart-source'); |
| 44 | 22 | $('li.viz-group.' + source).addClass('open'); |
| 45 | 23 | $('li.viz-group.' + source + ' span.viz-section-title.' + source).addClass('open'); |
| @@ -73,11 +51,24 @@ | ||
| 73 | 51 | |
| 74 | 52 | $('.type-radio').change(function () { |
| 75 | 53 | $('.type-label-selected').removeClass('type-label-selected'); |
| 76 | 54 | $(this).parent().addClass('type-label-selected'); |
| 77 | - updateTypeAriaChecked(); | |
| 78 | 55 | }); |
| 79 | 56 | |
| 57 | + $('#vz-chart-settings h2').click(function () { | |
| 58 | + $("#vz-chart-source").hide(); | |
| 59 | + $("#vz-chart-permissions").removeClass('open').addClass('bottom-fixed'); | |
| 60 | + $(this).parent().removeClass('bottom-fixed').addClass('open'); | |
| 61 | + $("#vz-chart-permissions .viz-group-header").hide(); | |
| 62 | + return false; | |
| 63 | + }); | |
| 64 | + $('#vz-chart-settings .customize-section-back').click(function () { | |
| 65 | + $("#vz-chart-source").show(); | |
| 66 | + $(this).parent().parent().removeClass('open').addClass('bottom-fixed'); | |
| 67 | + | |
| 68 | + return false; | |
| 69 | + }); | |
| 70 | + | |
| 80 | 71 | // collapse other open sections of this group |
| 81 | 72 | $(document).on('click', '.viz-group-title', function () { |
| 82 | 73 | var parent = $(this).parent(); |
| 83 | 74 | |
| @@ -87,27 +78,22 @@ | ||
| 87 | 78 | parent.parent().find('.viz-group.open').removeClass('open'); |
| 88 | 79 | parent.addClass('open'); |
| 89 | 80 | } |
| 90 | 81 | |
| 91 | - /* | |
| 92 | - * if the user wants to perform an action and click that tab to change the source | |
| 93 | - * and the chart is no longer showing because that particular LHS screen is showing | |
| 94 | - * e.g. create parameters, import json, db query box etc. | |
| 95 | - * we need to make sure we cancel the current process WITHOUT saving | |
| 96 | - * and then show the chart as it was | |
| 97 | - * let's close the LHS window and show the chart that is hidden | |
| 98 | - */ | |
| 99 | - $('body').trigger('visualizer:change:action'); | |
| 100 | - updateGroupAriaState($(this)); | |
| 82 | + // if the user wanted to perform an action | |
| 83 | + // and the chart is no longer showing because that particular screen is showing | |
| 84 | + // e.g. create parameters | |
| 85 | + // and then the user decided to click on another action | |
| 86 | + // let's invoke the show chart of the previous action so that the chart shows | |
| 87 | + // and the user does not get confused | |
| 88 | + $('input[type="button"][data-current!="chart"].show-chart-toggle').trigger('click'); | |
| 101 | 89 | }); |
| 102 | 90 | |
| 103 | 91 | // collapse other open subsections of this section |
| 104 | 92 | $(document).on('click', '.viz-section-title', function () { |
| 105 | 93 | var grandparent = $(this).parent().parent(); |
| 106 | - grandparent.find('.viz-section-title.open').not(this).each(function () { | |
| 107 | - $(this).removeClass('open').siblings('.viz-section-items').hide(); | |
| 108 | - }); | |
| 109 | - updateSectionAriaState($(this)); | |
| 94 | + grandparent.find('.viz-section-title.open ~ .viz-section-items').hide(); | |
| 95 | + grandparent.find('.viz-section-title.open').removeClass('open'); | |
| 110 | 96 | }); |
| 111 | 97 | |
| 112 | 98 | $('#view-remote-file').click(function () { |
| 113 | 99 | var url = $(this).parent().find('#vz-schedule-url').val(); |
| @@ -133,11 +119,11 @@ | ||
| 133 | 119 | $(this).parent().submit(); |
| 134 | 120 | } |
| 135 | 121 | }); |
| 136 | 122 | |
| 137 | - $( window ).on( 'load', function() { | |
| 123 | + $('#thehole').load(function () { | |
| 138 | 124 | $('#canvas').unlock(); |
| 139 | - } ); | |
| 125 | + }); | |
| 140 | 126 | |
| 141 | 127 | $(document).on('click', '.viz-section-title', function () { |
| 142 | 128 | $(this).toggleClass('open').parent().find('.viz-section-items').toggle(); |
| 143 | 129 | }); |
| @@ -150,9 +136,9 @@ | ||
| 150 | 136 | $('#cancel-button').click(function () { |
| 151 | 137 | $('#cancel-form').submit(); |
| 152 | 138 | }); |
| 153 | 139 | |
| 154 | - init_available_chart_list(); | |
| 140 | + init_type_vs_library(); | |
| 155 | 141 | |
| 156 | 142 | $('.viz-abort').on('click', function(e){ |
| 157 | 143 | e.preventDefault(); |
| 158 | 144 | window.parent.postMessage('visualizer:mediaframe:close', '*'); |
| @@ -159,226 +145,66 @@ | ||
| 159 | 145 | }); |
| 160 | 146 | |
| 161 | 147 | } |
| 162 | 148 | |
| 163 | - function initAccessibility(){ | |
| 164 | - // Chart type picker: treat tiles as radios with keyboard support. | |
| 165 | - var $typePicker = $('#type-picker'); | |
| 166 | - if($typePicker.length){ | |
| 167 | - $typePicker.attr('role', 'radiogroup'); | |
| 168 | - $('.type-label').each(function(){ | |
| 169 | - var $label = $(this); | |
| 170 | - var $input = $label.find('input[type="radio"]'); | |
| 171 | - $label.attr('tabindex', '0').attr('role', 'radio'); | |
| 172 | - if($input.length){ | |
| 173 | - $label.attr('aria-checked', $input.is(':checked') ? 'true' : 'false'); | |
| 174 | - }else{ | |
| 175 | - $label.attr('aria-disabled', 'true'); | |
| 176 | - } | |
| 177 | - }); | |
| 178 | - $(document).on('keydown', '.type-label', function(e){ | |
| 179 | - if(e.key === 'Enter' || e.key === ' '){ | |
| 180 | - e.preventDefault(); | |
| 181 | - var $label = $(this); | |
| 182 | - var $input = $label.find('input[type="radio"]'); | |
| 183 | - if($input.length){ | |
| 184 | - $input.prop('checked', true).trigger('change'); | |
| 185 | - } | |
| 186 | - } | |
| 187 | - }); | |
| 149 | + function init_type_vs_library() { | |
| 150 | + var $data = $('select.viz-select-library').attr('data-type-vs-library'); | |
| 151 | + if(typeof $data === 'undefined' || $data.length === 0){ | |
| 152 | + return; | |
| 188 | 153 | } |
| 189 | - | |
| 190 | - // Collapsible groups: add button roles + keyboard activation. | |
| 191 | - $('.viz-group-title').each(function(index){ | |
| 192 | - var $title = $(this); | |
| 193 | - $title.attr('role', 'button').attr('tabindex', '0'); | |
| 194 | - var $content = $title.siblings('.viz-group-content'); | |
| 195 | - if($content.length){ | |
| 196 | - if(!$content.attr('id')){ | |
| 197 | - $content.attr('id', 'viz-group-content-' + index); | |
| 198 | - } | |
| 199 | - $title.attr('aria-controls', $content.attr('id')); | |
| 200 | - updateGroupAriaState($title); | |
| 201 | - } | |
| 154 | + var $typeVsLibrary = JSON.parse( $('select.viz-select-library').attr('data-type-vs-library') ); | |
| 155 | + // disable all unsupported libraries for the chart type. | |
| 156 | + $('input.type-radio').on('click', function(){ | |
| 157 | + enable_libraries_for($(this).val(), $typeVsLibrary); | |
| 202 | 158 | }); |
| 203 | - $(document).on('keydown', '.viz-group-title', function(e){ | |
| 204 | - if(e.key === 'Enter' || e.key === ' '){ | |
| 205 | - e.preventDefault(); | |
| 206 | - $(this).trigger('click'); | |
| 207 | - } | |
| 208 | - }); | |
| 209 | 159 | |
| 210 | - // Subsections in source panel. | |
| 211 | - $('.viz-section-title').each(function(index){ | |
| 212 | - var $title = $(this); | |
| 213 | - $title.attr('role', 'button').attr('tabindex', '0'); | |
| 214 | - var $items = $title.siblings('.viz-section-items'); | |
| 215 | - if($items.length){ | |
| 216 | - if(!$items.attr('id')){ | |
| 217 | - $items.attr('id', 'viz-section-items-' + index); | |
| 218 | - } | |
| 219 | - $title.attr('aria-controls', $items.attr('id')); | |
| 220 | - updateSectionAriaState($title); | |
| 221 | - } | |
| 222 | - }); | |
| 223 | - $(document).on('keydown', '.viz-section-title', function(e){ | |
| 224 | - if(e.key === 'Enter' || e.key === ' '){ | |
| 225 | - e.preventDefault(); | |
| 226 | - $(this).trigger('click'); | |
| 227 | - } | |
| 228 | - }); | |
| 160 | + enable_libraries_for($('input.type-radio:checked').val(), $typeVsLibrary); | |
| 229 | 161 | } |
| 230 | 162 | |
| 231 | - function updateTypeAriaChecked(){ | |
| 232 | - $('.type-label').each(function(){ | |
| 233 | - var $label = $(this); | |
| 234 | - var $input = $label.find('input[type="radio"]'); | |
| 235 | - if($input.length){ | |
| 236 | - $label.attr('aria-checked', $input.is(':checked') ? 'true' : 'false'); | |
| 237 | - } | |
| 163 | + function enable_libraries_for($type, $typeVsLibrary) { | |
| 164 | + $('select.viz-select-library option').addClass('disabled').attr('disabled', 'disabled'); | |
| 165 | + var $libs = $typeVsLibrary[$type]; | |
| 166 | + $.each($libs, function( i, $lib ) { | |
| 167 | + $('select.viz-select-library option[value="' + $lib + '"]').removeClass('disabled').removeAttr('disabled'); | |
| 238 | 168 | }); |
| 169 | + $('select.viz-select-library').val( $('select.viz-select-library option:not(.disabled)').val() ); | |
| 239 | 170 | } |
| 240 | 171 | |
| 241 | - function updateGroupAriaState($title){ | |
| 242 | - if(!$title || $title.length === 0){ | |
| 243 | - return; | |
| 244 | - } | |
| 245 | - var isOpen = $title.parent().hasClass('open'); | |
| 246 | - $title.attr('aria-expanded', isOpen ? 'true' : 'false'); | |
| 247 | - } | |
| 172 | + function init_permissions(){ | |
| 173 | + $('#vz-chart-permissions h2').click(function () { | |
| 174 | + $("#vz-chart-source").hide(); | |
| 175 | + $("#vz-chart-permissions .viz-group-header").show(); | |
| 176 | + $("#vz-chart-settings").removeClass('open').addClass('bottom-fixed'); | |
| 248 | 177 | |
| 249 | - function updateSectionAriaState($title){ | |
| 250 | - if(!$title || $title.length === 0){ | |
| 251 | - return; | |
| 252 | - } | |
| 253 | - var isOpen = $title.hasClass('open'); | |
| 254 | - $title.attr('aria-expanded', isOpen ? 'true' : 'false'); | |
| 255 | - } | |
| 178 | + $('#settings-button').click(function(e) { | |
| 179 | + e.preventDefault(); | |
| 180 | + $('#permissions-form').submit(); | |
| 181 | + $('#settings-form').submit(); | |
| 182 | + }); | |
| 256 | 183 | |
| 257 | - /** | |
| 258 | - * Initialize/Update the available chart list based on their supported renderer libraries. | |
| 259 | - * | |
| 260 | - * @returns {void} | |
| 261 | - */ | |
| 262 | - function init_available_chart_list() { | |
| 263 | - const rendererSelect = document.querySelector('select.viz-select-library'); | |
| 264 | - if ( ! rendererSelect ) { | |
| 265 | - return; | |
| 266 | - } | |
| 184 | + $(this).parent().removeClass('bottom-fixed').addClass('open'); | |
| 267 | 185 | |
| 268 | - const rendererTypesMappingData = rendererSelect?.getAttribute('data-type-vs-library'); | |
| 269 | - if( ! rendererTypesMappingData ) { | |
| 270 | - return; | |
| 271 | - } | |
| 186 | + return false; | |
| 187 | + }); | |
| 188 | + $('#vz-chart-permissions .customize-section-back').click(function () { | |
| 189 | + $("#vz-chart-source").show(); | |
| 272 | 190 | |
| 273 | - /** @type {Record<string, ('GoogleCharts' | 'ChartJS' | 'DataTable')[]>} */ | |
| 274 | - const rendererTypesMapping = JSON.parse( rendererTypesMappingData ); | |
| 275 | - | |
| 276 | - document.querySelectorAll('input.type-radio').forEach( chartTypeRadio => { | |
| 277 | - | |
| 278 | - // Init the lib based on the default selected chart type. | |
| 279 | - if ( chartTypeRadio.checked ) { | |
| 280 | - const chartType = chartTypeRadio.value; | |
| 281 | - if ( ! chartType ) { | |
| 282 | - return; | |
| 283 | - } | |
| 284 | - | |
| 285 | - const selectedRenderer = rendererSelect.value; | |
| 286 | - if ( ! rendererTypesMapping[chartType]?.includes( selectedRenderer ) ) { | |
| 287 | - disable_renderer_select_placeholder(); | |
| 288 | - rendererSelect.value = rendererTypesMapping[chartType][0] | |
| 289 | - } | |
| 290 | - } | |
| 291 | - | |
| 292 | - chartTypeRadio.addEventListener('click', (event) => { | |
| 293 | - // Check if the chart type is supported by the selected renderer. If not, select the first supported renderer. | |
| 294 | - const chartType = event.target.value; | |
| 295 | - if ( ! chartType ) { | |
| 296 | - return; | |
| 297 | - } | |
| 298 | - | |
| 299 | - const selectedRenderer = rendererSelect.value; | |
| 300 | - if ( ! rendererTypesMapping[chartType]?.includes( selectedRenderer ) ) { | |
| 301 | - disable_renderer_select_placeholder(); | |
| 302 | - rendererSelect.value = rendererTypesMapping[chartType][0] | |
| 303 | - } | |
| 191 | + $("#vz-chart-permissions .viz-group-header").hide(); | |
| 192 | + $('#settings-button').click(function(e) { | |
| 193 | + e.preventDefault(); | |
| 194 | + $('#settings-form').submit(); | |
| 304 | 195 | }); |
| 305 | - }); | |
| 306 | 196 | |
| 307 | - // Update the chart list on user interaction. | |
| 308 | - rendererSelect.addEventListener('change', (event) => { | |
| 309 | - disable_renderer_select_placeholder(); | |
| 310 | - toggle_renderer_type( event.target.value ); | |
| 311 | - toggle_chart_types_by_render( event.target.value ); | |
| 312 | - }); | |
| 197 | + $(this).parent().parent().removeClass('open').addClass('bottom-fixed'); | |
| 313 | 198 | |
| 314 | - } | |
| 315 | - | |
| 316 | - /** | |
| 317 | - * Disable the placeholder option in the renderer select. | |
| 318 | - */ | |
| 319 | - function disable_renderer_select_placeholder() { | |
| 320 | - const placeholderOption = document.querySelector('#library-select-placeholder'); | |
| 321 | - if ( placeholderOption && placeholderOption.disabled === false ) { | |
| 322 | - placeholderOption.disabled = true; | |
| 323 | - } | |
| 324 | - } | |
| 325 | - | |
| 326 | - /** | |
| 327 | - * Toggle the renderer type class based on the given renderer type. | |
| 328 | - * | |
| 329 | - * The class is used to style the chart type picker based on the given renderer library. | |
| 330 | - * | |
| 331 | - * @param {('GoogleCharts' | 'ChartJS' | 'DataTable')} rendererType The renderer type to toggle the class. | |
| 332 | - */ | |
| 333 | - function toggle_renderer_type( rendererType ) { | |
| 334 | - const typePicker = document.querySelector('#type-picker'); | |
| 335 | - if ( ! typePicker ) { | |
| 336 | - return; | |
| 337 | - } | |
| 338 | - | |
| 339 | - typePicker.classList.remove('lib-GoogleCharts', 'lib-ChartJS', 'lib-DataTable'); | |
| 340 | - typePicker.classList.add(`lib-${rendererType}`); | |
| 341 | - } | |
| 342 | - | |
| 343 | - /** | |
| 344 | - * Toggle chart types based on the given renderer type. | |
| 345 | - * | |
| 346 | - * @param {('GoogleCharts' | 'ChartJS' | 'DataTable')} rendererType The renderer type to filter the chart types. | |
| 347 | - */ | |
| 348 | - function toggle_chart_types_by_render( rendererType ) { | |
| 349 | - document.querySelectorAll('.type-box').forEach( typeBox => { | |
| 350 | - const hasLib = typeBox.classList.contains(`type-lib-${rendererType}`); | |
| 351 | - typeBox.classList.toggle('viz-hidden', ! hasLib ); | |
| 352 | - | |
| 353 | - // Reset unavailable chart type selection. | |
| 354 | - const chartOption = typeBox.querySelector('input[type="radio"]'); | |
| 355 | - if ( ! hasLib && chartOption?.checked ) { | |
| 356 | - chartOption.checked = false; | |
| 357 | - } | |
| 199 | + return false; | |
| 358 | 200 | }); |
| 359 | 201 | |
| 360 | - enable_libraries_for($('input.type-radio:checked').val(), $typeVsLibrary); | |
| 361 | - } | |
| 362 | - | |
| 363 | - function enable_libraries_for($type, $typeVsLibrary) { | |
| 364 | - $('select.viz-select-library option').addClass('disabled').attr('disabled', 'disabled'); | |
| 365 | - $('select.viz-select-library option .premium-label').remove(); | |
| 366 | - $('select.viz-select-library option').append('<span class="premium-label"> (PREMIUM)</span>'); | |
| 367 | - var $libs = $typeVsLibrary[$type]; | |
| 368 | - $.each($libs, function( i, $lib ) { | |
| 369 | - $('select.viz-select-library option[value="' + $lib + '"]').removeClass('disabled').removeAttr('disabled'); | |
| 370 | - $('select.viz-select-library option[value="' + $lib + '"] .premium-label').remove(); | |
| 371 | - }); | |
| 372 | - $('select.viz-select-library').val( $('select.viz-select-library option:not(.disabled)').val() ); | |
| 373 | - } | |
| 374 | - | |
| 375 | - function init_permissions(){ | |
| 376 | 202 | $('.visualizer-permission').chosen({ |
| 377 | 203 | width : '50%', |
| 378 | 204 | search_contains : true |
| 379 | 205 | }); |
| 380 | - | |
| 206 | + | |
| 381 | 207 | $('.visualizer-permission-type').each(function(x, y){ |
| 382 | 208 | var type = $(y).attr('data-visualizer-permission-type'); |
| 383 | 209 | var child = $('.visualizer-permission-' + type + '-specific'); |
| 384 | 210 | if($(y).val() === 'all'){ |
| @@ -385,9 +211,9 @@ | ||
| 385 | 211 | child.next('div.chosen-container').hide(); |
| 386 | 212 | return; |
| 387 | 213 | } |
| 388 | 214 | }); |
| 389 | - | |
| 215 | + | |
| 390 | 216 | $('.visualizer-permission-type').on('change', function(evt, params) { |
| 391 | 217 | var type = $(this).attr('data-visualizer-permission-type'); |
| 392 | 218 | var child = $('.visualizer-permission-' + type + '-specific'); |
| 393 | 219 | child.empty(); |
| @@ -430,9 +256,9 @@ | ||
| 430 | 256 | lineWrapping: true, |
| 431 | 257 | dragDrop: false, |
| 432 | 258 | matchBrackets: true, |
| 433 | 259 | autoCloseBrackets: true, |
| 434 | - extraKeys: {"Shift-Space": "autocomplete"}, | |
| 260 | + extraKeys: {"Ctrl-Space": "autocomplete"}, | |
| 435 | 261 | hintOptions: { tables: table_columns } |
| 436 | 262 | }); |
| 437 | 263 | |
| 438 | 264 | // force refresh so that the query shows on first time load. Otherwise you have to click on the editor for it to show. |
| @@ -440,9 +266,9 @@ | ||
| 440 | 266 | cm.refresh(); |
| 441 | 267 | }); |
| 442 | 268 | |
| 443 | 269 | cm.focus(); |
| 444 | - | |
| 270 | + | |
| 445 | 271 | // update text area. |
| 446 | 272 | cm.on('inputRead', function(x, y){ |
| 447 | 273 | cm.save(); |
| 448 | 274 | }); |
| @@ -451,9 +277,9 @@ | ||
| 451 | 277 | // from the editor. Let's force this. |
| 452 | 278 | $('body').on('visualizer:db:query:update', function(event, data){ |
| 453 | 279 | cm.save(); |
| 454 | 280 | }); |
| 455 | - | |
| 281 | + | |
| 456 | 282 | // clear the editor. |
| 457 | 283 | $('body').on('visualizer:db:query:setvalue', function(event, data){ |
| 458 | 284 | cm.setValue(data.value); |
| 459 | 285 | cm.clearHistory(); |
| @@ -468,10 +294,8 @@ | ||
| 468 | 294 | |
| 469 | 295 | function init_filter_import() { |
| 470 | 296 | $( '#db-filter-save-button' ).on( 'click', function(){ |
| 471 | 297 | $('#vz-filter-wizard').submit(); |
| 472 | - $( '#vz-wp-sync-options' ).hide(); | |
| 473 | - $( '#vz-wp-sync-btn' ).attr( 'aria-expanded', false ); | |
| 474 | 298 | }); |
| 475 | 299 | } |
| 476 | 300 | |
| 477 | 301 | function init_db_import(){ |
| @@ -484,9 +308,9 @@ | ||
| 484 | 308 | $('body').trigger('visualizer:db:query:update', {}); |
| 485 | 309 | if($('.visualizer-db-query').val() === ''){ |
| 486 | 310 | return; |
| 487 | 311 | } |
| 488 | - | |
| 312 | + | |
| 489 | 313 | start_ajax($('#visualizer-db-query')); |
| 490 | 314 | $('.db-wizard-results').empty(); |
| 491 | 315 | $('.db-wizard-error').empty(); |
| 492 | 316 | $.ajax({ |
| @@ -513,19 +337,9 @@ | ||
| 513 | 337 | }); |
| 514 | 338 | }); |
| 515 | 339 | |
| 516 | 340 | $( '#db-chart-button' ).on( 'click', function(){ |
| 517 | - | |
| 518 | - $('body').off('visualizer:change:action').on('visualizer:change:action', function(e){ | |
| 519 | - var filter_button = $( '#db-chart-button' ); | |
| 520 | - $( '#visualizer-db-query' ).css("z-index", "-1").hide(); | |
| 521 | - filter_button.val( filter_button.attr( 'data-t-chart' ) ); | |
| 522 | - filter_button.html( filter_button.attr( 'data-t-chart' ) ); | |
| 523 | - filter_button.attr( 'data-current', 'chart' ); | |
| 524 | - $( '#canvas' ).css("z-index", "1").show(); | |
| 525 | - }); | |
| 526 | - | |
| 527 | - $('#content').css('width', 'calc(100% - 350px)'); | |
| 341 | + $('#content').css('width', 'calc(100% - 300px)'); | |
| 528 | 342 | if( $(this).attr( 'data-current' ) === 'chart'){ |
| 529 | 343 | $(this).val( $(this).attr( 'data-t-filter' ) ); |
| 530 | 344 | $(this).html( $(this).attr( 'data-t-filter' ) ); |
| 531 | 345 | $(this).attr( 'data-current', 'filter' ); |
| @@ -544,29 +358,13 @@ | ||
| 544 | 358 | $( '#db-chart-save-button' ).trigger('click'); |
| 545 | 359 | } |
| 546 | 360 | } ); |
| 547 | 361 | |
| 548 | - $( document ).on( 'click', '#vz-db-sync-btn', function(){ | |
| 549 | - var $options = $( '#vz-db-sync-options' ); | |
| 550 | - var isOpen = $options.is( ':visible' ); | |
| 551 | - $options.toggle(); | |
| 552 | - $( this ).attr( 'aria-expanded', ! isOpen ); | |
| 553 | - } ); | |
| 554 | - | |
| 555 | - $( document ).on( 'click', '#vz-wp-sync-btn', function(){ | |
| 556 | - var $options = $( '#vz-wp-sync-options' ); | |
| 557 | - var isOpen = $options.is( ':visible' ); | |
| 558 | - $options.toggle(); | |
| 559 | - $( this ).attr( 'aria-expanded', ! isOpen ); | |
| 560 | - } ); | |
| 561 | - | |
| 562 | 362 | $( '#db-chart-save-button' ).on( 'click', function(){ |
| 563 | 363 | // submit only if a query has been provided. |
| 564 | 364 | if($('#db-query-form .visualizer-db-query').val().length > 0){ |
| 565 | 365 | $('#viz-db-wizard-params').val($('#db-query-form').serialize()); |
| 566 | 366 | $('#vz-db-wizard').submit(); |
| 567 | - $( '#vz-db-sync-options' ).hide(); | |
| 568 | - $( '#vz-db-sync-btn' ).attr( 'aria-expanded', false ); | |
| 569 | 367 | }else{ |
| 570 | 368 | $('#canvas').unlock(); |
| 571 | 369 | } |
| 572 | 370 | }); |
| @@ -589,31 +387,11 @@ | ||
| 589 | 387 | active: false, |
| 590 | 388 | collapsible: true |
| 591 | 389 | }); |
| 592 | 390 | |
| 593 | - // open the accordions by default if they are indicated with the 'open' class. | |
| 594 | - $('.visualizer-json-subform .viz-substep.open').each(function(i, e){ | |
| 595 | - $('.visualizer-json-subform').accordion( "option", "active", i ); | |
| 596 | - }); | |
| 597 | - | |
| 598 | 391 | // toggle between chart and create/modify parameters |
| 599 | - $( '#json-chart-button, #woo-chart-button' ).on( 'click', function(){ | |
| 600 | - | |
| 601 | - $('body').off('visualizer:change:action').on('visualizer:change:action', function(e){ | |
| 602 | - var filter_button = $( '#json-chart-button, #woo-chart-button' ); | |
| 603 | - $( '#visualizer-json-screen' ).css("z-index", "-1").hide(); | |
| 604 | - filter_button.val( filter_button.attr( 'data-t-chart' ) ); | |
| 605 | - filter_button.html( filter_button.attr( 'data-t-chart' ) ); | |
| 606 | - filter_button.attr( 'data-current', 'chart' ); | |
| 607 | - $( '#canvas' ).css("z-index", "1").show(); | |
| 608 | - $( '#vz-import-woo-report' ).find( 'select, input' ).removeAttr( 'disabled' ); | |
| 609 | - }); | |
| 610 | - | |
| 611 | - if ( 'json-chart-button' === $( this ).attr( 'id' ) ) { | |
| 612 | - $( '#vz-import-woo-report' ).find( 'select, input' ).attr( 'disabled', true ); | |
| 613 | - } else { | |
| 614 | - $( '#vz-import-woo-report' ).find( 'select, input' ).removeAttr( 'disabled' ); | |
| 615 | - } | |
| 392 | + $( '#json-chart-button' ).on( 'click', function(){ | |
| 393 | + var $bttn = $(this); | |
| 616 | 394 | $('#content').css('width', 'calc(100% - 100px)'); |
| 617 | 395 | if( $(this).attr( 'data-current' ) === 'chart'){ |
| 618 | 396 | // toggle from chart to LHS form |
| 619 | 397 | $(this).val( $(this).attr( 'data-t-filter' ) ); |
| @@ -620,17 +398,8 @@ | ||
| 620 | 398 | $(this).html( $(this).attr( 'data-t-filter' ) ); |
| 621 | 399 | $(this).attr( 'data-current', 'filter' ); |
| 622 | 400 | $( '.visualizer-editor-lhs' ).hide(); |
| 623 | 401 | $( '#visualizer-json-screen' ).css("z-index", "9999").show(); |
| 624 | - if ( 'woo-chart-button' === $( this ).attr( 'id' ) && '' !== $( '#vz-woo-source:visible' ).val() ) { | |
| 625 | - $( '#vz-import-json-url' ).val( visualizer.rest_base + $( '#vz-woo-source' ).val() ).attr( 'readonly', true ); | |
| 626 | - } else { | |
| 627 | - if ( 'undefined' !== $( '#vz-import-json-url' ).attr( 'readonly' ) ) { | |
| 628 | - $( '#vz-import-json-url' ).val( '' ).removeAttr( 'readonly' ).removeAttr( 'value' ); | |
| 629 | - $('#json-endpoint-form')[0].reset(); | |
| 630 | - $('.visualizer-json-form h3.viz-step:not(.step1)').addClass('ui-state-disabled'); | |
| 631 | - } | |
| 632 | - } | |
| 633 | 402 | $( '#canvas' ).hide(); |
| 634 | 403 | }else{ |
| 635 | 404 | // toggle from LHS form to chart |
| 636 | 405 | $( '#json-conclude-form' ).trigger('submit'); |
| @@ -637,9 +406,9 @@ | ||
| 637 | 406 | } |
| 638 | 407 | } ); |
| 639 | 408 | |
| 640 | 409 | $('body').on('visualizer:json:form:submit', function() { |
| 641 | - var filter_button = $( '#json-chart-button, #woo-chart-button' ); | |
| 410 | + var filter_button = $( '#json-chart-button' ); | |
| 642 | 411 | $( '#visualizer-json-screen' ).css("z-index", "-1").hide(); |
| 643 | 412 | $('#canvas').lock(); |
| 644 | 413 | filter_button.val( filter_button.attr( 'data-t-chart' ) ); |
| 645 | 414 | filter_button.html( filter_button.attr( 'data-t-chart' ) ); |
| @@ -644,9 +413,9 @@ | ||
| 644 | 413 | filter_button.val( filter_button.attr( 'data-t-chart' ) ); |
| 645 | 414 | filter_button.html( filter_button.attr( 'data-t-chart' ) ); |
| 646 | 415 | filter_button.attr( 'data-current', 'chart' ); |
| 647 | 416 | end_ajax( $( '#visualizer-json-screen' ) ); |
| 648 | - $( '#canvas' ).removeClass('visualizer-chart-loaded').css("z-index", "1").show(); | |
| 417 | + $( '#canvas' ).css("z-index", "1").show(); | |
| 649 | 418 | }); |
| 650 | 419 | |
| 651 | 420 | |
| 652 | 421 | // fetch the roots for the provided endpoint |
| @@ -739,9 +508,9 @@ | ||
| 739 | 508 | return false; |
| 740 | 509 | } |
| 741 | 510 | |
| 742 | 511 | // populate the form elements that are in the other tabs. |
| 743 | - $('#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){ | |
| 512 | + $('#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){ | |
| 744 | 513 | $('#json-conclude-form').append('<input type="hidden" name="' + y.name + '" value="' + y.value + '">'); |
| 745 | 514 | }); |
| 746 | 515 | |
| 747 | 516 | $('body').trigger('visualizer:json:form:submit'); |
| @@ -747,12 +516,11 @@ | ||
| 747 | 516 | $('body').trigger('visualizer:json:form:submit'); |
| 748 | 517 | }); |
| 749 | 518 | |
| 750 | 519 | // update the schedule |
| 751 | - $('#json-chart-save-button, #woo-chart-save-button').on('click', function(e){ | |
| 520 | + $('#json-chart-save-button').on('click', function(e){ | |
| 752 | 521 | e.preventDefault(); |
| 753 | 522 | $('#canvas').lock(); |
| 754 | - var btnID = jQuery( this ).attr( 'id' ); | |
| 755 | 523 | $.ajax({ |
| 756 | 524 | url : ajaxurl, |
| 757 | 525 | method : 'post', |
| 758 | 526 | data : { |
| @@ -757,11 +525,10 @@ | ||
| 757 | 525 | method : 'post', |
| 758 | 526 | data : { |
| 759 | 527 | 'action' : visualizer.ajax['actions']['json_set_schedule'], |
| 760 | 528 | 'security' : visualizer.ajax['nonces']['json_set_schedule'], |
| 761 | - 'chart' : $('#vz-json-time, #vz-woo-time').attr('data-chart'), | |
| 762 | - 'time' : $('#vz-json-time, #vz-woo-time').val(), | |
| 763 | - 'is_woocommerce_report': 'woo-chart-save-button' === btnID, | |
| 529 | + 'chart' : $('#vz-json-time').attr('data-chart'), | |
| 530 | + 'time' : $('#vz-json-time').val() | |
| 764 | 531 | }, |
| 765 | 532 | success : function(data){ |
| 766 | 533 | // do nothing. |
| 767 | 534 | }, |
| @@ -770,20 +537,8 @@ | ||
| 770 | 537 | } |
| 771 | 538 | }); |
| 772 | 539 | }); |
| 773 | 540 | |
| 774 | - // Select WooCommerce report endpoint. | |
| 775 | - $( '#vz-woo-source' ).on( 'click', function( e ) { | |
| 776 | - // Trigger change action. | |
| 777 | - $( 'body' ).trigger( 'visualizer:change:action' ); | |
| 778 | - | |
| 779 | - if ( '' !== $( this ).val() ) { | |
| 780 | - $( '#woo-chart-button, #woo-chart-save-button' ).removeAttr( 'disabled' ); | |
| 781 | - } else { | |
| 782 | - $( '#woo-chart-button, #woo-chart-save-button' ).attr( 'disabled', true ); | |
| 783 | - } | |
| 784 | - } ); | |
| 785 | - | |
| 786 | 541 | } |
| 787 | 542 | |
| 788 | 543 | function init_editor_table() { |
| 789 | 544 | $('body').on('visualizer:db:editor:table:init', function(event, data){ |
| @@ -809,9 +564,9 @@ | ||
| 809 | 564 | }; |
| 810 | 565 | |
| 811 | 566 | // show column visibility button only when more than 6 columns are found (including the Label column) |
| 812 | 567 | if($(element + ' table.viz-editor-table thead tr th').length > 6){ |
| 813 | - $.extend( settings, { | |
| 568 | + $.extend( settings, { | |
| 814 | 569 | dom: 'Bt', |
| 815 | 570 | buttons: [ |
| 816 | 571 | { |
| 817 | 572 | extend: 'colvis', |
| @@ -892,107 +647,5 @@ | ||
| 892 | 647 | }); |
| 893 | 648 | |
| 894 | 649 | return $(this); |
| 895 | 650 | }; |
| 896 | - | |
| 897 | - // Telemetry | |
| 898 | - function getChartID() { | |
| 899 | - const urlParams = new URLSearchParams(window.location.search); | |
| 900 | - return urlParams.get('chart') ?? ''; | |
| 901 | - } | |
| 902 | - | |
| 903 | - const groupId = getChartID(); | |
| 904 | - | |
| 905 | - const chartTypes = document.querySelector('#viz-types-form') | |
| 906 | - if( chartTypes ) { | |
| 907 | - document.querySelector('.push-right[type=submit]')?.addEventListener('click', async function (event) { | |
| 908 | - if ( typeof window.tiTrk !== 'undefined' ) { | |
| 909 | - event.preventDefault(); | |
| 910 | - try { | |
| 911 | - const formData = new FormData(document.querySelector('#viz-types-form')); | |
| 912 | - const savedData = Object.fromEntries(formData); | |
| 913 | - | |
| 914 | - tiTrk?.with('visualizer')?.add({ | |
| 915 | - feature: 'chart-create', | |
| 916 | - featureComponent: 'saved-data', | |
| 917 | - featureData: { | |
| 918 | - type: savedData?.['type'], | |
| 919 | - library: savedData?.['chart-library'] | |
| 920 | - }, | |
| 921 | - groupId | |
| 922 | - }); | |
| 923 | - | |
| 924 | - // Do not make the user to wait too long for the event to be uploaded. | |
| 925 | - const timer = new Promise((resolve) => setTimeout(resolve, 500)); | |
| 926 | - await Promise.race([timer, tiTrk?.uploadEvents()]); | |
| 927 | - } catch (e) { | |
| 928 | - console.warn(e); | |
| 929 | - } | |
| 930 | - $('#viz-types-form').submit(); | |
| 931 | - } | |
| 932 | - }); | |
| 933 | - } | |
| 934 | - | |
| 935 | - [ | |
| 936 | - { | |
| 937 | - selector: '#editor-button', | |
| 938 | - featureComponent: 'source-manual-data' | |
| 939 | - }, | |
| 940 | - { | |
| 941 | - selector: '#vz-import-file', | |
| 942 | - featureComponent: 'source-import-csv-file' | |
| 943 | - }, | |
| 944 | - { | |
| 945 | - selector: '#vz-save-schedule', | |
| 946 | - featureComponent: 'source-import-csv-remote' | |
| 947 | - }, | |
| 948 | - { | |
| 949 | - selector: '#visualizer-json-fetch', | |
| 950 | - featureComponent: 'source-import-json-remote' | |
| 951 | - }, | |
| 952 | - { | |
| 953 | - selector: '#existing-chart', | |
| 954 | - featureComponent: 'source-import-chart' | |
| 955 | - }, | |
| 956 | - { | |
| 957 | - selector: '#filter-chart-button', | |
| 958 | - featureComponent: 'source-import-wordpress', | |
| 959 | - }, | |
| 960 | - { | |
| 961 | - selector: '#woo-chart-button', | |
| 962 | - featureComponent: 'source-import-woocommerce' | |
| 963 | - }, | |
| 964 | - { | |
| 965 | - selector: '#db-chart-button', | |
| 966 | - featureComponent: 'source-import-database' | |
| 967 | - } | |
| 968 | - ].forEach(({ selector, featureComponent }) => { | |
| 969 | - document.querySelector(selector)?.addEventListener('click', function () { | |
| 970 | - window?.tiTrk?.with('visualizer')?.set('used-source',{ | |
| 971 | - feature: 'chart-edit-used-source', | |
| 972 | - featureComponent, | |
| 973 | - groupId | |
| 974 | - }); | |
| 975 | - }); | |
| 976 | - }); | |
| 977 | -})(jQuery); | |
| 978 | - | |
| 979 | - | |
| 980 | -document.querySelector('#viz-copy-shortcode')?.addEventListener('click', function() { | |
| 981 | - var copyText = document.querySelector('#viz-shortcode')?.value; | |
| 982 | - if ( !copyText ) { | |
| 983 | - return; | |
| 984 | - } | |
| 985 | - | |
| 986 | - navigator.clipboard.writeText(copyText); | |
| 987 | - alert(visualizer.l10n.copied); | |
| 988 | -}); | |
| 989 | - | |
| 990 | -// Connect Chart Backend Title Info Panel with the field from the settings form. | |
| 991 | -const interactiveBackendTitleField = document.querySelector( '#viz-backend-name' ); | |
| 992 | -const backendTitleSave = document.querySelector( '#settings-form input[name="backend-title"]' ); | |
| 993 | - | |
| 994 | -if ( interactiveBackendTitleField && backendTitleSave ) { | |
| 995 | - interactiveBackendTitleField.addEventListener('input', function() { | |
| 996 | - backendTitleSave.value = this.value; | |
| 997 | - }); | |
| 998 | -} | |
| 651 | +})(jQuery); | |