| 1 |
/* global charitable_reporting, wpchar, wpCookies */ |
| 2 |
// eslint-disable-line no-unused-vars |
| 3 |
|
| 4 |
var CharitableAdminReporting = window.CharitableAdminReporting || (function (document, window, $) { |
| 5 |
|
| 6 |
var s = {}, |
| 7 |
$reports, |
| 8 |
showGrowthToolsNotice = false, |
| 9 |
elements = {}, |
| 10 |
charts = {}; |
| 11 |
|
| 12 |
var app = { |
| 13 |
|
| 14 |
settings: { |
| 15 |
clickWatch: false |
| 16 |
}, |
| 17 |
|
| 18 |
/** |
| 19 |
* Start the engine. |
| 20 |
* |
| 21 |
* @since 1.8.1 |
| 22 |
*/ |
| 23 |
init: function () { |
| 24 |
|
| 25 |
s = this.settings; |
| 26 |
|
| 27 |
// Document ready. |
| 28 |
$(app.ready); |
| 29 |
|
| 30 |
}, |
| 31 |
|
| 32 |
/** |
| 33 |
* Document ready. |
| 34 |
* |
| 35 |
* @since 1.8.1 |
| 36 |
* |
| 37 |
*/ |
| 38 |
ready: function () { // check to see if javascript has been defined. |
| 39 |
|
| 40 |
// check to see if charitable_reporting has been defined. |
| 41 |
if ( typeof charitable_reporting === 'undefined' ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
wpchar.debug('charitable_reporting'); |
| 46 |
wpchar.debug(charitable_reporting); |
| 47 |
|
| 48 |
$reports = $('#charitable-reports'); |
| 49 |
|
| 50 |
if ( $reports.length === 0 ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
// UI elements. |
| 55 |
elements.$start_datepicker = $( '#charitable-reports-start_date' ); |
| 56 |
elements.$end_datepicker = $( '#charitable-reports-end_date' ); |
| 57 |
elements.$filter_button = $( '#charitable-reports-filter-button'); |
| 58 |
elements.$report_campaign_filter = $('#report-campaign-filter'); |
| 59 |
elements.$report_category_filter = $('#report-category-filter'); |
| 60 |
|
| 61 |
// Data containers. |
| 62 |
elements.$top_donation_amount = $('#charitable-top-donation-total-amount'); |
| 63 |
elements.$top_donation_count = $('#charitable-top-donation-total-count'); |
| 64 |
elements.$top_donation_average = $('#charitable-top-donation-average'); |
| 65 |
elements.$top_donation_donors_count = $('#charitable-top-donor-count'); |
| 66 |
elements.$top_charitable_refund_total_amount = $('#charitable-top-refund-total-amount'); |
| 67 |
elements.$top_charitable_refund_count = $('#charitable-top-refund-count'); |
| 68 |
elements.$top_donors_list = $('#charitable-top-donors-list'); |
| 69 |
elements.$donations_breakdown_list = $('#donations-breakdown-list'); |
| 70 |
elements.$payment_methods_list = $('ul#charitable-payment-methods-list'); |
| 71 |
elements.$activity_list = $('#charitable-activity-list'); |
| 72 |
elements.$top_campaigns_list = $('#charitable-top-campaigns-list'); |
| 73 |
elements.$report_date_range_filter = $('#report-date-range-filter'); |
| 74 |
elements.$topnav_datepicker = $('#charitable-reports-topnav-datepicker'); |
| 75 |
elements.$topnav_datepicker_comparefrom = $('#charitable-reports-topnav-datepicker-comparefrom-lybunt'); |
| 76 |
elements.$topnav_datepicker_compareto = $('#charitable-reports-topnav-datepicker-compareto-lybunt'); |
| 77 |
|
| 78 |
s.datePickerStartDate = ''; |
| 79 |
s.datePickerEndDate = ''; |
| 80 |
|
| 81 |
s.datePickerCompareFromStartDate = ''; |
| 82 |
s.datePickerCompareFromEndDate = ''; |
| 83 |
s.datePickerCompareToStartDate = ''; |
| 84 |
s.datePickerCompareToEndDate = ''; |
| 85 |
|
| 86 |
|
| 87 |
if ( app.isAdvancedPage() ) { |
| 88 |
app.initDatePickerRanges( 'ranged' ); |
| 89 |
} else { |
| 90 |
app.initDatePickerRanges( '' ); |
| 91 |
} |
| 92 |
|
| 93 |
app.initDatePicker(); |
| 94 |
|
| 95 |
// Bind all actions. |
| 96 |
app.bindUIActions(); |
| 97 |
|
| 98 |
app.initCharts(); |
| 99 |
app.renderCharts(); |
| 100 |
|
| 101 |
app.checkCategoryDropdown(); |
| 102 |
|
| 103 |
app.updateDatePickerVars(); |
| 104 |
|
| 105 |
app.initPagination(); |
| 106 |
|
| 107 |
}, |
| 108 |
|
| 109 |
/** |
| 110 |
* Updates the datepicker vars. |
| 111 |
* |
| 112 |
* @since 1.8.1 |
| 113 |
* |
| 114 |
*/ |
| 115 |
updateDatePickerVars: function () { |
| 116 |
|
| 117 |
if ( $reports.find('input.charitable-datepicker-ranged').length === 0 ) { |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
var drp = $reports.find('input.charitable-datepicker-ranged').data('daterangepicker'); |
| 122 |
|
| 123 |
s.datePickerStartDate = ( drp.startDate._i ) ? drp.startDate._i : ''; |
| 124 |
s.datePickerEndDate = ( drp.endDate._i ) ? drp.endDate._i : ''; |
| 125 |
|
| 126 |
}, |
| 127 |
|
| 128 |
/** |
| 129 |
* Checks to see if the category dropdown should be enabled on the page (overview). |
| 130 |
* |
| 131 |
* @since 1.8.1 |
| 132 |
* |
| 133 |
*/ |
| 134 |
checkCategoryDropdown: function () { |
| 135 |
|
| 136 |
if ( elements.$report_campaign_filter.val() === '-1' ) { |
| 137 |
elements.$report_category_filter.removeClass('charitable-disabled'); |
| 138 |
} else { |
| 139 |
elements.$report_category_filter.val('-1').addClass('charitable-disabled'); |
| 140 |
} |
| 141 |
|
| 142 |
}, |
| 143 |
|
| 144 |
/** |
| 145 |
* Inits the date picker ranges, for when that UI needs to be initialized. |
| 146 |
* |
| 147 |
* @since 1.8.1 |
| 148 |
* |
| 149 |
*/ |
| 150 |
initDatePickerRanges: function ( pickerType = 'ranged' ) { |
| 151 |
|
| 152 |
// Determine args for datepickers on various report pages. |
| 153 |
if ( pickerType === 'ranged' ) { |
| 154 |
|
| 155 |
// if moment is defined, use it to set the datepicker ranges. |
| 156 |
if ( typeof moment !== 'undefined' ) { |
| 157 |
|
| 158 |
s.ranges = { |
| 159 |
'This Year': [ |
| 160 |
moment().startOf('year'), moment().endOf('year') // eslint-disable-line |
| 161 |
], |
| 162 |
'Last Year': [ |
| 163 |
moment().subtract(1, 'year').startOf('year'), // eslint-disable-line |
| 164 |
moment().subtract(1, 'year').endOf('year') // eslint-disable-line |
| 165 |
], |
| 166 |
'This Month': [ |
| 167 |
moment().startOf('month'), moment().endOf('month') // eslint-disable-line |
| 168 |
], |
| 169 |
'Last Month': [ |
| 170 |
moment().subtract(1, 'month').startOf('month'), // eslint-disable-line |
| 171 |
moment().subtract(1, 'month').endOf('month') // eslint-disable-line |
| 172 |
] |
| 173 |
} |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
} else { // default to overview page. |
| 178 |
|
| 179 |
if ( typeof moment !== 'undefined' ) { |
| 180 |
|
| 181 |
s.ranges = { |
| 182 |
'Today': [ |
| 183 |
moment(), moment() // eslint-disable-line |
| 184 |
], |
| 185 |
'Yesterday': [ |
| 186 |
moment().subtract(1, 'days'), // eslint-disable-line |
| 187 |
moment().subtract(1, 'days') // eslint-disable-line |
| 188 |
], |
| 189 |
'Last 7 Days': [ |
| 190 |
moment().subtract(6, 'days'), // eslint-disable-line |
| 191 |
moment() // eslint-disable-line |
| 192 |
], |
| 193 |
'Last 14 Days': [ |
| 194 |
moment().subtract(13, 'days'), // eslint-disable-line |
| 195 |
moment() // eslint-disable-line |
| 196 |
], |
| 197 |
'Last 30 Days': [ |
| 198 |
moment().subtract(29, 'days'), // eslint-disable-line |
| 199 |
moment() // eslint-disable-line |
| 200 |
], |
| 201 |
'This Month': [ |
| 202 |
moment().startOf('month'), moment().endOf('month') // eslint-disable-line |
| 203 |
], |
| 204 |
'Last Month': [ |
| 205 |
moment().subtract(1, 'month').startOf('month'), // eslint-disable-line |
| 206 |
moment().subtract(1, 'month').endOf('month') // eslint-disable-line |
| 207 |
] |
| 208 |
}; |
| 209 |
|
| 210 |
} |
| 211 |
|
| 212 |
} |
| 213 |
|
| 214 |
}, |
| 215 |
|
| 216 |
/** |
| 217 |
* Inits the date picker for most standard datepicker UIs. |
| 218 |
* |
| 219 |
* @since 1.8.1 |
| 220 |
* |
| 221 |
*/ |
| 222 |
initDatePicker: function ( datepickerClass = 'ranged', datepickerObject = false ) { |
| 223 |
|
| 224 |
if ( datepickerObject ) { |
| 225 |
|
| 226 |
var $the_datepicker = $reports.find( datepickerObject ); |
| 227 |
|
| 228 |
$the_datepicker.daterangepicker({ |
| 229 |
opens: 'left', |
| 230 |
locale: { |
| 231 |
format: 'Y/M/DD' |
| 232 |
}, |
| 233 |
linkedCalendars: true, |
| 234 |
showCustomRangeLabel: true, |
| 235 |
alwaysShowCalendars: true, |
| 236 |
ranges: s.ranges |
| 237 |
|
| 238 |
}, function ( start, end, label ) { // eslint-disable-line |
| 239 |
|
| 240 |
wpchar.debug('first'); |
| 241 |
wpchar.debug( $the_datepicker ); |
| 242 |
|
| 243 |
$the_datepicker.attr('data-start-date', start.format('Y/M/DD') ); |
| 244 |
$the_datepicker.attr('data-end-date', end.format('Y/M/DD') ); |
| 245 |
|
| 246 |
wpchar.debug( $the_datepicker ); |
| 247 |
|
| 248 |
s.datePickerStartDate = start.format('Y/M/DD'); |
| 249 |
s.datePickerEndDate = end.format('Y/M/DD'); |
| 250 |
|
| 251 |
wpchar.debug( app.getStartDateFromDatePicker() ); |
| 252 |
wpchar.debug( app.getEndDateFromDatePicker() ); |
| 253 |
wpchar.debug( elements.$topnav_datepicker ); |
| 254 |
|
| 255 |
wpchar.debug("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD')); |
| 256 |
}); |
| 257 |
|
| 258 |
} else if ( datepickerClass === 'ranged' ) { |
| 259 |
|
| 260 |
$reports.find('input.charitable-datepicker-' + datepickerClass).daterangepicker({ |
| 261 |
opens: 'left', |
| 262 |
locale: { |
| 263 |
format: 'Y/M/DD' |
| 264 |
}, |
| 265 |
linkedCalendars: true, |
| 266 |
showCustomRangeLabel: true, |
| 267 |
alwaysShowCalendars: true, |
| 268 |
ranges: s.ranges |
| 269 |
|
| 270 |
}, function ( start, end, label ) { // eslint-disable-line |
| 271 |
elements.$topnav_datepicker.attr('data', 'start-date').val( start.format('Y/M/DD') ); |
| 272 |
elements.$topnav_datepicker.attr('data', 'end-date').val( end.format('Y/M/DD') ); |
| 273 |
|
| 274 |
s.datePickerStartDate = start.format('Y/M/DD'); |
| 275 |
s.datePickerEndDate = end.format('Y/M/DD'); |
| 276 |
|
| 277 |
wpchar.debug( app.getStartDateFromDatePicker() ); |
| 278 |
wpchar.debug( app.getEndDateFromDatePicker() ); |
| 279 |
wpchar.debug( elements.$topnav_datepicker ); |
| 280 |
|
| 281 |
wpchar.debug("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD')); |
| 282 |
}); |
| 283 |
|
| 284 |
$reports.find('input#charitable-reports-topnav-datepicker-comparefrom-lybunt.charitable-datepicker-' + datepickerClass).daterangepicker({ |
| 285 |
opens: 'left', |
| 286 |
locale: { |
| 287 |
format: 'Y/M/DD' |
| 288 |
}, |
| 289 |
linkedCalendars: true, |
| 290 |
showCustomRangeLabel: true, |
| 291 |
alwaysShowCalendars: true, |
| 292 |
ranges: s.ranges |
| 293 |
|
| 294 |
}, function ( start, end, label ) { // eslint-disable-line |
| 295 |
wpchar.debug('second'); |
| 296 |
wpchar.debug( start.format('Y/M/DD') ); |
| 297 |
wpchar.debug( end.format('Y/M/DD') ); |
| 298 |
elements.$topnav_datepicker_comparefrom.attr('data-start-date', start.format('Y/M/DD') ); |
| 299 |
elements.$topnav_datepicker_comparefrom.attr('data-end-date', end.format('Y/M/DD') ); |
| 300 |
|
| 301 |
s.datePickerCompareFromStartDate = start.format('Y/M/DD'); |
| 302 |
s.datePickerCompareFromEndDate = end.format('Y/M/DD'); |
| 303 |
|
| 304 |
wpchar.debug( app.getStartDateFromDatePicker() ); |
| 305 |
wpchar.debug( app.getEndDateFromDatePicker() ); |
| 306 |
wpchar.debug( elements.$topnav_datepicker_comparefrom ); |
| 307 |
wpchar.debug( this ); |
| 308 |
wpchar.debug( label ); |
| 309 |
|
| 310 |
wpchar.debug("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD')); |
| 311 |
}); |
| 312 |
|
| 313 |
$reports.find('input#charitable-reports-topnav-datepicker-compareto-lybunt.charitable-datepicker-' + datepickerClass).daterangepicker({ |
| 314 |
opens: 'left', |
| 315 |
locale: { |
| 316 |
format: 'Y/M/DD' |
| 317 |
}, |
| 318 |
linkedCalendars: true, |
| 319 |
showCustomRangeLabel: true, |
| 320 |
alwaysShowCalendars: true, |
| 321 |
ranges: s.ranges |
| 322 |
|
| 323 |
}, function ( start, end, label ) { // eslint-disable-line |
| 324 |
wpchar.debug('second'); |
| 325 |
wpchar.debug( start.format('Y/M/DD') ); |
| 326 |
wpchar.debug( end.format('Y/M/DD') ); |
| 327 |
elements.$topnav_datepicker_compareto.attr('data-start-date', start.format('Y/M/DD') ); |
| 328 |
elements.$topnav_datepicker_compareto.attr('data-end-date', end.format('Y/M/DD') ); |
| 329 |
|
| 330 |
s.datePickerCompareToStartDate = start.format('Y/M/DD'); |
| 331 |
s.datePickerCompareToEndDate = end.format('Y/M/DD'); |
| 332 |
|
| 333 |
wpchar.debug( app.getStartDateFromDatePicker() ); |
| 334 |
wpchar.debug( app.getEndDateFromDatePicker() ); |
| 335 |
wpchar.debug( elements.$topnav_datepicker_comparefrom ); |
| 336 |
wpchar.debug( this ); |
| 337 |
wpchar.debug( label ); |
| 338 |
|
| 339 |
wpchar.debug("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD')); |
| 340 |
}); |
| 341 |
|
| 342 |
} else { |
| 343 |
|
| 344 |
wpchar.debug('using datepicker class: ' + $( 'input.' + datepickerClass ).val() ); |
| 345 |
|
| 346 |
var $the_datepicker = $reports.find( 'input.' + datepickerClass ); // eslint-disable-line |
| 347 |
|
| 348 |
$the_datepicker.daterangepicker({ |
| 349 |
opens: 'left', |
| 350 |
locale: { |
| 351 |
format: 'Y/M/DD' |
| 352 |
}, |
| 353 |
linkedCalendars: true, |
| 354 |
showCustomRangeLabel: true, |
| 355 |
alwaysShowCalendars: true, |
| 356 |
ranges: s.ranges |
| 357 |
|
| 358 |
}, function ( start, end, label ) { // eslint-disable-line |
| 359 |
|
| 360 |
wpchar.debug('third'); |
| 361 |
wpchar.debug( $the_datepicker ); |
| 362 |
|
| 363 |
$the_datepicker.attr('data', 'start-date').val( start.format('Y/M/DD') ); |
| 364 |
$the_datepicker.attr('data', 'end-date').val( end.format('Y/M/DD') ); |
| 365 |
|
| 366 |
s.datePickerStartDate = start.format('Y/M/DD'); |
| 367 |
s.datePickerEndDate = end.format('Y/M/DD'); |
| 368 |
|
| 369 |
wpchar.debug( app.getStartDateFromDatePicker() ); |
| 370 |
wpchar.debug( app.getEndDateFromDatePicker() ); |
| 371 |
wpchar.debug( elements.$topnav_datepicker ); |
| 372 |
|
| 373 |
wpchar.debug("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD')); |
| 374 |
}); |
| 375 |
|
| 376 |
} |
| 377 |
|
| 378 |
}, |
| 379 |
|
| 380 |
/** |
| 381 |
* Element bindings. |
| 382 |
* |
| 383 |
* @since 1.8.1 |
| 384 |
*/ |
| 385 |
bindUIActions: function () { |
| 386 |
|
| 387 |
$reports.on('click', '.charitable-toggle', function (e) { |
| 388 |
e.preventDefault(); |
| 389 |
// remove the focus from the button. |
| 390 |
$(this).blur(); |
| 391 |
app.fieldSectionToggle($(this), 'click'); |
| 392 |
}); |
| 393 |
|
| 394 |
// Init all date pickers on the page. |
| 395 |
$reports.find('.charitable-report-download-items').each(function () { |
| 396 |
app.initDownloadButton($(this)); |
| 397 |
}); |
| 398 |
|
| 399 |
$reports.on('click', '#charitable-reports-filter-button[data-filter-type="overview"]', function (e) { // eslint-disable-line |
| 400 |
e.preventDefault(); |
| 401 |
|
| 402 |
wpchar.debug('overview filter button clicked'); |
| 403 |
|
| 404 |
// Update the "print" button hidden field with the new value of the dropdown. |
| 405 |
var campaign_id = parseInt( $('#report-campaign-filter').val() ) || -1; |
| 406 |
$reports.find('form#charitable-overview-print input[name="campaign_id"]').val( campaign_id ); |
| 407 |
var category_id = parseInt( $('#report-category-filter').val() ) || 0; |
| 408 |
$reports.find('form#charitable-overview-print input[name="category_id"]').val( category_id ); |
| 409 |
|
| 410 |
var start_date = app.getStartDateFromDatePicker(); |
| 411 |
var end_date = app.getEndDateFromDatePicker(); |
| 412 |
|
| 413 |
// if charitable-reports-topnav-datepicker exists, update the data attributes with the new dates. |
| 414 |
if ( elements.$topnav_datepicker.length > 0 ) { |
| 415 |
elements.$topnav_datepicker.attr('data-start-date', start_date ); |
| 416 |
elements.$topnav_datepicker.attr('data-end-date', end_date ); |
| 417 |
} |
| 418 |
// Update the "print" button hidden field with the new value of the dropdown. |
| 419 |
$reports.find('form#charitable-overview-print input[name="start_date"]').val( start_date ); |
| 420 |
$reports.find('form#charitable-overview-print input[name="end_date"]').val( end_date ); |
| 421 |
|
| 422 |
wpchar.debug( 'start_date: ' + start_date ); |
| 423 |
wpchar.debug( 'end_date: ' + end_date ); |
| 424 |
|
| 425 |
app.getOverviewReports(); |
| 426 |
}); |
| 427 |
|
| 428 |
/* advanced reports */ |
| 429 |
|
| 430 |
// selecting a value in the advanced report type dropdown. |
| 431 |
$reports.on('change', '#report-advanced-type-filter', function (e) { // eslint-disable-line |
| 432 |
e.preventDefault(); |
| 433 |
app.loadAdvancedReportUI( $(this).val() ); |
| 434 |
}); |
| 435 |
|
| 436 |
// clicking of the filter button. |
| 437 |
$reports.on('click', '.charitable-advanced-filter-button a.button', function (e) { // eslint-disable-line |
| 438 |
e.preventDefault(); |
| 439 |
app.getAdvancedReports( $( this ) ); |
| 440 |
}); |
| 441 |
|
| 442 |
$reports.on('click', '#charitable-reports-filter-button[data-filter-type="activity"]', function (e) { // eslint-disable-line |
| 443 |
e.preventDefault(); |
| 444 |
app.getActivityReports(); |
| 445 |
}); |
| 446 |
|
| 447 |
$reports.on('click', '#charitable-reports-filter-button[data-filter-type="donor"]', function (e) { // eslint-disable-line |
| 448 |
e.preventDefault(); |
| 449 |
app.getDonorReports(); |
| 450 |
}); |
| 451 |
|
| 452 |
$reports.on('change', '#report-campaign-filter', function (e) { // eslint-disable-line |
| 453 |
// e.preventDefault(); |
| 454 |
app.checkCategoryDropdown(); |
| 455 |
}); |
| 456 |
|
| 457 |
/* dhashboard */ |
| 458 |
|
| 459 |
if ( app.isDashboardPage() ) { |
| 460 |
|
| 461 |
$reports.on('change', '#report-date-range-filter', function (e) { // eslint-disable-line |
| 462 |
e.preventDefault(); |
| 463 |
|
| 464 |
// Update the "print" button hidden field with the new value of the dropdown. |
| 465 |
$reports.find('form#charitable-dashboard-print input[name="days"]').val( $(this).val() ); |
| 466 |
|
| 467 |
app.getDashboardReports(); |
| 468 |
}); |
| 469 |
|
| 470 |
} |
| 471 |
|
| 472 |
}, |
| 473 |
|
| 474 |
/** |
| 475 |
* Toggle field group visibility in the field sidebar. |
| 476 |
* |
| 477 |
* @since 1.8.1 |
| 478 |
* |
| 479 |
* @param {mixed} el DOM element or jQuery object. |
| 480 |
* @param {string} action Action. |
| 481 |
*/ |
| 482 |
fieldSectionToggle: function (el, action) { |
| 483 |
|
| 484 |
var $this = $(el), |
| 485 |
$nearestContainer = $this.closest('.charitable-container'), |
| 486 |
$toggleGroup = $nearestContainer.find('.charitable-toggle-container'), |
| 487 |
sectionName = $nearestContainer.data('section-name'), |
| 488 |
$icon = $this.find('i'), |
| 489 |
cookieName = 'charitable_reports_section_' + sectionName; |
| 490 |
|
| 491 |
if (action === 'click') { |
| 492 |
|
| 493 |
$icon.toggleClass('charitable-angle-right'); |
| 494 |
|
| 495 |
$toggleGroup.stop().slideToggle('', function () { |
| 496 |
$nearestContainer.toggleClass('charitable-closed'); |
| 497 |
if ($nearestContainer.hasClass('charitable-closed')) { |
| 498 |
$nearestContainer.removeClass('charitable-open'); |
| 499 |
wpCookies.remove(cookieName); |
| 500 |
} else { |
| 501 |
wpCookies.set(cookieName, 'true', 2592000); // 1 month |
| 502 |
} |
| 503 |
}); |
| 504 |
|
| 505 |
return; |
| 506 |
} |
| 507 |
|
| 508 |
}, |
| 509 |
|
| 510 |
/* dynamic UI updates */ |
| 511 |
|
| 512 |
/** |
| 513 |
* This loads the UI/data for advanced reports, usually when a filter has been applied on the page. |
| 514 |
* |
| 515 |
* @since 1.8.1 |
| 516 |
* |
| 517 |
* @param {string} slug The slug of the advanced report. |
| 518 |
* |
| 519 |
*/ |
| 520 |
loadAdvancedReportUI: function ( slug = '' ) { |
| 521 |
|
| 522 |
wpchar.debug( charitable_reporting ); |
| 523 |
wpchar.debug( charitable_reporting.advanced_reports[slug].title ); |
| 524 |
wpchar.debug( slug ); |
| 525 |
|
| 526 |
// show the appropriate advanced report UI (date pickers and filter buttons). |
| 527 |
$reports.find('.charitable-advanced-date-picker, .charitable-advanced-filter-button').addClass('charitable-hidden'); |
| 528 |
$reports.find('.charitable-advanced-date-picker[data-report-type="' + slug + '"]').removeClass('charitable-hidden'); |
| 529 |
$reports.find('.charitable-advanced-filter-button[data-report-type="' + slug + '"]').removeClass('charitable-hidden'); |
| 530 |
|
| 531 |
app.disableUI(); |
| 532 |
app.reportUILoadingOn(); |
| 533 |
|
| 534 |
var data = { |
| 535 |
action: 'charitable_report_advanced_ui', |
| 536 |
nonce: charitable_reporting.nonce, |
| 537 |
report_type: slug, |
| 538 |
report_title: charitable_reporting.advanced_reports[slug].title, |
| 539 |
report_description: charitable_reporting.advanced_reports[slug].description, |
| 540 |
start_date: s.datePickerStartDate, // this would be a default date? |
| 541 |
end_date: s.datePickerEndDate // this would be a default date? |
| 542 |
}; |
| 543 |
|
| 544 |
$.post( charitable_reporting.ajax_url, data, function (response) { |
| 545 |
|
| 546 |
if (response.success) { // check and see if HTML donation_breakdown is returned and if so, update the breakdown table. |
| 547 |
|
| 548 |
wpchar.debug('response success'); |
| 549 |
|
| 550 |
// use slug as a dynamic variable to access the charitable_reporting object. |
| 551 |
if ( typeof charitable_reporting.advanced_reports[slug] !== 'undefined' ) { |
| 552 |
// update the title and description of the title cards, if the content exists in the localized strings JS in the footer. |
| 553 |
$reports.find('.charitable-title-card-content h2').html( charitable_reporting.advanced_reports[slug].title ); |
| 554 |
$reports.find('.charitable-title-card-content div.charitable-report-description').html( charitable_reporting.advanced_reports[slug].description ); |
| 555 |
} |
| 556 |
|
| 557 |
if ( response.data.html ) { |
| 558 |
$reports.find('#charitable-report-advanced-container').html( response.data.html ); |
| 559 |
} else { |
| 560 |
$reports.find('#charitable-report-advanced-container').html( '' ); |
| 561 |
} |
| 562 |
|
| 563 |
app.enableUI(); |
| 564 |
app.reportUILoadingOff(); |
| 565 |
|
| 566 |
} |
| 567 |
|
| 568 |
}); |
| 569 |
|
| 570 |
// init the date pickers for the advanced report UI. |
| 571 |
app.initDatePicker( false, '.charitable-advanced-date-picker[data-report-type="' + slug + '"] input.charitable-reports-datepicker' ); |
| 572 |
|
| 573 |
// populate the start/end date vars. |
| 574 |
if ( slug !== 'lybunt' ) { |
| 575 |
s.datePickerStartDate = $reports.find('.charitable-advanced-date-picker[data-report-type="' + slug + '"]').find('input.charitable-reports-datepicker').data('start-date'); |
| 576 |
s.datePickerEndDate = $reports.find('.charitable-advanced-date-picker[data-report-type="' + slug + '"]').find('input.charitable-reports-datepicker').data('end-date'); |
| 577 |
} else { |
| 578 |
s.datePickerCompareFromStartDate = $reports.find('.charitable-advanced-date-picker[data-report-type="' + slug + '"]').find('input#charitable-reports-topnav-datepicker-comparefrom-lybunt').data('start-date'); |
| 579 |
s.datePickerCompareFromEndDate = $reports.find('.charitable-advanced-date-picker[data-report-type="' + slug + '"]').find('input#charitable-reports-topnav-datepicker-comparefrom-lybunt').data('end-date'); |
| 580 |
s.datePickerCompareToStartDate = $reports.find('.charitable-advanced-date-picker[data-report-type="' + slug + '"]').find('input#charitable-reports-topnav-datepicker-compareto-lybunt').data('start-date'); |
| 581 |
s.datePickerCompareToEndDate = $reports.find('.charitable-advanced-date-picker[data-report-type="' + slug + '"]').find('input#charitable-reports-topnav-datepicker-compareto-lybunt').data('end-date'); |
| 582 |
} |
| 583 |
|
| 584 |
}, |
| 585 |
|
| 586 |
/** |
| 587 |
* This laods the UI/data for dashboard reports, usually when a filter has been applied on the page. |
| 588 |
* |
| 589 |
* @since 1.8.1 |
| 590 |
* |
| 591 |
*/ |
| 592 |
getDashboardReports: function () { |
| 593 |
|
| 594 |
var data = { |
| 595 |
action: 'charitable_report_dashboard_data', |
| 596 |
nonce: charitable_reporting.nonce, |
| 597 |
start_date: app.getDashboardStartDate(), |
| 598 |
end_date: app.getDashboardEndDate(), |
| 599 |
days: app.getDashboardDays() |
| 600 |
}; |
| 601 |
|
| 602 |
app.disableUI(); |
| 603 |
app.reportUILoadingOn(); |
| 604 |
|
| 605 |
$.post( charitable_reporting.ajax_url, data, function (response) { |
| 606 |
|
| 607 |
if (response.success) { // check and see if HTML donation_breakdown is returned and if so, update the breakdown table. |
| 608 |
|
| 609 |
wpchar.debug('dashboard response success'); |
| 610 |
|
| 611 |
showGrowthToolsNotice = false; |
| 612 |
|
| 613 |
if ( response.data.html.charitable_cards ) { |
| 614 |
wpchar.debug( 'updating dashboard with: ' + response.data.html.charitable_cards ); |
| 615 |
$reports.find('#charitable-dashboard-report-cards').html( response.data.html.charitable_cards ); |
| 616 |
} |
| 617 |
|
| 618 |
if ( response.data.html.charitable_reports ) { |
| 619 |
wpchar.debug( 'updating dashboard with: ' + response.data.html.charitable_reports ); |
| 620 |
$reports.find('#charitable-dashboard-report-sections').html( response.data.html.charitable_reports ); |
| 621 |
} |
| 622 |
|
| 623 |
// if form#charitable-dashboard-print exists, update the hidden fields with the new dates. |
| 624 |
if ( $reports.find('form#charitable-dashboard-print').length > 0 ) { |
| 625 |
$reports.find('form#charitable-dashboard-print input[name="start_date"]').val( response.data.start_date ); |
| 626 |
$reports.find('form#charitable-dashboard-print input[name="end_date"]').val( response.data.end_date ); |
| 627 |
$reports.find('form#charitable-dashboard-print input[name="days"]').val( response.data.days ); |
| 628 |
} |
| 629 |
|
| 630 |
wpchar.debug( charts.headlineChart ); |
| 631 |
wpchar.debug( response.data.headline_chart_options.donation_axis ); |
| 632 |
wpchar.debug( response.data.headline_chart_options.date_axis ); |
| 633 |
// check and see if axis data is returned and if so, update the headline chart. |
| 634 |
if ( charts.headlineChart && response.data.headline_chart_options.donation_axis && response.data.headline_chart_options.date_axis ) { |
| 635 |
charts.headlineChart.updateOptions({ |
| 636 |
series: [ |
| 637 |
{ |
| 638 |
name: 'Donations', |
| 639 |
data: response.data.headline_chart_options.donation_axis |
| 640 |
} |
| 641 |
], |
| 642 |
xaxis: { |
| 643 |
categories: response.data.headline_chart_options.date_axis |
| 644 |
} |
| 645 |
}); |
| 646 |
|
| 647 |
// determine if the donation axis is all zeros. |
| 648 |
var isAllZero = response.data.headline_chart_options.donation_axis.every( function ( val ) { |
| 649 |
return val === 0; |
| 650 |
}); |
| 651 |
|
| 652 |
// check to see if the donation axis is empty or has all zeros. |
| 653 |
if ( response.data.headline_chart_options.donation_axis.length === 0 || isAllZero === false ) { |
| 654 |
showGrowthToolsNotice = false; |
| 655 |
} else{ |
| 656 |
showGrowthToolsNotice = true; |
| 657 |
} |
| 658 |
if ( showGrowthToolsNotice && $( '.charitable-growth-tools-notice' ).length ) { |
| 659 |
$( '.charitable-growth-tools-notice' ).removeClass( 'charitable-hidden' ); |
| 660 |
} else { |
| 661 |
$( '.charitable-growth-tools-notice' ).addClass( 'charitable-hidden' ); |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
app.enableUI(); |
| 666 |
app.reportUILoadingOff(); |
| 667 |
|
| 668 |
} |
| 669 |
|
| 670 |
}); |
| 671 |
|
| 672 |
}, |
| 673 |
|
| 674 |
/** |
| 675 |
* This laods the UI/data for report:overview reports, usually when a filter has been applied on the page. |
| 676 |
* |
| 677 |
* @since 1.8.1 |
| 678 |
* |
| 679 |
*/ |
| 680 |
getOverviewReports: function () { |
| 681 |
|
| 682 |
var data = { |
| 683 |
action: 'charitable_report_overview_data', |
| 684 |
nonce: charitable_reporting.nonce, |
| 685 |
start_date: app.getStartDateFromDatePicker(), |
| 686 |
end_date: app.getEndDateFromDatePicker(), |
| 687 |
campaign_id: parseInt( $('#report-campaign-filter').val() ) || 0, |
| 688 |
campaign_category_id: parseInt( $('#report-category-filter').val() ) || 0, |
| 689 |
filter: $('#report-date-range-filter').val() |
| 690 |
}; |
| 691 |
|
| 692 |
app.disableUI(); |
| 693 |
app.reportUILoadingOn(); |
| 694 |
|
| 695 |
$.post(charitable_reporting.ajax_url, data, function (response) { |
| 696 |
|
| 697 |
if (response.success) { // check and see if HTML donation_breakdown is returned and if so, update the breakdown table. |
| 698 |
|
| 699 |
wpchar.debug('response success'); |
| 700 |
|
| 701 |
if ( response.data.html.donation_breakdown ) { |
| 702 |
elements.$donations_breakdown_list.html(response.data.html.donation_breakdown); |
| 703 |
} |
| 704 |
|
| 705 |
// check and see if axis data is returned and if so, update the headline chart. |
| 706 |
if ( charts.headlineChart && response.data.headline_chart_options.donation_axis && response.data.headline_chart_options.date_axis ) { |
| 707 |
charts.headlineChart.updateOptions({ |
| 708 |
series: [ |
| 709 |
{ |
| 710 |
name: 'Donations', |
| 711 |
data: response.data.headline_chart_options.donation_axis |
| 712 |
} |
| 713 |
], |
| 714 |
xaxis: { |
| 715 |
categories: response.data.headline_chart_options.date_axis |
| 716 |
} |
| 717 |
}); |
| 718 |
} |
| 719 |
|
| 720 |
if (response.data.donation_amount) { |
| 721 |
elements.$top_donation_amount.html(response.data.donation_amount); |
| 722 |
} |
| 723 |
|
| 724 |
// if donation_count was returned, update the donation count. |
| 725 |
if ( response.data.donation_count ) { |
| 726 |
elements.$top_donation_count.html(response.data.donation_count); |
| 727 |
} else { |
| 728 |
elements.$top_donation_count.html('0'); |
| 729 |
} |
| 730 |
|
| 731 |
if ( response.data.donation_average ) { |
| 732 |
elements.$top_donation_average.html(response.data.donation_average); |
| 733 |
} else { |
| 734 |
elements.$top_donation_average.html('0'); |
| 735 |
} |
| 736 |
|
| 737 |
// if donor_count was returned, update the donor count. |
| 738 |
if ( response.data.donors_count ) { |
| 739 |
elements.$top_donation_donors_count.html( response.data.donors_count ); |
| 740 |
} else { |
| 741 |
elements.$top_donation_donors_count.html('0'); |
| 742 |
} |
| 743 |
|
| 744 |
if ( response.data.refund_total_amount ) { |
| 745 |
elements.$top_charitable_refund_total_amount.html(response.data.refund_total_amount); |
| 746 |
} |
| 747 |
|
| 748 |
if ( response.data.refund_count ) { |
| 749 |
elements.$top_charitable_refund_count.html(response.data.refund_count); |
| 750 |
} else { |
| 751 |
elements.$top_charitable_refund_count.html('0'); |
| 752 |
} |
| 753 |
|
| 754 |
if ( response.data.html.payment_methods_list ) { |
| 755 |
elements.$payment_methods_list.html( response.data.html.payment_methods_list ); |
| 756 |
} |
| 757 |
|
| 758 |
if ( charts.paymentMethodsChart && response.data.payment_methods_chart.payment_percentages && response.data.payment_methods_chart.payment_labels ) { |
| 759 |
charts.paymentMethodsChart.updateOptions( { series: response.data.payment_methods_chart.payment_percentages, labels: response.data.payment_methods_chart.payment_labels } ); |
| 760 |
} |
| 761 |
|
| 762 |
if ( response.data.html.activities ) { |
| 763 |
wpchar.debug( 'updating activities with: ' + response.data.html.activities ); |
| 764 |
$reports.find('.charitable-activity-report .charitable-report-ui .the-list').html(response.data.html.activities); |
| 765 |
} |
| 766 |
|
| 767 |
if ( response.data.html.top_donors_list ) { |
| 768 |
wpchar.debug( 'updating top donors with: ' + response.data.html.top_donors_list ); |
| 769 |
$reports.find('.charitable-top-donors-report .charitable-report-ui').html(response.data.html.top_donors_list); |
| 770 |
} |
| 771 |
|
| 772 |
if ( response.data.html.top_campaigns_list ) { |
| 773 |
elements.$top_campaigns_list.html(response.data.html.top_campaigns_list); |
| 774 |
} |
| 775 |
|
| 776 |
// update the "download csv" form. |
| 777 |
$reports.find('#charitable-donations-breakdown-download-form input[name="start_date"]').val( app.getStartDateFromDatePicker() ); |
| 778 |
$reports.find('#charitable-donations-breakdown-download-form input[name="end_date"]').val( app.getEndDateFromDatePicker() ); |
| 779 |
$reports.find('#charitable-donations-breakdown-download-form input[name="campaign_id"]').val( parseInt( $('#report-campaign-filter').val() ) ); |
| 780 |
$reports.find('#charitable-donations-breakdown-download-form input[name="category_id"]').val( parseInt( $('#report-category-filter').val() ) ); |
| 781 |
|
| 782 |
app.enableUI(); |
| 783 |
app.reportUILoadingOff(); |
| 784 |
app.checkCategoryDropdown(); |
| 785 |
|
| 786 |
} |
| 787 |
|
| 788 |
}); |
| 789 |
|
| 790 |
|
| 791 |
}, |
| 792 |
|
| 793 |
/** |
| 794 |
* This laods the UI/data for advanced reports, usually when a filter has been applied on the page. |
| 795 |
* |
| 796 |
* @since 1.8.1 |
| 797 |
* |
| 798 |
* @param {string} button Button element clicked, which we use to get the report type. |
| 799 |
* |
| 800 |
*/ |
| 801 |
getAdvancedReports: function ( $button = false ) { |
| 802 |
|
| 803 |
var report_type = $button.parent().data('report-type'), |
| 804 |
data = {}; |
| 805 |
|
| 806 |
if ( 'lybunt' === report_type ) { |
| 807 |
|
| 808 |
var datePickerCompareFromStartDate = $reports.find('.charitable-advanced-date-picker[data-report-type="' + report_type + '"]').find('input#charitable-reports-topnav-datepicker-comparefrom-lybunt').attr('data-start-date'), |
| 809 |
datePickerCompareFromEndDate = $reports.find('.charitable-advanced-date-picker[data-report-type="' + report_type + '"]').find('input#charitable-reports-topnav-datepicker-comparefrom-lybunt').attr('data-end-date'), |
| 810 |
datePickerCompareToStartDate = $reports.find('.charitable-advanced-date-picker[data-report-type="' + report_type + '"]').find('input#charitable-reports-topnav-datepicker-compareto-lybunt').attr('data-start-date'), |
| 811 |
datePickerCompareToEndDate = $reports.find('.charitable-advanced-date-picker[data-report-type="' + report_type + '"]').find('input#charitable-reports-topnav-datepicker-compareto-lybunt').attr('data-end-date'); |
| 812 |
|
| 813 |
data = { |
| 814 |
action: 'charitable_report_advanced_data', |
| 815 |
nonce: charitable_reporting.nonce, |
| 816 |
report_type: report_type, |
| 817 |
compare_from_start_date: datePickerCompareFromStartDate, |
| 818 |
compare_from_end_date: datePickerCompareFromEndDate, |
| 819 |
compare_to_start_date: datePickerCompareToStartDate, |
| 820 |
compare_to_end_date: datePickerCompareToEndDate |
| 821 |
}; |
| 822 |
|
| 823 |
} else { |
| 824 |
|
| 825 |
var start_date = s.datePickerStartDate, // $reports.find('.charitable-advanced-date-picker[data-report-type="' + report_type + '"]').find('input.charitable-reports-datepicker').data('start-date'), |
| 826 |
end_date = s.datePickerEndDate; // $reports.find('.charitable-advanced-date-picker[data-report-type="' + report_type + '"]').find('input.charitable-reports-datepicker').data('end-date'); |
| 827 |
|
| 828 |
data = { |
| 829 |
action: 'charitable_report_advanced_data', |
| 830 |
nonce: charitable_reporting.nonce, |
| 831 |
report_type: report_type, |
| 832 |
start_date: start_date, |
| 833 |
end_date: end_date |
| 834 |
}; |
| 835 |
|
| 836 |
} |
| 837 |
|
| 838 |
app.disableUI(); |
| 839 |
app.reportUILoadingOn(); |
| 840 |
|
| 841 |
$.post( charitable_reporting.ajax_url, data, function (response) { |
| 842 |
|
| 843 |
if (response.success) { // check and see if HTML donation_breakdown is returned and if so, update the breakdown table. |
| 844 |
|
| 845 |
wpchar.debug('response success'); |
| 846 |
|
| 847 |
// use slug as a dynamic variable to access the charitable_reporting object. |
| 848 |
if ( typeof charitable_reporting.advanced_reports[report_type] !== 'undefined' ) { |
| 849 |
// update the title and description of the title cards, if the content exists in the localized strings JS in the footer. |
| 850 |
$reports.find('.charitable-title-card-content h2').html( charitable_reporting.advanced_reports[report_type].title ); |
| 851 |
$reports.find('.charitable-title-card-content div.charitable-report-description').html( charitable_reporting.advanced_reports[report_type].description ); |
| 852 |
} |
| 853 |
|
| 854 |
if ( response.data.html ) { |
| 855 |
$reports.find('#charitable-report-advanced-container').html( response.data.html ); |
| 856 |
} |
| 857 |
|
| 858 |
app.enableUI(); |
| 859 |
app.reportUILoadingOff(); |
| 860 |
|
| 861 |
} |
| 862 |
|
| 863 |
}); |
| 864 |
|
| 865 |
}, |
| 866 |
|
| 867 |
/** |
| 868 |
* This laods the UI/data for activity reports. |
| 869 |
* |
| 870 |
* @since 1.8.1 |
| 871 |
* |
| 872 |
*/ |
| 873 |
getActivityReports: function () { |
| 874 |
|
| 875 |
var data = { |
| 876 |
action: 'charitable_report_activity_data', |
| 877 |
nonce: charitable_reporting.nonce, |
| 878 |
start_date: app.getStartDateFromDatePicker(), |
| 879 |
end_date: app.getEndDateFromDatePicker(), |
| 880 |
campaign_id: parseInt( $('#report-campaign-filter').val() ), |
| 881 |
activity_type: $('#report-activity-type-filter').val() |
| 882 |
}; |
| 883 |
|
| 884 |
app.disableUI(); |
| 885 |
app.reportUILoadingOn(); |
| 886 |
|
| 887 |
$.post(charitable_reporting.ajax_url, data, function (response) { |
| 888 |
|
| 889 |
if (response.success) { // check and see if HTML donation_breakdown is returned and if so, update the breakdown table. |
| 890 |
|
| 891 |
wpchar.debug('response success'); |
| 892 |
|
| 893 |
if (response.data.html.activities) { |
| 894 |
wpchar.debug( 'updating activities with: ' + response.data.html.activities ); |
| 895 |
$reports.find('.charitable-the-list-container').html(response.data.html.activities); |
| 896 |
} |
| 897 |
|
| 898 |
// update the "download csv" form. |
| 899 |
$reports.find('#charitable-activity-download-form input[name="start_date"]').val( app.getStartDateFromDatePicker() ); |
| 900 |
$reports.find('#charitable-activity-download-form input[name="end_date"]').val( app.getEndDateFromDatePicker() ); |
| 901 |
$reports.find('#charitable-activity-download-form input[name="campaign_id"]').val( parseInt( $('#report-campaign-filter').val() ) ); |
| 902 |
$reports.find('#charitable-activity-download-form input[name="activity_type"]').val( $('#report-activity-type-filter').val() ); |
| 903 |
|
| 904 |
app.enableUI(); |
| 905 |
app.reportUILoadingOff(); |
| 906 |
|
| 907 |
} |
| 908 |
|
| 909 |
}); |
| 910 |
|
| 911 |
}, |
| 912 |
|
| 913 |
/** |
| 914 |
* This laods the UI/data for donor reports. |
| 915 |
* |
| 916 |
* @since 1.8.1 |
| 917 |
* |
| 918 |
*/ |
| 919 |
getDonorReports: function () { |
| 920 |
|
| 921 |
var data = { |
| 922 |
action: 'charitable_report_donor_data', |
| 923 |
nonce: charitable_reporting.nonce, |
| 924 |
report_type: $('#report-donor-type-filter').val(), |
| 925 |
limit: $('#report-donor-limit').val(), |
| 926 |
offset: $('#report-donor-offset').val(), |
| 927 |
ppage: $('#report-donor-ppage').val() |
| 928 |
}; |
| 929 |
|
| 930 |
app.disableUI(); |
| 931 |
app.reportUILoadingOn(); |
| 932 |
|
| 933 |
$.post(charitable_reporting.ajax_url, data, function (response) { |
| 934 |
|
| 935 |
if (response.success) { // check and see if HTML donation_breakdown is returned and if so, update the breakdown table. |
| 936 |
|
| 937 |
if ( response.data.html.donors ) { |
| 938 |
wpchar.debug( 'updating donors with: ' + response.data.html.donors ); |
| 939 |
$reports.find('#charitable-report-donor-container').html( response.data.html.donors ); |
| 940 |
} |
| 941 |
|
| 942 |
if ( response.data.html.title_card ) { |
| 943 |
$reports.find('#charitable-report-donor-title-card').html( response.data.html.title_card ); |
| 944 |
} |
| 945 |
|
| 946 |
app.enableUI(); |
| 947 |
app.reportUILoadingOff(); |
| 948 |
|
| 949 |
} |
| 950 |
|
| 951 |
}); |
| 952 |
|
| 953 |
}, |
| 954 |
|
| 955 |
initPagination: function () { |
| 956 |
|
| 957 |
if ( $reports.find('.charitable-reports-pagination-nav').length === 0 ) { |
| 958 |
return; |
| 959 |
} |
| 960 |
|
| 961 |
$reports.on('click', '.charitable-reports-pagination-nav .page-item a.page-link', function (e) { // eslint-disable-line |
| 962 |
e.preventDefault(); |
| 963 |
|
| 964 |
var $this = $(this), |
| 965 |
limit = $this.data('limit'), |
| 966 |
offset = $this.data('offset'), |
| 967 |
ppage = $this.data('ppage'), |
| 968 |
total_pages = $this.data('total-pages'), |
| 969 |
current_page = $this.data('current-page'), |
| 970 |
report_type = $this.data('report-type'), |
| 971 |
page = $this.data('page'), |
| 972 |
tab = $this.data('tab'); |
| 973 |
|
| 974 |
var data = { |
| 975 |
action: 'charitable_report_donor_data_pagination', |
| 976 |
nonce: charitable_reporting.nonce, |
| 977 |
limit: limit, |
| 978 |
offset: offset, |
| 979 |
ppage: ppage, |
| 980 |
total_pages: total_pages, |
| 981 |
current_page: current_page, |
| 982 |
report_type: report_type, |
| 983 |
page: page, |
| 984 |
tab: tab |
| 985 |
}; |
| 986 |
|
| 987 |
$.post(charitable_reporting.ajax_url, data, function (response) { |
| 988 |
|
| 989 |
if (response.success) { // check and see if HTML donation_breakdown is returned and if so, update the breakdown table. |
| 990 |
|
| 991 |
if ( response.data.html.donors ) { |
| 992 |
$reports.find('#charitable-report-donor-container').html( response.data.html.donors ); |
| 993 |
} |
| 994 |
|
| 995 |
} |
| 996 |
|
| 997 |
}); |
| 998 |
|
| 999 |
}); |
| 1000 |
|
| 1001 |
}, |
| 1002 |
|
| 1003 |
/** |
| 1004 |
* This inits the "headline" chart for a page. |
| 1005 |
* |
| 1006 |
* @since 1.8.1 |
| 1007 |
* @since 1.8.1.6 - Added check for empty donation axis and animationEnd event. |
| 1008 |
* |
| 1009 |
*/ |
| 1010 |
initHeadlineChart: function () { |
| 1011 |
|
| 1012 |
if ( $('#charitable-headline-graph').length === 0 ) { |
| 1013 |
this.return; |
| 1014 |
} |
| 1015 |
|
| 1016 |
var enableToolTips = false; |
| 1017 |
|
| 1018 |
if ( typeof charitable_reporting.headline_chart_options.enable_tooltips !== 'undefined' && false !== charitable_reporting.headline_chart_options.enable_tooltips ) { |
| 1019 |
enableToolTips = true; |
| 1020 |
} |
| 1021 |
|
| 1022 |
var headlineChartOptions = { |
| 1023 |
chart: { |
| 1024 |
type: 'area', |
| 1025 |
width: '100%', |
| 1026 |
height: 400, |
| 1027 |
foreColor: "#757781", |
| 1028 |
toolbar: { |
| 1029 |
autoSelected: "pan", |
| 1030 |
show: false |
| 1031 |
}, |
| 1032 |
events: { |
| 1033 |
animationEnd: function ( chartContext, options ) { |
| 1034 |
// if the goal tools notice is not visible, show it. |
| 1035 |
if ( showGrowthToolsNotice && $( '.charitable-growth-tools-notice' ).length ) { |
| 1036 |
$( '.charitable-growth-tools-notice' ).removeClass( 'charitable-hidden' ); |
| 1037 |
} |
| 1038 |
} |
| 1039 |
} |
| 1040 |
}, |
| 1041 |
series: [ |
| 1042 |
{ |
| 1043 |
name: 'Donations', |
| 1044 |
data: charitable_reporting.headline_chart_options.donation_axis |
| 1045 |
} |
| 1046 |
], |
| 1047 |
colors: ["#5AA15226"], |
| 1048 |
grid: { |
| 1049 |
borderColor: "#C9D4CA", |
| 1050 |
clipMarkers: false, |
| 1051 |
yaxis: { |
| 1052 |
lines: { |
| 1053 |
show: true |
| 1054 |
} |
| 1055 |
} |
| 1056 |
}, |
| 1057 |
stroke: { |
| 1058 |
width: 3, |
| 1059 |
colors: ["#5AA152"] |
| 1060 |
}, |
| 1061 |
fill: { |
| 1062 |
type: "solid" |
| 1063 |
}, |
| 1064 |
tooltip: { |
| 1065 |
enabled: enableToolTips, |
| 1066 |
theme: "dark" |
| 1067 |
}, |
| 1068 |
dataLabels: { |
| 1069 |
enabled: false |
| 1070 |
}, |
| 1071 |
markers: { |
| 1072 |
size: 5, |
| 1073 |
colors: ["#FFFFFF"], |
| 1074 |
strokeColor: "#5AA152", |
| 1075 |
strokeWidth: 4 |
| 1076 |
}, |
| 1077 |
xaxis: { |
| 1078 |
categories: charitable_reporting.headline_chart_options.date_axis |
| 1079 |
}, |
| 1080 |
yaxis: { |
| 1081 |
labels: { |
| 1082 |
formatter: (value) => { |
| 1083 |
// Format currency values using the configured decimal count. |
| 1084 |
// Currency symbol is already decoded in PHP, so use it directly. |
| 1085 |
var decimalCount = typeof charitable_reporting.decimal_count !== 'undefined' |
| 1086 |
? charitable_reporting.decimal_count |
| 1087 |
: 2; |
| 1088 |
return charitable_reporting.currency_symbol + value.toFixed(decimalCount); |
| 1089 |
} |
| 1090 |
}, |
| 1091 |
min: 0 |
| 1092 |
} |
| 1093 |
} |
| 1094 |
|
| 1095 |
charts.headlineChart = new ApexCharts(document.querySelector("#charitable-headline-graph"), headlineChartOptions); // eslint-disable-line |
| 1096 |
|
| 1097 |
// check if array/value exists. |
| 1098 |
if ( typeof charitable_reporting.headline_chart_options.donation_axis !== 'undefined' ) { |
| 1099 |
// check if array has all zeros. |
| 1100 |
if ( charitable_reporting.headline_chart_options.donation_axis.every( function (i) { return i === 0; } ) ) { |
| 1101 |
showGrowthToolsNotice = true; |
| 1102 |
} else { |
| 1103 |
showGrowthToolsNotice = false; |
| 1104 |
} |
| 1105 |
} |
| 1106 |
|
| 1107 |
}, |
| 1108 |
|
| 1109 |
/** |
| 1110 |
* This inits the "payment" chart for a page, usually located on the dashboard. |
| 1111 |
* |
| 1112 |
* @since 1.8.1 |
| 1113 |
* |
| 1114 |
*/ |
| 1115 |
initPaymentChart: function () { |
| 1116 |
|
| 1117 |
if ( ! app.isDashboardPage() ) { |
| 1118 |
this.return; |
| 1119 |
} |
| 1120 |
|
| 1121 |
if ( $('#charitable-payment-methods-graph').length === 0 ) { |
| 1122 |
this.return; |
| 1123 |
} |
| 1124 |
|
| 1125 |
if ( typeof charitable_reporting.payment_methods_chart_options === 'undefined' ) { |
| 1126 |
this.return; |
| 1127 |
} |
| 1128 |
|
| 1129 |
// Color mapping for payment methods by gateway key. |
| 1130 |
// This ensures consistent colors regardless of order. |
| 1131 |
// Colors match the CSS legend dot colors in charitable-admin.scss. |
| 1132 |
var paymentMethodColors = { |
| 1133 |
'stripe': '#5AA152', // Green (matches CSS) |
| 1134 |
'offline': '#9e36f9', // Purple (matches CSS) |
| 1135 |
'manual': '#F99E36', // Orange (matches CSS) |
| 1136 |
'paypal': '#2B66D1', // Blue (matches CSS) |
| 1137 |
'square_core': '#d21561', // Pink/Red (unique color for Square) |
| 1138 |
'square': '#d21561' // Legacy Square support |
| 1139 |
}; |
| 1140 |
|
| 1141 |
// Default color palette for unknown payment methods. |
| 1142 |
var defaultColors = [ |
| 1143 |
'#d21561', '#9e36f9', '#F99E36', '#2B66D1', '#5AA152' |
| 1144 |
]; |
| 1145 |
|
| 1146 |
// Build colors array based on payment method keys. |
| 1147 |
var paymentKeys = typeof charitable_reporting.payment_methods_chart_options.payment_keys !== 'undefined' |
| 1148 |
? charitable_reporting.payment_methods_chart_options.payment_keys |
| 1149 |
: []; |
| 1150 |
var colors = []; |
| 1151 |
var colorIndex = 0; |
| 1152 |
|
| 1153 |
for ( var i = 0; i < paymentKeys.length; i++ ) { |
| 1154 |
var key = paymentKeys[i]; |
| 1155 |
if ( key && paymentMethodColors[key] ) { |
| 1156 |
colors.push( paymentMethodColors[key] ); |
| 1157 |
} else if ( key ) { |
| 1158 |
// For unknown payment methods, use a color from the default palette. |
| 1159 |
colors.push( defaultColors[colorIndex % defaultColors.length] ); |
| 1160 |
colorIndex++; |
| 1161 |
} else { |
| 1162 |
// Empty key (usually the trailing empty entry), use first default color. |
| 1163 |
colors.push( defaultColors[0] ); |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
// If no colors were generated (fallback), use the default array. |
| 1168 |
if ( colors.length === 0 ) { |
| 1169 |
colors = defaultColors; |
| 1170 |
} |
| 1171 |
|
| 1172 |
var paymentMethodsChartOptions = { |
| 1173 |
series: charitable_reporting.payment_methods_chart_options.payment_percentages, |
| 1174 |
labels: charitable_reporting.payment_methods_chart_options.payment_labels, |
| 1175 |
colors: colors, |
| 1176 |
chart: { |
| 1177 |
type: 'donut', |
| 1178 |
width: '75%', |
| 1179 |
toolbar: { |
| 1180 |
autoSelected: "pan", |
| 1181 |
show: false |
| 1182 |
} |
| 1183 |
}, |
| 1184 |
dataLabels: { |
| 1185 |
enabled: false |
| 1186 |
}, |
| 1187 |
yaxis: { |
| 1188 |
labels: { |
| 1189 |
formatter: (value) => { |
| 1190 |
return value + '%' |
| 1191 |
} |
| 1192 |
} |
| 1193 |
}, |
| 1194 |
plotOptions: { |
| 1195 |
pie: { |
| 1196 |
donut: { |
| 1197 |
size: '80%' |
| 1198 |
} |
| 1199 |
} |
| 1200 |
}, |
| 1201 |
total: { |
| 1202 |
show: true, |
| 1203 |
showAlways: true, |
| 1204 |
label: 'Total', |
| 1205 |
fontSize: '22px', |
| 1206 |
fontFamily: 'Helvetica, Arial, sans-serif', |
| 1207 |
fontWeight: 600, |
| 1208 |
color: '#373d3f', |
| 1209 |
formatter: function (w) { |
| 1210 |
return w.globals.seriesTotals.reduce((a, b) => { |
| 1211 |
return a + b |
| 1212 |
}, 0) |
| 1213 |
} |
| 1214 |
}, |
| 1215 |
legend: { |
| 1216 |
show: false, |
| 1217 |
showForSingleSeries: true, |
| 1218 |
showForNullSeries: true, |
| 1219 |
showForZeroSeries: true, |
| 1220 |
position: 'bottom', |
| 1221 |
horizontalAlign: 'center', |
| 1222 |
floating: false, |
| 1223 |
fontSize: '14px', |
| 1224 |
fontFamily: 'Helvetica, Arial', |
| 1225 |
fontWeight: 400, |
| 1226 |
inverseOrder: true, |
| 1227 |
customLegendItems: [], |
| 1228 |
offsetX: 0, |
| 1229 |
offsetY: 0, |
| 1230 |
labels: { |
| 1231 |
useSeriesColors: false |
| 1232 |
}, |
| 1233 |
markers: { |
| 1234 |
width: 12, |
| 1235 |
height: 12, |
| 1236 |
strokeWidth: 0, |
| 1237 |
strokeColor: '#fff', |
| 1238 |
radius: 12, |
| 1239 |
offsetX: 0, |
| 1240 |
offsetY: 0, |
| 1241 |
customHTML: function () { |
| 1242 |
return '<span class="custom-marker">test</span>' |
| 1243 |
} |
| 1244 |
}, |
| 1245 |
itemMargin: { |
| 1246 |
horizontal: 5, |
| 1247 |
vertical: 0 |
| 1248 |
} |
| 1249 |
} |
| 1250 |
} |
| 1251 |
|
| 1252 |
charts.paymentMethodsChart = new ApexCharts(document.querySelector("#charitable-payment-methods-graph"), paymentMethodsChartOptions); // eslint-disable-line |
| 1253 |
|
| 1254 |
}, |
| 1255 |
|
| 1256 |
/** |
| 1257 |
* Init the charts on the page. |
| 1258 |
* |
| 1259 |
* @since 1.8.1 |
| 1260 |
* |
| 1261 |
*/ |
| 1262 |
initCharts: function () { |
| 1263 |
|
| 1264 |
app.initHeadlineChart(); |
| 1265 |
app.initPaymentChart(); |
| 1266 |
|
| 1267 |
}, |
| 1268 |
|
| 1269 |
/** |
| 1270 |
* Render the headline chart on the page. |
| 1271 |
* |
| 1272 |
* @since 1.8.1 |
| 1273 |
* |
| 1274 |
*/ |
| 1275 |
renderHeadlineChart: function () { |
| 1276 |
|
| 1277 |
if ($('#charitable-headline-graph').length === 0) { |
| 1278 |
return; |
| 1279 |
} |
| 1280 |
|
| 1281 |
charts.headlineChart.render(); |
| 1282 |
|
| 1283 |
}, |
| 1284 |
|
| 1285 |
/** |
| 1286 |
* Render the payment chart on the page. |
| 1287 |
* |
| 1288 |
* @since 1.8.1 |
| 1289 |
* |
| 1290 |
*/ |
| 1291 |
renderPaymentChart: function () { |
| 1292 |
|
| 1293 |
if ($('#charitable-payment-methods-graph').length === 0) { |
| 1294 |
return; |
| 1295 |
} |
| 1296 |
|
| 1297 |
charts.paymentMethodsChart.render(); |
| 1298 |
|
| 1299 |
}, |
| 1300 |
|
| 1301 |
/** |
| 1302 |
* Render the charts on the page. |
| 1303 |
* |
| 1304 |
* @since 1.8.1 |
| 1305 |
* |
| 1306 |
*/ |
| 1307 |
renderCharts: function () { |
| 1308 |
|
| 1309 |
app.renderHeadlineChart(); |
| 1310 |
app.renderPaymentChart(); |
| 1311 |
|
| 1312 |
}, |
| 1313 |
|
| 1314 |
/* UI and Misc */ |
| 1315 |
|
| 1316 |
/** |
| 1317 |
* Disables the UI on the page. |
| 1318 |
* |
| 1319 |
* @since 1.8.1 |
| 1320 |
* |
| 1321 |
*/ |
| 1322 |
disableUI: function () { |
| 1323 |
|
| 1324 |
$reports.find('a, button, input, select').attr('disabled', 'disabled').addClass('charitable-disabled'); |
| 1325 |
|
| 1326 |
}, |
| 1327 |
|
| 1328 |
/** |
| 1329 |
* Enables the UI on the page. |
| 1330 |
* |
| 1331 |
* @since 1.8.1 |
| 1332 |
* |
| 1333 |
*/ |
| 1334 |
enableUI: function () { |
| 1335 |
|
| 1336 |
$reports.find('a, button, input, select').removeAttr('disabled').removeClass('charitable-disabled'); |
| 1337 |
|
| 1338 |
}, |
| 1339 |
|
| 1340 |
/** |
| 1341 |
* Shows the loading indicator on the page. |
| 1342 |
* |
| 1343 |
* @since 1.8.1 |
| 1344 |
* |
| 1345 |
*/ |
| 1346 |
reportUILoadingOn: function () { |
| 1347 |
|
| 1348 |
$reports.find('.charitable-report-ui, .charitable-activity-list-container').addClass('charitable-section-loading'); |
| 1349 |
|
| 1350 |
}, |
| 1351 |
|
| 1352 |
/** |
| 1353 |
* Hides the loading indicator on the page. |
| 1354 |
* |
| 1355 |
* @since 1.8.1 |
| 1356 |
* |
| 1357 |
*/ |
| 1358 |
reportUILoadingOff: function () { |
| 1359 |
|
| 1360 |
$reports.find('.charitable-report-ui, .charitable-activity-list-container').removeClass('charitable-section-loading'); |
| 1361 |
|
| 1362 |
}, |
| 1363 |
|
| 1364 |
/** |
| 1365 |
* Util function that gets the start dates from the date picker. |
| 1366 |
* |
| 1367 |
* @since 1.8.1 |
| 1368 |
* |
| 1369 |
*/ |
| 1370 |
getStartDateFromDatePicker: function () { |
| 1371 |
|
| 1372 |
return s.datePickerStartDate; // elements.$topnav_datepicker.data('start-date'); |
| 1373 |
|
| 1374 |
}, |
| 1375 |
|
| 1376 |
/** |
| 1377 |
* Util function that gets the end dates from the date picker. |
| 1378 |
* |
| 1379 |
* @since 1.8.1 |
| 1380 |
* |
| 1381 |
*/ |
| 1382 |
getEndDateFromDatePicker: function () { |
| 1383 |
|
| 1384 |
return s.datePickerEndDate; // elements.$topnav_datepicker.data('end-date'); |
| 1385 |
|
| 1386 |
}, |
| 1387 |
|
| 1388 |
/** |
| 1389 |
* Util function that gets the start date "compare" from the date picker. |
| 1390 |
* |
| 1391 |
* @since 1.8.1 |
| 1392 |
* |
| 1393 |
*/ |
| 1394 |
getStartDateFromCompareFromDatePicker: function () { |
| 1395 |
|
| 1396 |
return s.datePickerCompareFromStartDate; |
| 1397 |
|
| 1398 |
}, |
| 1399 |
|
| 1400 |
/** |
| 1401 |
* Util function that gets the end date "compare" from the date picker. |
| 1402 |
* |
| 1403 |
* @since 1.8.1 |
| 1404 |
* |
| 1405 |
*/ |
| 1406 |
getEndDateFromCompareFromDatePicker: function () { |
| 1407 |
|
| 1408 |
return s.datePickerCompareFromEndDate; |
| 1409 |
|
| 1410 |
}, |
| 1411 |
|
| 1412 |
/** |
| 1413 |
* Util function that gets the start date "compare" from the date picker. |
| 1414 |
* |
| 1415 |
* @since 1.8.1 |
| 1416 |
* |
| 1417 |
*/ |
| 1418 |
getStartDateFromCompareToDatePicker: function () { |
| 1419 |
|
| 1420 |
return s.datePickerCompareToStartDate; |
| 1421 |
|
| 1422 |
}, |
| 1423 |
|
| 1424 |
/** |
| 1425 |
* Util function that gets the end date "compare" from the date picker. |
| 1426 |
* |
| 1427 |
* @since 1.8.1 |
| 1428 |
* |
| 1429 |
*/ |
| 1430 |
getEndDateFromCompareToDatePicker: function () { |
| 1431 |
|
| 1432 |
return s.datePickerCompareToEndDate; |
| 1433 |
|
| 1434 |
}, |
| 1435 |
|
| 1436 |
/** |
| 1437 |
* Util function that gets dashboard start date. |
| 1438 |
* |
| 1439 |
* @since 1.8.1 |
| 1440 |
* |
| 1441 |
*/ |
| 1442 |
getDashboardStartDate: function () { |
| 1443 |
|
| 1444 |
return $reports.find('#charitable-dashboard-report-start-date').val(); |
| 1445 |
|
| 1446 |
}, |
| 1447 |
|
| 1448 |
/** |
| 1449 |
* Util function that gets dashboard end date. |
| 1450 |
* |
| 1451 |
* @since 1.8.1 |
| 1452 |
* |
| 1453 |
*/ |
| 1454 |
getDashboardEndDate: function () { |
| 1455 |
|
| 1456 |
return $reports.find('#charitable-dashboard-report-end-date').val(); |
| 1457 |
|
| 1458 |
}, |
| 1459 |
|
| 1460 |
/** |
| 1461 |
* Util function that gets dashboard "days" (last 7, 14, 30, etc.) |
| 1462 |
* |
| 1463 |
* @since 1.8.1 |
| 1464 |
* |
| 1465 |
*/ |
| 1466 |
getDashboardDays: function () { |
| 1467 |
|
| 1468 |
return $reports.find('#report-date-range-filter').val(); |
| 1469 |
|
| 1470 |
}, |
| 1471 |
|
| 1472 |
/** |
| 1473 |
* Util funcion that checks if this is an advanced report page. |
| 1474 |
* |
| 1475 |
* @since 1.8.1 |
| 1476 |
* |
| 1477 |
*/ |
| 1478 |
isAdvancedPage: function() { |
| 1479 |
|
| 1480 |
return ( $('.charitable-advanced-report').length > 0 ); |
| 1481 |
|
| 1482 |
}, |
| 1483 |
|
| 1484 |
/** |
| 1485 |
* Util funcion that checks if this is a dashboard page. |
| 1486 |
* |
| 1487 |
* @since 1.8.1 |
| 1488 |
* |
| 1489 |
*/ |
| 1490 |
isDashboardPage: function() { |
| 1491 |
|
| 1492 |
return ( $('#charitable-dashboard-report-container').length > 0 ); |
| 1493 |
|
| 1494 |
}, |
| 1495 |
|
| 1496 |
/* utils */ |
| 1497 |
|
| 1498 |
/** |
| 1499 |
* Util function that decodes HTML entities. |
| 1500 |
* |
| 1501 |
* @since 1.8.1 |
| 1502 |
* |
| 1503 |
*/ |
| 1504 |
decodeHtml: function (html) { |
| 1505 |
var txt = document.createElement("textarea"); |
| 1506 |
txt.innerHTML = html; |
| 1507 |
return txt.value; |
| 1508 |
} |
| 1509 |
|
| 1510 |
|
| 1511 |
}; |
| 1512 |
|
| 1513 |
return app; |
| 1514 |
|
| 1515 |
}(document, window, jQuery)); // eslint-disable-line no-undef |
| 1516 |
|
| 1517 |
CharitableAdminReporting.init(); |
| 1518 |
|