| @@ -1,45 +1,12 @@ | ||
| 1 | 1 | /* global prompt */ |
| 2 | 2 | /* global visualizer */ |
| 3 | 3 | /* global alert */ |
| 4 | -/* global ajaxurl */ | |
| 5 | -/* global CodeMirror */ | |
| 6 | 4 | |
| 7 | 5 | (function ($) { |
| 8 | - $(window).on('load', function(){ | |
| 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(); | |
| 12 | - } | |
| 13 | - }); | |
| 14 | - | |
| 15 | 6 | $(document).ready(function () { |
| 16 | - // open the correct source tab. | |
| 17 | - var source = $('#visualizer-chart-id').attr('data-chart-source'); | |
| 18 | - $('li.viz-group.' + source).addClass('open'); | |
| 19 | - | |
| 20 | 7 | init_permissions(); |
| 21 | 8 | |
| 22 | - if(typeof visualizer !== 'undefined' && visualizer.is_pro) { | |
| 23 | - init_db_import(); | |
| 24 | - init_filter_import(); | |
| 25 | - } | |
| 26 | - | |
| 27 | - // update the manual configuation link to point to the correct chart type. | |
| 28 | - var type = $('#visualizer-chart-id').attr('data-chart-type'); | |
| 29 | - var chart_type_in_api_link = type + 'chart'; | |
| 30 | - switch (type) { | |
| 31 | - case "gauge": | |
| 32 | - case "table": | |
| 33 | - case "timeline": | |
| 34 | - chart_type_in_api_link = type; | |
| 35 | - break; | |
| 36 | - } | |
| 37 | - | |
| 38 | - if($('span.viz-gvlink').length > 0) { | |
| 39 | - $('span.viz-gvlink').html($('span.viz-gvlink').html().replace('?', chart_type_in_api_link)); | |
| 40 | - } | |
| 41 | - | |
| 42 | 9 | $('.type-radio').change(function () { |
| 43 | 10 | $('.type-label-selected').removeClass('type-label-selected'); |
| 44 | 11 | $(this).parent().addClass('type-label-selected'); |
| 45 | 12 | }); |
| @@ -104,12 +71,8 @@ | ||
| 104 | 71 | $(this).parent().find('.viz-section-description:first').toggle(); |
| 105 | 72 | return false; |
| 106 | 73 | }); |
| 107 | 74 | |
| 108 | - $('#cancel-button').click(function () { | |
| 109 | - $('#cancel-form').submit(); | |
| 110 | - }); | |
| 111 | - | |
| 112 | 75 | }); |
| 113 | 76 | |
| 114 | 77 | function init_permissions(){ |
| 115 | 78 | $('#vz-chart-permissions h2').click(function () { |
| @@ -185,125 +148,8 @@ | ||
| 185 | 148 | } |
| 186 | 149 | }); |
| 187 | 150 | }); |
| 188 | 151 | } |
| 189 | - | |
| 190 | - // https://codemirror.net/ | |
| 191 | - function init_db_import_component(){ | |
| 192 | - var table_columns = visualizer.db_query.tables; | |
| 193 | - var code_mirror = wp.CodeMirror || CodeMirror; | |
| 194 | - var cm = code_mirror.fromTextArea($('.visualizer-db-query').get(0), { | |
| 195 | - value: $('.visualizer-db-query').val(), | |
| 196 | - autofocus: true, | |
| 197 | - mode: 'text/x-mysql', | |
| 198 | - lineWrapping: true, | |
| 199 | - dragDrop: false, | |
| 200 | - matchBrackets: true, | |
| 201 | - autoCloseBrackets: true, | |
| 202 | - extraKeys: {"Ctrl-Space": "autocomplete"}, | |
| 203 | - hintOptions: { tables: table_columns } | |
| 204 | - }); | |
| 205 | - | |
| 206 | - // force refresh so that the query shows on first time load. Otherwise you have to click on the editor for it to show. | |
| 207 | - $('body').on('visualizer:db:query:focus', function(event, data){ | |
| 208 | - cm.refresh(); | |
| 209 | - }); | |
| 210 | - | |
| 211 | - cm.focus(); | |
| 212 | - | |
| 213 | - // update text area. | |
| 214 | - cm.on('inputRead', function(x, y){ | |
| 215 | - cm.save(); | |
| 216 | - }); | |
| 217 | - | |
| 218 | - // backspace and delete do not register so the text box does not get empty if the entire query is deleted | |
| 219 | - // from the editor. Let's force this. | |
| 220 | - $('body').on('visualizer:db:query:update', function(event, data){ | |
| 221 | - cm.save(); | |
| 222 | - }); | |
| 223 | - } | |
| 224 | - | |
| 225 | - function init_filter_import() { | |
| 226 | - $( '#db-filter-save-button' ).on( 'click', function(){ | |
| 227 | - $('#vz-filter-wizard').submit(); | |
| 228 | - }); | |
| 229 | - } | |
| 230 | - | |
| 231 | - function init_db_import(){ | |
| 232 | - $( '#visualizer-db-query' ).css("z-index", "-1").hide(); | |
| 233 | - | |
| 234 | - init_db_import_component(); | |
| 235 | - | |
| 236 | - $('#visualizer-query-fetch').on('click', function(e){ | |
| 237 | - | |
| 238 | - $('body').trigger('visualizer:db:query:update', {}); | |
| 239 | - if($('.visualizer-db-query').val() === ''){ | |
| 240 | - return; | |
| 241 | - } | |
| 242 | - | |
| 243 | - start_ajax($('#visualizer-db-query')); | |
| 244 | - $('.db-wizard-results').empty(); | |
| 245 | - $('.db-wizard-error').empty(); | |
| 246 | - $.ajax({ | |
| 247 | - url : ajaxurl, | |
| 248 | - method : 'post', | |
| 249 | - data : { | |
| 250 | - 'action' : visualizer.ajax['actions']['db_get_data'], | |
| 251 | - 'security' : visualizer.ajax['nonces']['db_get_data'], | |
| 252 | - 'params' : $('#db-query-form').serialize() | |
| 253 | - }, | |
| 254 | - success : function(data){ | |
| 255 | - if(data.success){ | |
| 256 | - $('.db-wizard-results').html(data.data.table); | |
| 257 | - $('#results').DataTable({ | |
| 258 | - "paging": false | |
| 259 | - }); | |
| 260 | - }else{ | |
| 261 | - $('.db-wizard-error').html(data.data.msg); | |
| 262 | - } | |
| 263 | - }, | |
| 264 | - complete: function(){ | |
| 265 | - end_ajax($('#visualizer-db-query')); | |
| 266 | - } | |
| 267 | - }); | |
| 268 | - }); | |
| 269 | - | |
| 270 | - $( '#db-chart-button' ).on( 'click', function(){ | |
| 271 | - $('#content').css('width', 'calc(100% - 300px)'); | |
| 272 | - if( $(this).attr( 'data-current' ) === 'chart'){ | |
| 273 | - $(this).val( $(this).attr( 'data-t-filter' ) ); | |
| 274 | - $(this).html( $(this).attr( 'data-t-filter' ) ); | |
| 275 | - $(this).attr( 'data-current', 'filter' ); | |
| 276 | - $( '.visualizer-editor-lhs' ).hide(); | |
| 277 | - $( '#visualizer-db-query' ).css("z-index", "9999").show(); | |
| 278 | - $('body').trigger('visualizer:db:query:focus', {}); | |
| 279 | - $( '#canvas' ).hide(); | |
| 280 | - }else{ | |
| 281 | - var filter_button = $(this); | |
| 282 | - $( '#visualizer-db-query' ).css("z-index", "-1").hide(); | |
| 283 | - $('#canvas').lock(); | |
| 284 | - filter_button.val( filter_button.attr( 'data-t-chart' ) ); | |
| 285 | - filter_button.html( filter_button.attr( 'data-t-chart' ) ); | |
| 286 | - filter_button.attr( 'data-current', 'chart' ); | |
| 287 | - $( '#canvas' ).css("z-index", "1").show(); | |
| 288 | - $( '#db-chart-save-button' ).trigger('click'); | |
| 289 | - } | |
| 290 | - } ); | |
| 291 | - | |
| 292 | - $( '#db-chart-save-button' ).on( 'click', function(){ | |
| 293 | - $('#viz-db-wizard-params').val($('#db-query-form').serialize()); | |
| 294 | - $('#vz-db-wizard').submit(); | |
| 295 | - }); | |
| 296 | - } | |
| 297 | - | |
| 298 | - function start_ajax(element){ | |
| 299 | - element.lock(); | |
| 300 | - } | |
| 301 | - | |
| 302 | - function end_ajax(element){ | |
| 303 | - element.unlock(); | |
| 304 | - } | |
| 305 | - | |
| 306 | 152 | })(jQuery); |
| 307 | 153 | |
| 308 | 154 | (function ($) { |
| 309 | 155 | $.fn.lock = function () { |