| @@ -1,44 +1,10 @@ | ||
| 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).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 | - init_permissions(); | |
| 21 | - | |
| 22 | - if(typeof visualizer !== 'undefined' && visualizer.is_pro) { | |
| 23 | - init_db_import(); | |
| 24 | - } | |
| 25 | - | |
| 26 | - // update the manual configuation link to point to the correct chart type. | |
| 27 | - var type = $('#visualizer-chart-id').attr('data-chart-type'); | |
| 28 | - var chart_type_in_api_link = type + 'chart'; | |
| 29 | - switch (type) { | |
| 30 | - case "gauge": | |
| 31 | - case "table": | |
| 32 | - case "timeline": | |
| 33 | - chart_type_in_api_link = type; | |
| 34 | - break; | |
| 35 | - } | |
| 36 | - | |
| 37 | - if($('span.viz-gvlink').length > 0) { | |
| 38 | - $('span.viz-gvlink').html($('span.viz-gvlink').html().replace('?', chart_type_in_api_link)); | |
| 39 | - } | |
| 40 | - | |
| 41 | 7 | $('.type-radio').change(function () { |
| 42 | 8 | $('.type-label-selected').removeClass('type-label-selected'); |
| 43 | 9 | $(this).parent().addClass('type-label-selected'); |
| 44 | 10 | }); |
| @@ -44,11 +10,10 @@ | ||
| 44 | 10 | }); |
| 45 | 11 | |
| 46 | 12 | $('#vz-chart-settings h2').click(function () { |
| 47 | 13 | $("#vz-chart-source").hide(); |
| 48 | - $("#vz-chart-permissions").removeClass('open').addClass('bottom-fixed'); | |
| 49 | 14 | $(this).parent().removeClass('bottom-fixed').addClass('open'); |
| 50 | - $("#vz-chart-permissions .viz-group-header").hide(); | |
| 15 | + | |
| 51 | 16 | return false; |
| 52 | 17 | }); |
| 53 | 18 | $('#vz-chart-settings .customize-section-back').click(function () { |
| 54 | 19 | $("#vz-chart-source").show(); |
| @@ -55,15 +20,15 @@ | ||
| 55 | 20 | $(this).parent().parent().removeClass('open').addClass('bottom-fixed'); |
| 56 | 21 | |
| 57 | 22 | return false; |
| 58 | 23 | }); |
| 59 | - $('.viz-group-title').click(function () { | |
| 24 | + $('.group-title').click(function () { | |
| 60 | 25 | var parent = $(this).parent(); |
| 61 | 26 | |
| 62 | 27 | if (parent.hasClass('open')) { |
| 63 | 28 | parent.removeClass('open'); |
| 64 | 29 | } else { |
| 65 | - parent.parent().find('.viz-group.open').removeClass('open'); | |
| 30 | + parent.parent().find('.group.open').removeClass('open'); | |
| 66 | 31 | parent.addClass('open'); |
| 67 | 32 | } |
| 68 | 33 | }); |
| 69 | 34 | $('#view-remote-file').click(function () { |
| @@ -94,209 +59,18 @@ | ||
| 94 | 59 | $('#thehole').load(function () { |
| 95 | 60 | $('#canvas').unlock(); |
| 96 | 61 | }); |
| 97 | 62 | |
| 98 | - $('.viz-section-title').click(function () { | |
| 99 | - $(this).toggleClass('open').parent().find('.viz-section-items').toggle(); | |
| 63 | + $('.section-title').click(function () { | |
| 64 | + $(this).toggleClass('open').parent().find('.section-items').toggle(); | |
| 100 | 65 | }); |
| 101 | 66 | |
| 102 | 67 | $('.more-info').click(function () { |
| 103 | - $(this).parent().find('.viz-section-description:first').toggle(); | |
| 68 | + $(this).parent().find('.section-description:first').toggle(); | |
| 104 | 69 | return false; |
| 105 | 70 | }); |
| 106 | 71 | |
| 107 | - $('#cancel-button').click(function () { | |
| 108 | - $('#cancel-form').submit(); | |
| 109 | - }); | |
| 110 | - | |
| 111 | 72 | }); |
| 112 | - | |
| 113 | - function init_permissions(){ | |
| 114 | - $('#vz-chart-permissions h2').click(function () { | |
| 115 | - $("#vz-chart-source").hide(); | |
| 116 | - $("#vz-chart-permissions .viz-group-header").show(); | |
| 117 | - $("#vz-chart-settings").removeClass('open').addClass('bottom-fixed'); | |
| 118 | - | |
| 119 | - $('#settings-button').click(function(e) { | |
| 120 | - e.preventDefault(); | |
| 121 | - $('#permissions-form').submit(); | |
| 122 | - $('#settings-form').submit(); | |
| 123 | - }); | |
| 124 | - | |
| 125 | - $(this).parent().removeClass('bottom-fixed').addClass('open'); | |
| 126 | - | |
| 127 | - return false; | |
| 128 | - }); | |
| 129 | - $('#vz-chart-permissions .customize-section-back').click(function () { | |
| 130 | - $("#vz-chart-source").show(); | |
| 131 | - | |
| 132 | - $("#vz-chart-permissions .viz-group-header").hide(); | |
| 133 | - $('#settings-button').click(function(e) { | |
| 134 | - e.preventDefault(); | |
| 135 | - $('#settings-form').submit(); | |
| 136 | - }); | |
| 137 | - | |
| 138 | - $(this).parent().parent().removeClass('open').addClass('bottom-fixed'); | |
| 139 | - | |
| 140 | - return false; | |
| 141 | - }); | |
| 142 | - | |
| 143 | - $('.visualizer-permission').chosen({ | |
| 144 | - width : '50%', | |
| 145 | - search_contains : true | |
| 146 | - }); | |
| 147 | - | |
| 148 | - $('.visualizer-permission-type').each(function(x, y){ | |
| 149 | - var type = $(y).attr('data-visualizer-permission-type'); | |
| 150 | - var child = $('.visualizer-permission-' + type + '-specific'); | |
| 151 | - if($(y).val() === 'all'){ | |
| 152 | - child.next('div.chosen-container').hide(); | |
| 153 | - return; | |
| 154 | - } | |
| 155 | - }); | |
| 156 | - | |
| 157 | - $('.visualizer-permission-type').on('change', function(evt, params) { | |
| 158 | - var type = $(this).attr('data-visualizer-permission-type'); | |
| 159 | - var child = $('.visualizer-permission-' + type + '-specific'); | |
| 160 | - child.empty(); | |
| 161 | - if(params.selected === 'all'){ | |
| 162 | - child.next('div.chosen-container').hide(); | |
| 163 | - return; | |
| 164 | - } else { | |
| 165 | - child.next('div.chosen-container').show(); | |
| 166 | - } | |
| 167 | - child.append('<option value="">' + visualizer.l10n['loading'] + '</option>').trigger('chosen:updated'); | |
| 168 | - $.ajax({ | |
| 169 | - url : visualizer.ajax['url'], | |
| 170 | - method : 'post', | |
| 171 | - data : { | |
| 172 | - 'action' : visualizer.ajax['actions']['permissions'], | |
| 173 | - 'nonce' : visualizer.ajax['nonces']['permissions'], | |
| 174 | - 'type' : params.selected | |
| 175 | - }, | |
| 176 | - success : function(d, textStatus, XMLHttpRequest){ | |
| 177 | - if(d.success) { | |
| 178 | - child.empty(); | |
| 179 | - $.each(d.data, function(k, v){ | |
| 180 | - child.append('<option value="' + k + '">' + v + '</option>'); | |
| 181 | - }); | |
| 182 | - child.trigger('chosen:updated'); | |
| 183 | - } | |
| 184 | - } | |
| 185 | - }); | |
| 186 | - }); | |
| 187 | - } | |
| 188 | - | |
| 189 | - // https://codemirror.net/ | |
| 190 | - function init_db_import_component(){ | |
| 191 | - var table_columns = visualizer.db_query.tables; | |
| 192 | - var code_mirror = wp.CodeMirror || CodeMirror; | |
| 193 | - var cm = code_mirror.fromTextArea($('.visualizer-db-query').get(0), { | |
| 194 | - value: $('.visualizer-db-query').val(), | |
| 195 | - autofocus: true, | |
| 196 | - mode: 'text/x-mysql', | |
| 197 | - lineWrapping: true, | |
| 198 | - dragDrop: false, | |
| 199 | - matchBrackets: true, | |
| 200 | - autoCloseBrackets: true, | |
| 201 | - extraKeys: {"Ctrl-Space": "autocomplete"}, | |
| 202 | - hintOptions: { tables: table_columns } | |
| 203 | - }); | |
| 204 | - | |
| 205 | - // force refresh so that the query shows on first time load. Otherwise you have to click on the editor for it to show. | |
| 206 | - $('body').on('visualizer:db:query:focus', function(event, data){ | |
| 207 | - cm.refresh(); | |
| 208 | - }); | |
| 209 | - | |
| 210 | - cm.focus(); | |
| 211 | - | |
| 212 | - // update text area. | |
| 213 | - cm.on('inputRead', function(x, y){ | |
| 214 | - cm.save(); | |
| 215 | - }); | |
| 216 | - | |
| 217 | - // backspace and delete do not register so the text box does not get empty if the entire query is deleted | |
| 218 | - // from the editor. Let's force this. | |
| 219 | - $('body').on('visualizer:db:query:update', function(event, data){ | |
| 220 | - cm.save(); | |
| 221 | - }); | |
| 222 | - } | |
| 223 | - | |
| 224 | - function init_db_import(){ | |
| 225 | - $( '#visualizer-db-query' ).css("z-index", "-1").hide(); | |
| 226 | - | |
| 227 | - init_db_import_component(); | |
| 228 | - | |
| 229 | - $('#visualizer-query-fetch').on('click', function(e){ | |
| 230 | - | |
| 231 | - $('body').trigger('visualizer:db:query:update', {}); | |
| 232 | - if($('.visualizer-db-query').val() === ''){ | |
| 233 | - return; | |
| 234 | - } | |
| 235 | - | |
| 236 | - start_ajax($('#visualizer-db-query')); | |
| 237 | - $('.db-wizard-results').empty(); | |
| 238 | - $('.db-wizard-error').empty(); | |
| 239 | - $.ajax({ | |
| 240 | - url : ajaxurl, | |
| 241 | - method : 'post', | |
| 242 | - data : { | |
| 243 | - 'action' : visualizer.ajax['actions']['db_get_data'], | |
| 244 | - 'security' : visualizer.ajax['nonces']['db_get_data'], | |
| 245 | - 'params' : $('#db-query-form').serialize() | |
| 246 | - }, | |
| 247 | - success : function(data){ | |
| 248 | - if(data.success){ | |
| 249 | - $('.db-wizard-results').html(data.data.table); | |
| 250 | - $('#results').DataTable({ | |
| 251 | - "paging": false | |
| 252 | - }); | |
| 253 | - }else{ | |
| 254 | - $('.db-wizard-error').html(data.data.msg); | |
| 255 | - } | |
| 256 | - }, | |
| 257 | - complete: function(){ | |
| 258 | - end_ajax($('#visualizer-db-query')); | |
| 259 | - } | |
| 260 | - }); | |
| 261 | - }); | |
| 262 | - | |
| 263 | - $( '#db-chart-button' ).on( 'click', function(){ | |
| 264 | - $('#content').css('width', 'calc(100% - 300px)'); | |
| 265 | - if( $(this).attr( 'data-current' ) === 'chart'){ | |
| 266 | - $(this).val( $(this).attr( 'data-t-filter' ) ); | |
| 267 | - $(this).html( $(this).attr( 'data-t-filter' ) ); | |
| 268 | - $(this).attr( 'data-current', 'filter' ); | |
| 269 | - $( '.visualizer-editor-lhs' ).hide(); | |
| 270 | - $( '#visualizer-db-query' ).css("z-index", "9999").show(); | |
| 271 | - $('body').trigger('visualizer:db:query:focus', {}); | |
| 272 | - $( '#canvas' ).hide(); | |
| 273 | - }else{ | |
| 274 | - var filter_button = $(this); | |
| 275 | - $( '#visualizer-db-query' ).css("z-index", "-1").hide(); | |
| 276 | - $('#canvas').lock(); | |
| 277 | - filter_button.val( filter_button.attr( 'data-t-chart' ) ); | |
| 278 | - filter_button.html( filter_button.attr( 'data-t-chart' ) ); | |
| 279 | - filter_button.attr( 'data-current', 'chart' ); | |
| 280 | - $( '#canvas' ).css("z-index", "1").show(); | |
| 281 | - $( '#db-chart-save-button' ).trigger('click'); | |
| 282 | - } | |
| 283 | - } ); | |
| 284 | - | |
| 285 | - $( '#db-chart-save-button' ).on( 'click', function(){ | |
| 286 | - $('#viz-db-wizard-params').val($('#db-query-form').serialize()); | |
| 287 | - $('#vz-db-wizard').submit(); | |
| 288 | - }); | |
| 289 | - } | |
| 290 | - | |
| 291 | - function start_ajax(element){ | |
| 292 | - element.lock(); | |
| 293 | - } | |
| 294 | - | |
| 295 | - function end_ajax(element){ | |
| 296 | - element.unlock(); | |
| 297 | - } | |
| 298 | - | |
| 299 | 73 | })(jQuery); |
| 300 | 74 | |
| 301 | 75 | (function ($) { |
| 302 | 76 | $.fn.lock = function () { |