| 1 |
(function($) { |
| 2 |
'use strict'; |
| 3 |
function AysChartBuilder(element, options){ |
| 4 |
this.el = element; |
| 5 |
this.$el = $(element); |
| 6 |
this.ajaxAction = 'ays_chart_admin_ajax'; |
| 7 |
this.htmlClassPrefix = 'ays-chart-'; |
| 8 |
this.htmlNamePrefix = 'ays_'; |
| 9 |
this.dbOptions = undefined; |
| 10 |
this.chartSourceData = undefined; |
| 11 |
this.chartObj = undefined; |
| 12 |
this.chartOptions = null; |
| 13 |
this.chartData = null; |
| 14 |
this.chartTempData = null; |
| 15 |
|
| 16 |
this.chartSources = { |
| 17 |
'bar_chart' : 'Bar Chart', |
| 18 |
'pie_chart' : 'Pie Chart', |
| 19 |
'column_chart' : 'Column Chart' |
| 20 |
} |
| 21 |
|
| 22 |
this.init(); |
| 23 |
|
| 24 |
return this; |
| 25 |
} |
| 26 |
|
| 27 |
AysChartBuilder.prototype.init = function() { |
| 28 |
var _this = this; |
| 29 |
_this.chartSourceData = window.ChartBuilderSourceData; |
| 30 |
_this.setEvents(); |
| 31 |
_this.initLibraries(); |
| 32 |
_this.setAccordionEvents(); |
| 33 |
|
| 34 |
}; |
| 35 |
|
| 36 |
// Set events |
| 37 |
AysChartBuilder.prototype.setEvents = function(e){ |
| 38 |
var _this = this; |
| 39 |
/* == Choose poll type from modal == */ |
| 40 |
_this.$el.on('dblclick' , '.'+_this.htmlClassPrefix+'layer_box_blocks label.'+_this.htmlClassPrefix+'dblclick-layer:not(.'+_this.htmlClassPrefix+'type-pro-feature)', function(){ |
| 41 |
_this.$el.find('.'+_this.htmlClassPrefix+'select_button_layer input.'+_this.htmlClassPrefix+'layer_button').trigger('click'); |
| 42 |
}); |
| 43 |
|
| 44 |
_this.$el.on('change' , '.'+_this.htmlClassPrefix+'choose-source', function(){ |
| 45 |
_this.$el.find('.'+_this.htmlClassPrefix+'select_button_layer input.'+_this.htmlClassPrefix+'layer_button').prop('disabled',false).attr("data-type" , $(this).val()); |
| 46 |
// _this.$el.find('#poll_choose_type').val($(this).val()); |
| 47 |
}); |
| 48 |
|
| 49 |
_this.$el.on('click', '.'+_this.htmlClassPrefix+'layer_button' ,function(){ |
| 50 |
var getCheckedChartTpye = _this.$el.find('.'+_this.htmlClassPrefix+'choose-source:checked').val(); |
| 51 |
_this.$el.find('.'+_this.htmlClassPrefix+'layer_container').css({'position':'unset' , 'display':'none'}); |
| 52 |
_this.$el.find('.'+_this.htmlClassPrefix+'type-info-box-text-changeable').text(_this.chartSources[getCheckedChartTpye]); |
| 53 |
_this.$el.find('#'+_this.htmlClassPrefix+'option-chart-type').val(getCheckedChartTpye); |
| 54 |
_this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').attr('id' , _this.htmlClassPrefix+getCheckedChartTpye); |
| 55 |
_this.loadChartBySource( getCheckedChartTpye ); |
| 56 |
}); |
| 57 |
/* */ |
| 58 |
|
| 59 |
/* == Tabulation == */ |
| 60 |
_this.$el.on('click', '.nav-tab-wrapper a.nav-tab' , _this.changeTabs); |
| 61 |
/* */ |
| 62 |
|
| 63 |
// /* == Range slider functions == */ |
| 64 |
// _this.$el.on('input', '#ays-chart-option-font-size', _this.rangeSliderChange); |
| 65 |
// _this.$el.on('mouseenter', '#ays-chart-option-font-size', function(e) { |
| 66 |
// $('#ays-chart-range-value').show(); |
| 67 |
// }); |
| 68 |
// _this.$el.on('mouseleave', '#ays-chart-option-font-size', function(e) { |
| 69 |
// $('#ays-chart-range-value').hide(); |
| 70 |
// }); |
| 71 |
// /* */ |
| 72 |
|
| 73 |
/* == Notifications dismiss button == */ |
| 74 |
_this.$el.on('click', '.notice-dismiss', function (e) { |
| 75 |
_this.changeCurrentUrl('status'); |
| 76 |
}); |
| 77 |
|
| 78 |
_this.$el.on('click', '.toggle_ddmenu' , _this.toggleDDmenu); |
| 79 |
/* */ |
| 80 |
|
| 81 |
/* Add Manual data */ |
| 82 |
_this.$el.on("click" , '.'+_this.htmlClassPrefix+'add-new-row-box', function(){ |
| 83 |
_this.addChartDataRow(); |
| 84 |
}); |
| 85 |
|
| 86 |
_this.$el.on("click" , '.'+_this.htmlClassPrefix+'add-new-column-box', function(){ |
| 87 |
_this.addLineChartDataColumn(); |
| 88 |
}); |
| 89 |
|
| 90 |
_this.$el.on('click', '.'+_this.htmlClassPrefix+'show-on-chart-bttn', function(e){ |
| 91 |
var loadedChartType = _this.$el.find('.'+_this.htmlClassPrefix+'choose-source:checked').val(); |
| 92 |
var chartType = (loadedChartType === undefined) ? _this.chartSourceData.chartType : loadedChartType; |
| 93 |
e.preventDefault(); |
| 94 |
_this.showOnChart($(this), chartType); |
| 95 |
}); |
| 96 |
|
| 97 |
/* */ |
| 98 |
|
| 99 |
/* Delete data */ |
| 100 |
_this.$el.on("click" , '.'+_this.htmlClassPrefix+'chart-source-data-remove-block', function(){ |
| 101 |
_this.deleteChartDataRow($(this)); |
| 102 |
}); |
| 103 |
_this.$el.on('mouseenter', '.'+_this.htmlClassPrefix+'chart-source-data-remove-block', function() { |
| 104 |
$(this).find('path').css('fill', '#ff0000'); |
| 105 |
}); |
| 106 |
_this.$el.on('mouseleave', '.'+_this.htmlClassPrefix+'chart-source-data-remove-block', function() { |
| 107 |
$(this).find('path').css('fill', '#b8b8b8'); |
| 108 |
}); |
| 109 |
/* */ |
| 110 |
|
| 111 |
/* Load data on the edit page */ |
| 112 |
if(_this.chartSourceData.action == 'edit'){ |
| 113 |
_this.loadChartBySource( _this.chartSourceData.chartType ); |
| 114 |
} |
| 115 |
/* */ |
| 116 |
|
| 117 |
/* Save with Ctrl + S */ |
| 118 |
_this.$el.on('keydown', $(document), _this.quickSaveHotKeys); |
| 119 |
/* */ |
| 120 |
|
| 121 |
// Submit buttons disabling |
| 122 |
_this.$el.on('click', '.'+_this.htmlClassPrefix+'loader-banner', _this.submitOnce); |
| 123 |
/* */ |
| 124 |
|
| 125 |
// Disabling submit when press enter button on inputing |
| 126 |
$(document).on("keypress", '.ays-text-input', _this.disableSubmit); |
| 127 |
/* */ |
| 128 |
|
| 129 |
// Modal close |
| 130 |
$(document).on('click', '.ays-close', function () { |
| 131 |
$(this).parents('.ays-modal').aysModal('hide'); |
| 132 |
}); |
| 133 |
} |
| 134 |
|
| 135 |
// Disabling submit when pressing enter button on input |
| 136 |
AysChartBuilder.prototype.disableSubmit = function(e){ |
| 137 |
if(e.which == 13){ |
| 138 |
if($(document).find("#ays-charts-form").length !== 0 || $(document).find("#ays-settings-form").length !== 0){ |
| 139 |
return false; |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
// Change tabs (tabulation) |
| 145 |
AysChartBuilder.prototype.changeTabs = function(e){ |
| 146 |
if(! $(this).hasClass('no-js')){ |
| 147 |
var elemenetID = $(this).attr('href'); |
| 148 |
var active_tab = $(this).attr('data-tab'); |
| 149 |
$(document).find('.nav-tab-wrapper a.nav-tab').each(function () { |
| 150 |
if ($(this).hasClass('nav-tab-active')) { |
| 151 |
$(this).removeClass('nav-tab-active'); |
| 152 |
} |
| 153 |
}); |
| 154 |
$(this).addClass('nav-tab-active'); |
| 155 |
$(document).find('.ays-tab-content').each(function () { |
| 156 |
$(this).css('display', 'none'); |
| 157 |
}); |
| 158 |
$(document).find("[name='ays_form_tab']").val(active_tab); |
| 159 |
$('.ays-tab-content' + elemenetID).css('display', 'block'); |
| 160 |
e.preventDefault(); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
// AysChartBuilder.prototype.rangeSliderChange = function(e){ |
| 165 |
// var min = e.target.min; |
| 166 |
// var max = e.target.max; |
| 167 |
// var val = e.target.value; |
| 168 |
// var width = $('#ays-chart-option-font-size').width(); |
| 169 |
|
| 170 |
// $(e.target).css('backgroundSize', (val - min) / (max - min) * 100 + '% 100%'); |
| 171 |
|
| 172 |
// $('#ays-chart-range-value').css('left', 12.8 + (val - min) / (max - min + 1) * width + 'px'); |
| 173 |
// $('#ays-chart-range-value span').html(val); |
| 174 |
// } |
| 175 |
|
| 176 |
AysChartBuilder.prototype.changeCurrentUrl = function(e){ |
| 177 |
var linkModified = location.href.split('?')[1].split('&'); |
| 178 |
for(var i = 0; i < linkModified.length; i++){ |
| 179 |
if(linkModified[i].split("=")[0] == key){ |
| 180 |
linkModified.splice(i, 1); |
| 181 |
} |
| 182 |
} |
| 183 |
linkModified = linkModified.join('&'); |
| 184 |
window.history.replaceState({}, document.title, '?'+linkModified); |
| 185 |
} |
| 186 |
|
| 187 |
AysChartBuilder.prototype.toggleDDmenu = function(e){ |
| 188 |
var ddmenu = $(this).next(); |
| 189 |
var state = ddmenu.attr('data-expanded'); |
| 190 |
switch (state) { |
| 191 |
case 'true': |
| 192 |
$(this).find('.ays_fa').css({ |
| 193 |
transform: 'rotate(0deg)' |
| 194 |
}); |
| 195 |
ddmenu.attr('data-expanded', 'false'); |
| 196 |
break; |
| 197 |
case 'false': |
| 198 |
$(this).find('.ays_fa').css({ |
| 199 |
transform: 'rotate(90deg)' |
| 200 |
}); |
| 201 |
ddmenu.attr('data-expanded', 'true'); |
| 202 |
break; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
AysChartBuilder.prototype.submitOnce = function(el) { |
| 207 |
setTimeout(function() { |
| 208 |
$(document).find('.ays-chart-loader-banner').attr('disabled', true); |
| 209 |
}, 50); |
| 210 |
|
| 211 |
setTimeout(function() { |
| 212 |
$(document).find('.ays-chart-loader-banner').attr('disabled', false); |
| 213 |
}, 5000); |
| 214 |
} |
| 215 |
|
| 216 |
// Load charts by given type main function |
| 217 |
AysChartBuilder.prototype.initLibraries = function (){ |
| 218 |
var _this = this; |
| 219 |
|
| 220 |
} |
| 221 |
|
| 222 |
// Load charts by given type main function |
| 223 |
AysChartBuilder.prototype.loadChartBySource = function( chartType ){ |
| 224 |
var _this = this; |
| 225 |
|
| 226 |
if( ! chartType ){ |
| 227 |
chartType = _this.chartSourceData.chartType; |
| 228 |
} |
| 229 |
|
| 230 |
if(typeof chartType !== undefined && chartType){ |
| 231 |
switch (chartType) { |
| 232 |
case 'pie_chart': |
| 233 |
_this.pieChartView( chartType ); |
| 234 |
break; |
| 235 |
case 'bar_chart': |
| 236 |
_this.barChartView( chartType ); |
| 237 |
break; |
| 238 |
case 'column_chart': |
| 239 |
_this.columnChartView( chartType ); |
| 240 |
break; |
| 241 |
default: |
| 242 |
_this.pieChartView( chartType ); |
| 243 |
break; |
| 244 |
} |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
// Load chart by pie chart |
| 249 |
AysChartBuilder.prototype.pieChartView = function( chartType ){ |
| 250 |
var _this = this; |
| 251 |
var getChartSource = _this.chartSourceData.source; |
| 252 |
|
| 253 |
var dataTypes = _this.chartConvertData( getChartSource ); |
| 254 |
|
| 255 |
var settings = _this.chartSourceData.settings; |
| 256 |
var chartFontSize = settings['font_size']; |
| 257 |
var tooltipTrigger = settings['tooltip_trigger']; |
| 258 |
var showColorCode = (settings['show_color_code'] == 'checked') ? true : false; |
| 259 |
|
| 260 |
/* == Google part == */ |
| 261 |
google.charts.load('current', {'packages':['corechart']}); |
| 262 |
google.charts.setOnLoadCallback(drawChart); |
| 263 |
|
| 264 |
function drawChart() { |
| 265 |
_this.chartData = google.visualization.arrayToDataTable( dataTypes ); |
| 266 |
|
| 267 |
_this.chartOptions = { |
| 268 |
backgroundColor: 'transparent', |
| 269 |
fontSize: chartFontSize, |
| 270 |
tooltip: { |
| 271 |
trigger: tooltipTrigger, |
| 272 |
showColorCode: showColorCode |
| 273 |
} |
| 274 |
}; |
| 275 |
|
| 276 |
// height: 250, |
| 277 |
// chartArea: { |
| 278 |
// width: '80%', |
| 279 |
// height: '80%' |
| 280 |
// }, |
| 281 |
|
| 282 |
_this.chartObj = new google.visualization.PieChart( document.getElementById(_this.htmlClassPrefix + chartType) ); |
| 283 |
|
| 284 |
_this.chartObj.draw( _this.chartData, _this.chartOptions ); |
| 285 |
_this.resizeChart(); |
| 286 |
} |
| 287 |
/* */ |
| 288 |
} |
| 289 |
|
| 290 |
// Load chart by bar chart |
| 291 |
AysChartBuilder.prototype.barChartView = function( chartType ){ |
| 292 |
var _this = this; |
| 293 |
var getChartSource = _this.chartSourceData.source; |
| 294 |
var dataTypes = _this.chartConvertData( getChartSource ); |
| 295 |
|
| 296 |
var settings = _this.chartSourceData.settings; |
| 297 |
var chartFontSize = settings['font_size']; |
| 298 |
var tooltipTrigger = settings['tooltip_trigger']; |
| 299 |
var showColorCode = (settings['show_color_code'] == 'checked') ? true : false; |
| 300 |
|
| 301 |
/* == Google part == */ |
| 302 |
google.charts.load('current', {'packages':['corechart']}); |
| 303 |
google.charts.setOnLoadCallback(drawChart); |
| 304 |
|
| 305 |
function drawChart() { |
| 306 |
_this.chartData = google.visualization.arrayToDataTable(dataTypes); |
| 307 |
|
| 308 |
_this.chartOptions = { |
| 309 |
backgroundColor: 'transparent', |
| 310 |
fontSize: chartFontSize, |
| 311 |
legend: { position: 'none' }, |
| 312 |
tooltip: { |
| 313 |
trigger: tooltipTrigger, |
| 314 |
showColorCode: showColorCode |
| 315 |
} |
| 316 |
}; |
| 317 |
|
| 318 |
_this.chartObj = new google.visualization.BarChart(document.getElementById(_this.htmlClassPrefix + chartType)); |
| 319 |
|
| 320 |
_this.chartObj.draw( _this.chartData, _this.chartOptions ); |
| 321 |
_this.resizeChart(); |
| 322 |
} |
| 323 |
/* */ |
| 324 |
} |
| 325 |
|
| 326 |
// Load chart by column chart |
| 327 |
AysChartBuilder.prototype.columnChartView = function( chartType ){ |
| 328 |
var _this = this; |
| 329 |
var getChartSource = _this.chartSourceData.source; |
| 330 |
|
| 331 |
var dataTypes = _this.chartConvertData( getChartSource ); |
| 332 |
|
| 333 |
var settings = _this.chartSourceData.settings; |
| 334 |
var chartFontSize = settings['font_size']; |
| 335 |
var tooltipTrigger = settings['tooltip_trigger']; |
| 336 |
var showColorCode = (settings['show_color_code'] == 'checked') ? true : false; |
| 337 |
|
| 338 |
// Collect data in new array for chart rendering (Column chart) |
| 339 |
|
| 340 |
/* == Google part == */ |
| 341 |
google.charts.load('current', {'packages':['corechart']}); |
| 342 |
google.charts.setOnLoadCallback(drawChart); |
| 343 |
|
| 344 |
function drawChart() { |
| 345 |
_this.chartData = google.visualization.arrayToDataTable(dataTypes); |
| 346 |
|
| 347 |
_this.chartOptions = { |
| 348 |
backgroundColor: 'transparent', |
| 349 |
fontSize: chartFontSize, |
| 350 |
legend: { position: 'none' }, |
| 351 |
tooltip: { |
| 352 |
trigger: tooltipTrigger, |
| 353 |
showColorCode: showColorCode |
| 354 |
} |
| 355 |
}; |
| 356 |
|
| 357 |
_this.chartObj = new google.visualization.ColumnChart(document.getElementById(_this.htmlClassPrefix + chartType)); |
| 358 |
|
| 359 |
_this.chartObj.draw( _this.chartData, _this.chartOptions ); |
| 360 |
_this.resizeChart(); |
| 361 |
} |
| 362 |
/* */ |
| 363 |
} |
| 364 |
|
| 365 |
// Detect window resize moment to draw charts responsively |
| 366 |
AysChartBuilder.prototype.resizeChart = function(){ |
| 367 |
var _this = this; |
| 368 |
|
| 369 |
//create trigger to resizeEnd event |
| 370 |
$(window).resize(function() { |
| 371 |
if(this.resizeTO) clearTimeout(this.resizeTO); |
| 372 |
this.resizeTO = setTimeout(function() { |
| 373 |
$(this).trigger('resizeEnd'); |
| 374 |
}, 100); |
| 375 |
}); |
| 376 |
|
| 377 |
//redraw graph when window resize is completed |
| 378 |
$(window).on('resizeEnd', function() { |
| 379 |
_this.chartObj.draw( _this.chartData, _this.chartOptions ); |
| 380 |
}); |
| 381 |
|
| 382 |
} |
| 383 |
|
| 384 |
// Load chart by pie chart |
| 385 |
AysChartBuilder.prototype.chartConvertData = function( data ){ |
| 386 |
var _this = this; |
| 387 |
// var dataTypes = [['Option', 'Value', { role: 'style' }]]; |
| 388 |
var dataTypes = [['Option', 'Value']]; |
| 389 |
|
| 390 |
// var defaultColors = _this.chartSourceData.settings['colors']; |
| 391 |
|
| 392 |
// Collect data in new array for chart rendering |
| 393 |
for ( var key in data ) { |
| 394 |
if ( data.hasOwnProperty( key ) ) { |
| 395 |
// var columnColor = (key <= 10) ? defaultColors[key] : Math.floor( Math.random() * 16777215 ).toString(16); |
| 396 |
dataTypes.push([ |
| 397 |
data[key][0], +(data[key][1]) |
| 398 |
]); |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
return dataTypes; |
| 403 |
} |
| 404 |
|
| 405 |
// Update chart data and display immediately |
| 406 |
AysChartBuilder.prototype.updateChartData = function( newData ){ |
| 407 |
var _this = this; |
| 408 |
_this.chartObj.draw( newData, _this.chartOptions ); |
| 409 |
} |
| 410 |
|
| 411 |
AysChartBuilder.prototype.addChartDataRow = function (element){ |
| 412 |
// var deleteImageUrl = ChartBuilderSourceData.removeManualDataRow; |
| 413 |
var content = ''; |
| 414 |
|
| 415 |
var addedTermsandConds = this.$el.find("."+this.htmlClassPrefix+"chart-source-data-edit-block"); |
| 416 |
var addedTermsandCondsId = this.$el.find("."+this.htmlClassPrefix+"chart-source-data-edit-block:last-child"); |
| 417 |
var dataId = addedTermsandConds.length >= 1 ? addedTermsandCondsId.data("sourceId") + 1 : 1; |
| 418 |
var colCount = addedTermsandConds.first().children().length - 1; |
| 419 |
|
| 420 |
var termsCondsMessageAttrName = this.newTermsCondsMessageAttrName( this.htmlNamePrefix + 'chart_source_data' , dataId ); |
| 421 |
|
| 422 |
// content += '<div class = "'+this.htmlClassPrefix+'chart-source-data-edit-block" data-source-id="' + dataId + '">'; |
| 423 |
// content += '<div class="'+this.htmlClassPrefix+'chart-source-data-input-box">'; |
| 424 |
// content += '<input type="text" class="ays-text-input form-control" name="' + termsCondsMessageAttrName + '">'; |
| 425 |
// content += '</div>'; |
| 426 |
// content += '<div class="'+this.htmlClassPrefix+'chart-source-data-input-box">'; |
| 427 |
// content += '<input type="text" class="ays-text-input form-control" name="' + termsCondsMessageAttrName + '">'; |
| 428 |
// content += '</div>'; |
| 429 |
// content += '<div class="'+this.htmlClassPrefix+'icons-box '+this.htmlClassPrefix+'icons-remove-box">'; |
| 430 |
// content += '<img class="'+this.htmlClassPrefix+'chart-source-data-remove-block" src="' + deleteImageUrl + '">'; |
| 431 |
// content += '</div>'; |
| 432 |
// content += '</div>'; |
| 433 |
|
| 434 |
content += '<div class = "'+this.htmlClassPrefix+'chart-source-data-edit-block" data-source-id="' + dataId + '" >'; |
| 435 |
content += '<div class="'+this.htmlClassPrefix+'icons-box '+this.htmlClassPrefix+'icons-remove-box">'; |
| 436 |
content += '<svg class="'+this.htmlClassPrefix+'chart-source-data-remove-block" data-trigger="hover" data-toggle="tooltip" title="Delete row" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M310.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L160 210.7 54.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L114.7 256 9.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 301.3 265.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L205.3 256 310.6 150.6z" style="fill: #b8b8b8;"/></svg>'; |
| 437 |
content += '</div>'; |
| 438 |
for (var i = 0; i < colCount; i++) { |
| 439 |
if (i == 0) { |
| 440 |
content += '<div class="'+this.htmlClassPrefix+'chart-source-data-input-box">'; |
| 441 |
content += '<input type="text" class="ays-text-input form-control" name="' + termsCondsMessageAttrName + '">'; |
| 442 |
content += '</div>'; |
| 443 |
} else { |
| 444 |
content += '<div class="'+this.htmlClassPrefix+'chart-source-data-input-box '+this.htmlClassPrefix+'chart-source-data-input-number">'; |
| 445 |
content += '<input type="number" class="ays-text-input form-control" name="' + termsCondsMessageAttrName + '">'; |
| 446 |
content += '</div>'; |
| 447 |
} |
| 448 |
} |
| 449 |
content += '</div>'; |
| 450 |
|
| 451 |
|
| 452 |
this.$el.find('.'+this.htmlClassPrefix+'chart-source-data-content').append(content); |
| 453 |
} |
| 454 |
|
| 455 |
AysChartBuilder.prototype.deleteChartDataRow = function (element){ |
| 456 |
var $this = element; |
| 457 |
var $thisMainParent = $this.parent().parent(); |
| 458 |
$this.tooltip('hide'); |
| 459 |
$thisMainParent.remove(); |
| 460 |
} |
| 461 |
|
| 462 |
AysChartBuilder.prototype.newTermsCondsMessageAttrName = function (termCondName, termCondId){ |
| 463 |
var _this = this; |
| 464 |
return termCondName + '['+ termCondId +'][]'; |
| 465 |
} |
| 466 |
|
| 467 |
AysChartBuilder.prototype.setAccordionEvents = function(e){ |
| 468 |
var _this = this; |
| 469 |
_this.$el.on('click', '.ays-accordion-options-header', function(e){ |
| 470 |
_this.openCloseAccordion(e, _this); |
| 471 |
}); |
| 472 |
} |
| 473 |
|
| 474 |
AysChartBuilder.prototype.openCloseAccordion = function(e, _this){ |
| 475 |
|
| 476 |
var container = $(e.target).parents('.ays-accordion-options-container'); |
| 477 |
|
| 478 |
if( container.attr('data-collapsed') === 'true' ){ |
| 479 |
_this.closeAllAccordions( container.parents('.ays-tab-content').attr('id') ); |
| 480 |
// container.find('.ays-accordion-options-content').removeClass('display_none'); |
| 481 |
container.attr('data-collapsed', 'false'); |
| 482 |
container.find('.ays-accordion-options-header .ays-accordion-arrow').removeClass('ays-accordion-arrow-right').addClass('ays-accordion-arrow-down'); |
| 483 |
}else{ |
| 484 |
// container.find('.ays-accordion-options-content').addClass('display_none'); |
| 485 |
container.attr('data-collapsed', 'true'); |
| 486 |
container.find('.ays-accordion-options-header .ays-accordion-arrow').removeClass('ays-accordion-arrow-down').addClass('ays-accordion-arrow-right'); |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
AysChartBuilder.prototype.closeAllAccordions = function( tab ){ |
| 491 |
var _this = this; |
| 492 |
var container = _this.$el.find('#' + tab + ' .ays-accordions-container'); |
| 493 |
|
| 494 |
container.find('.ays-accordion-options-container').each(function (){ |
| 495 |
$(this).attr('data-collapsed', 'true'); |
| 496 |
$(this).find('.ays-accordion-options-header .ays-accordion-arrow').removeClass('ays-accordion-arrow-down').addClass('ays-accordion-arrow-right'); |
| 497 |
}); |
| 498 |
} |
| 499 |
|
| 500 |
AysChartBuilder.prototype.startAjax = function( element ){ |
| 501 |
element.lock(); |
| 502 |
} |
| 503 |
|
| 504 |
AysChartBuilder.prototype.endAjax = function( element ){ |
| 505 |
element.unlock(); |
| 506 |
} |
| 507 |
|
| 508 |
AysChartBuilder.prototype.quickSaveHotKeys = function() { |
| 509 |
$(document).on('keydown', function(e){ |
| 510 |
var saveButton = $(document).find('input#ays-button-apply'); |
| 511 |
if ( saveButton.length > 0 ) { |
| 512 |
if (!(e.which == 83 && e.ctrlKey) && !(e.which == 19)){ |
| 513 |
return true; |
| 514 |
} |
| 515 |
saveButton.trigger("click"); |
| 516 |
e.preventDefault(); |
| 517 |
return false; |
| 518 |
} |
| 519 |
}); |
| 520 |
} |
| 521 |
|
| 522 |
// Manual data show on chart button |
| 523 |
AysChartBuilder.prototype.showOnChart = function (button, chartType) { |
| 524 |
var _this = this; |
| 525 |
|
| 526 |
var form = $(document).find("#ays-charts-form"); |
| 527 |
var data = form.serializeFormJSON(); |
| 528 |
// var count = $(document).find(".ays-chart-chart-source-data-edit-block").length; |
| 529 |
var lastId = $(document).find(".ays-chart-chart-source-data-edit-block:last-child").attr('data-source-id'); |
| 530 |
var chartData = []; |
| 531 |
for (var i = 0; i <= lastId; i++) { |
| 532 |
if (data['ays_chart_source_data['+i+'][]'] != undefined) { |
| 533 |
chartData.push(data['ays_chart_source_data['+i+'][]']); |
| 534 |
} |
| 535 |
} |
| 536 |
chartData = _this.chartConvertData( chartData ); |
| 537 |
|
| 538 |
chartData = window.google.visualization.arrayToDataTable( chartData ); |
| 539 |
|
| 540 |
_this.updateChartData( chartData ); |
| 541 |
|
| 542 |
chartData = null; |
| 543 |
} |
| 544 |
|
| 545 |
$.fn.AysChartBuilderMain = function(options) { |
| 546 |
return this.each(function() { |
| 547 |
if (!$.data(this, 'AysChartBuilderMain')) { |
| 548 |
$.data(this, 'AysChartBuilderMain', new AysChartBuilder(this, options)); |
| 549 |
} else { |
| 550 |
try { |
| 551 |
$(this).data('AysChartBuilderMain').init(); |
| 552 |
} catch (err) { |
| 553 |
console.error('AysChartBuilderMain has not initiated properly'); |
| 554 |
} |
| 555 |
} |
| 556 |
}); |
| 557 |
}; |
| 558 |
$(document).find('#ays-charts-form').AysChartBuilderMain(); |
| 559 |
|
| 560 |
})(jQuery); |
| 561 |
|
| 562 |
(function ($) { |
| 563 |
|
| 564 |
$.fn.serializeFormJSON = function () { |
| 565 |
let o = {}, |
| 566 |
a = this.serializeArray(); |
| 567 |
$.each(a, function () { |
| 568 |
if (o[this.name]) { |
| 569 |
if (!o[this.name].push) { |
| 570 |
o[this.name] = [o[this.name]]; |
| 571 |
} |
| 572 |
o[this.name].push(this.value || ''); |
| 573 |
} else { |
| 574 |
o[this.name] = this.value || ''; |
| 575 |
} |
| 576 |
}); |
| 577 |
return o; |
| 578 |
}; |
| 579 |
|
| 580 |
$.fn.lock = function () { |
| 581 |
$(this).each(function () { |
| 582 |
var $this = $(this); |
| 583 |
var position = $this.css('position'); |
| 584 |
|
| 585 |
if (!position) { |
| 586 |
position = 'static'; |
| 587 |
} |
| 588 |
|
| 589 |
switch (position) { |
| 590 |
case 'absolute': |
| 591 |
case 'relative': |
| 592 |
break; |
| 593 |
default: |
| 594 |
$this.css('position', 'relative'); |
| 595 |
break; |
| 596 |
} |
| 597 |
$this.data('position', position); |
| 598 |
|
| 599 |
var width = $this.width(), |
| 600 |
height = $this.height(); |
| 601 |
|
| 602 |
var locker = $('<div class="locker"></div>'); |
| 603 |
locker.width(width).height(height); |
| 604 |
|
| 605 |
var loader = $('<div class="locker-loader"></div>'); |
| 606 |
loader.width(width).height(height); |
| 607 |
|
| 608 |
locker.append(loader); |
| 609 |
$this.append(locker); |
| 610 |
$(window).resize(function () { |
| 611 |
$this.find('.locker,.locker-loader').width($this.width()).height($this.height()); |
| 612 |
}); |
| 613 |
}); |
| 614 |
|
| 615 |
return $(this); |
| 616 |
}; |
| 617 |
|
| 618 |
$.fn.unlock = function () { |
| 619 |
$(this).each(function () { |
| 620 |
$(this).find('.locker').remove(); |
| 621 |
$(this).css('position', $(this).data('position')); |
| 622 |
}); |
| 623 |
|
| 624 |
return $(this); |
| 625 |
}; |
| 626 |
})(jQuery); |