PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.0
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.0
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / assets / js / charitable-admin.js

charitable-admin.js in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.0, at assets/js/charitable-admin.js

873 lines 23.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 CHARITABLE_ADMIN = window.CHARITABLE_ADMIN || {};
2
3 /**
4 * Datepicker
5 */
6 ( function( exports, $ ){
7
8 if ( ! $.fn.datepicker ) {
9 return;
10 }
11
12 var Datepicker = function( $el ) {
13 this.$el = $el;
14 var options = {
15 dateFormat : this.$el.data('format') || 'yy/mm/dd',
16 minDate : this.$el.data('min-date') || '',
17 beforeShow : function( input, inst ) {
18 $('#ui-datepicker-div').addClass('charitable-datepicker-table');
19 }
20 }
21
22 this.$el.datepicker( options );
23
24 if ( this.$el.data('date') ) {
25 this.$el.datepicker( 'setDate', this.$el.data('date') );
26 }
27
28 if ( this.$el.data('min-date') ) {
29 this.$el.datepicker( 'option', 'minDate', this.$el.data('min-date') );
30 }
31 }
32
33 exports.Datepicker = Datepicker;
34
35 })( CHARITABLE_ADMIN, jQuery );
36
37 /**
38 * Conditional settings.
39 */
40 ( function( exports, $ ){
41
42 var Settings = function( $el ) {
43 var triggers = [];
44
45 show_setting = function(value, $trigger) {
46 var not = '!' === value[0],
47 compare = not ? value.slice(1) : value,
48 show;
49
50 if ('checked' === compare) {
51 show = $trigger.is(':checked');
52 } else if ('selected' === compare) {
53 show = $trigger.selected();
54 } else {
55 show = $trigger.val() === compare;
56 }
57
58 return not ? !show : show;
59 };
60
61 toggle_setting = function($setting, $trigger) {
62 var $el = (function($setting){
63 var $tr = $setting.parents('tr');
64 return $tr.length ? $tr.first() : $setting;
65 })($setting),
66 value = get_setting_value( $setting ),
67 show = show_setting(value, $trigger);
68
69 $el.toggle(show);
70 };
71
72 get_setting_value = function($setting) {
73 var value = $setting.data( 'trigger-value' );
74
75 /* Backwards compatibility for pre 1.5 */
76 if ( 'undefined' === typeof value ) {
77 value = $setting.data( 'show-only-if-value' );
78 }
79
80 return value;
81 };
82
83 toggle_options = function($setting, $trigger) {
84 var value = $trigger.val(),
85 options = $setting.data( 'trigger-value' ),
86 available;
87
88 /* If it's a radio input that isn't checked, ignore the event. */
89 if ( 'radio' === $trigger.attr( 'type' ) && ! $trigger.prop( 'checked' ) ) {
90 return;
91 }
92
93 if ( ! options.hasOwnProperty( value ) ) {
94 return;
95 }
96
97 available = options[value];
98
99 $setting.find( 'input' ).each( function(){
100 var $option = $(this),
101 disabled = ! ( $option.val() in available );
102
103 if ( disabled ) {
104 $option.prop( 'checked', false );
105 }
106
107 $option.prop( 'disabled', disabled ).trigger( 'change' );
108 });
109 };
110
111 get_trigger_id = function($setting) {
112 var id = $setting.data( 'trigger-key' );
113
114 /* Backwards compatibility for pre 1.5 */
115 if ( 'undefined' === typeof id ) {
116 id = '#' + $setting.data( 'show-only-if-key' );
117 }
118
119 return id;
120 };
121
122 get_trigger = function(id) {
123 if ( '#' === id[0] ) {
124 return $( id );
125 }
126
127 return $( '[name="' + id + '"]' );
128 };
129
130 get_change_type = function($setting) {
131 var type = $setting.data( 'trigger-change-type' );
132
133 if ( 'undefined' === typeof type ) {
134 type = 'visibility';
135 }
136
137 return type;
138 };
139
140 on_change = function() {
141 var $trigger = $( this ),
142 trigger_idx = $trigger.data( 'trigger_idx' ),
143 settings;
144
145 trigger_idx.forEach( function( id ) {
146
147 settings = triggers[id]['settings'];
148
149 settings.forEach( function( $setting ) {
150 var change = get_change_type( $setting );
151
152 if ( 'visibility' === change ) {
153 toggle_setting( $setting, $trigger );
154 } else if ( 'options' === change ) {
155 toggle_options( $setting, $trigger );
156 }
157 } );
158 } );
159 };
160
161 this.$el = $el;
162
163 var i = 0;
164
165 this.$el.find( '[data-trigger-key],[data-show-only-if-key]' ).each( function(){
166 var $this = $(this),
167 trigger_id = get_trigger_id( $this ),
168 element = triggers[trigger_id];
169
170 if ( 'undefined' === typeof triggers[trigger_id] ) {
171 triggers[i] = {
172 trigger_id : trigger_id,
173 settings : []
174 };
175 }
176
177 triggers[i].settings.push( $this );
178
179 i += 1;
180 });
181
182 triggers.forEach( function( trigger, i ) {
183 var $trigger = get_trigger( trigger['trigger_id'] ),
184 trigger_idx = $trigger.data( 'trigger_idx' );
185
186 if ( 'undefined' === typeof( trigger_idx ) ) {
187 trigger_idx = [];
188 }
189
190 trigger_idx.push( i );
191
192 $trigger.data( 'trigger_idx', trigger_idx );
193
194 $trigger.on( 'change', on_change );
195
196 $trigger.trigger( 'change' );
197 } );
198 };
199
200 exports.Settings = Settings;
201
202 })( CHARITABLE_ADMIN, jQuery );
203
204 ( function($){
205
206 var setup_license_check = function() {
207 $('#charitable-settings-connect-btn').on( 'click', function( e ){
208 var data = {
209 action : 'charitable_license_check',
210 'license' : $('input[name="license-key"]').val(), // 022effc6d03bdda601503a1dc13672fd
211 'nonce' : $('input[name="_wpnonce"]').val(),
212 'chartiable_action' : $(this).data('action'),
213 };
214
215
216 if ( data.chartiable_action === 'verify' ) {
217 $(this).html('Verifying...');
218 } else {
219 $(this).html('Deactivating...');
220 }
221
222 $(this).prop('disabled', true);
223
224 $.ajax({
225 type: 'POST',
226 data: data,
227 dataType: 'json',
228 url: ajaxurl,
229 xhrFields: {
230 withCredentials: true
231 },
232 success: function (response) {
233 if ( response.success ) {
234
235 if ( response.data.valid === true ) {
236 $('#charitable-license-message').html( response.data.message );
237 if ( 'undefined' === typeof charitable_admin.admin_url ) {
238 window.location.href = charitable_admin.admin_url + 'admin.php?page=charitable-settings&tab=general&valid=valid';
239 } else {
240 location.reload();
241 }
242 } else {
243 $('#charitable-license-message').html( response.data.message );
244
245 if ( 'undefined' !== typeof charitable_admin.admin_url ) {
246
247 if ( response.data.license_limit === true ) {
248
249 window.location.href = charitable_admin.admin_url + 'admin.php?page=charitable-settings&tab=general&valid=invalid&license_limit=true';
250 } else if ( response.data.comm_success === false ) {
251 window.location.href = charitable_admin.admin_url + 'admin.php?page=charitable-settings&tab=general&valid=invalid&comm_success=false';
252 } else if ( data.chartiable_action === 'verify' ) {
253 window.location.href = charitable_admin.admin_url + 'admin.php?page=charitable-settings&tab=general&valid=invalid';
254 } else {
255 window.location.href = charitable_admin.admin_url + 'admin.php?page=charitable-settings&tab=general&valid=success';
256 }
257 } else {
258
259 location.reload();
260 }
261 }
262 }
263 // $user_fields.removeClass( 'loading-data' );
264 }
265 }).fail(function (data) {
266 if ( window.console && window.console.log ) {
267 // console.log( data );
268 // $user_fields.removeClass( 'loading-data' );
269 }
270 });
271
272 return false;
273
274 } );
275 };
276
277 var setup_campaign_end_date_field = function() {
278 $( '#campaign_end_date' ).on( 'change', function() {
279 var $field = $( this ),
280 date = $field.val(),
281 $span = $field.siblings( '.charitable-end-time' ),
282 $input = $field.siblings( '#campaign_end_time' );
283
284 if ( '' === date || ! date ) {
285 $span.hide();
286 $input.val( 0 );
287 } else {
288 $span.text( '@ 23:59 PM' ).show();
289 $input.val( '23:59:59' );
290 }
291 });
292 };
293
294 var setup_charitable_ajax = function() {
295 $('[data-charitable-action]').on( 'click', function( e ){
296 var data = $(this).data( 'charitable-args' ) || {},
297 action = 'charitable-' + $(this).data( 'charitable-action' );
298
299 $.post( ajaxurl,
300 {
301 'action' : action,
302 'data' : data
303 },
304 function( response ) {
305 // console.log( "Response: " + response );
306 }
307 );
308
309 return false;
310 } );
311 };
312
313 var setup_charitable_toggle = function() {
314 $( '[data-charitable-toggle]' ).on( 'click', function( e ){
315 var toggle_id = $(this).data( 'charitable-toggle' ),
316 toggle_text = $(this).attr( 'data-charitable-toggle-text' );
317
318 if ( toggle_text && toggle_text.length ) {
319 $(this).attr( 'data-charitable-toggle-text', $(this).text() );
320 $(this).text( toggle_text );
321 }
322
323 $('#' + toggle_id).toggle();
324
325 return false;
326 } );
327 };
328
329 var setup_advanced_meta_box = function() {
330 var $meta_box = $('#charitable-campaign-advanced-metabox');
331
332 $meta_box.tabs();
333
334 var min_height = $meta_box.find('.charitable-tabs').height();
335
336 $meta_box.find('.ui-tabs-panel').each( function(){
337 $(this).css( 'min-height', min_height );
338 });
339 };
340
341 var toggle_custom_donations_checkbox = function() {
342 var $custom = $('#campaign_allow_custom_donations'),
343 $suggestions = $('.charitable-campaign-suggested-donations tbody tr:not(.to-copy)'),
344 has_suggestions = $suggestions.length > 1 || false === $suggestions.first().hasClass('no-suggested-amounts');
345
346 $custom.prop( 'disabled', ! has_suggestions );
347
348 if ( ! has_suggestions ) {
349 $custom.prop( 'checked', true );
350 }
351 };
352
353 // Suggested Donations (in settings)
354 var setup_sortable_suggested_donations = function(){
355 $('.charitable-campaign-suggested-donations tbody').sortable({
356 items: "tr:not(.to-copy)",
357 handle: ".handle",
358 stop: function( event, ui ) {
359 reindex_rows();
360 }
361
362 });
363 };
364
365 var add_suggested_amount_row = function( $button ) {
366 var $table = $button.closest( '.charitable-campaign-suggested-donations' ).find('tbody');
367 var $clone = $table.find('tr.to-copy').clone().removeClass('to-copy hidden');
368 $table.find( '.no-suggested-amounts' ).hide();
369 $table.append( $clone );
370 reindex_rows();
371 toggle_custom_donations_checkbox();
372 };
373
374 var delete_suggested_amount_row = function($button) {
375
376 $button.closest( 'tr' ).remove();
377 var $table = $button.closest('.charitable-campaign-suggested-donations').find('tbody');
378 if( $table.find( 'tr:not(.to-copy)' ).length == 1 ){
379 $table.find( '.no-suggested-amounts' ).removeClass('hidden').show();
380 }
381 reindex_rows();
382 toggle_custom_donations_checkbox();
383 };
384
385 var reindex_rows = function(){
386 $('.charitable-campaign-suggested-donations tbody').each(function(){
387 $(this).children('tr').not('.no-suggested-amounts .to-copy').each(function(index) {
388
389 $(this).find('input[name="_campaign_suggested_donations_default[]"').val( index );
390 $(this).data('index', index );
391 $(this).find('input').each(function(i) {
392 this.name = this.name.replace(/(\[\d\])/, '[' + index + ']');
393 });
394 });
395 });
396 };
397
398 // Suggested Donations (in left sidebar in preview)
399 var setup_sortable_suggested_donations_mini = function(){
400 $('.charitable-campaign-suggested-donations-mini tbody').sortable({
401 items: "tr:not(.to-copy)",
402 handle: ".handle",
403 stop: function( event, ui ) {
404 reindex_rows_mini();
405 }
406
407 });
408 };
409
410 var reindex_rows_mini = function(){
411 alert('made it');
412 $('.charitable-campaign-suggested-donations-mini tbody').each(function(){
413 $(this).children('tr').not('.no-suggested-amounts .to-copy').each(function(index) {
414
415 $(this).find('input[name="_campaign_suggested_donations_default[]"').val( index );
416 $(this).data('index', index );
417 $(this).find('input').each(function(i) {
418 this.name = this.name.replace(/(\[\d\])/, '[' + index + ']');
419 });
420 });
421 });
422 };
423
424 var setup_dashboard_widgets = function() {
425 var $widget = $( '#charitable_dashboard_donations' );
426
427 if ( $widget.length ) {
428 $.ajax({
429 type: "GET",
430 data: {
431 action: 'charitable_load_dashboard_donations_widget'
432 },
433 url: ajaxurl,
434 success: function (response) {
435 $widget.find( '.inside' ).html( response );
436 }
437 });
438 }
439 };
440
441 var setup_actions_form = function() {
442 var $form = $( '.charitable-actions-form-wrapper' ),
443 $select,
444 $submit,
445 $button;
446
447 if ( ! $form.length ) {
448 return;
449 }
450
451 $select = $form.find( '.charitable-action-select' );
452 $submit = $form.find( '.charitable-actions-submit' );
453 $button = $submit.find( 'button' );
454
455 $submit.hide();
456
457 $select.on( 'change', function() {
458 var action = $select.val(),
459 text = $select.find( 'option:selected' ).data( 'button-text');
460
461 if ( '' === action ) {
462 $submit.hide();
463 return;
464 }
465
466 $form.find( '.charitable-action-fields' ).each( function() {
467 var $el = $( this );
468 $el.toggle( action === $el.data( 'type' ) );
469 });
470
471 if ( text ) {
472 $button.text( text );
473 } else {
474 $button.text( $button.prop( 'title' ) );
475 }
476
477 $submit.show();
478 });
479 }
480
481 var setup_select2 = function() {
482 if ( ! $.fn.select2 ) {
483 return;
484 }
485
486 $( '.select2 select, select.select2' ).select2();
487 }
488
489 var setup_donor_select = function() {
490 var user_fields;
491
492 var get_user_fields = function() {
493 if ( 'object' === typeof user_fields ) {
494 return user_fields;
495 }
496
497 user_fields = [];
498
499 $( '#charitable-user-fields-wrap' ).find( 'select,input,textarea' ).each( function() {
500 user_fields.push(this.name);
501 });
502
503 return user_fields;
504 };
505
506 $( '.charitable-admin-donation-form #donor-id' ).on( 'change', function() {
507 var donor_id = $(this).val(),
508 $user_fields,
509 field;
510
511 if ( '' === donor_id || 'new' === donor_id ) {
512 return;
513 }
514
515 $user_fields = $( '#charitable-user-fields-wrap' );
516 $user_fields.addClass( 'loading-data' );
517
518 data = {
519 action : 'charitable_get_donor_data',
520 donor_id : donor_id,
521 fields : get_user_fields(),
522 nonce : $(this).data( 'nonce' )
523 };
524
525 $.ajax({
526 type: 'POST',
527 data: data,
528 dataType: 'json',
529 url: ajaxurl,
530 xhrFields: {
531 withCredentials: true
532 },
533 success: function (response) {
534 if ( response.success ) {
535 for ( field in response.data ) {
536 $user_fields.find( "[name=" + field + "]" ).val( response.data[field] );
537 }
538 }
539 $user_fields.removeClass( 'loading-data' );
540 }
541 }).fail(function (data) {
542 if ( window.console && window.console.log ) {
543 // console.log( data );
544 $user_fields.removeClass( 'loading-data' );
545 }
546 });
547 });
548 }
549
550 var setup_currency_inputs = function() {
551 if ( 'undefined' === typeof accounting ) {
552 return;
553 }
554
555 var unformat = function( amount ) {
556 return Math.abs( parseFloat( accounting.unformat( amount, CHARITABLE.currency_format_decimal_sep ) ) );
557 }
558
559 var format = function( amount ) {
560 return accounting.formatMoney( amount, {
561 symbol : '',
562 decimal : CHARITABLE.currency_format_decimal_sep,
563 thousand : CHARITABLE.currency_format_thousand_sep,
564 precision : CHARITABLE.currency_format_num_decimals,
565 format : CHARITABLE.currency_format
566 }).trim();
567 }
568
569 $( 'body' ).on( 'change', '.currency-input', function() {
570 var amount = unformat( $( this ).val() );
571
572 if ( $.trim( amount ) > 0 ) {
573 $( this ).val( format( amount ) );
574 }
575 } );
576
577 $( '.currency-input' ).trigger( 'change' );
578 };
579
580 $(document).ready( function(){
581
582 $('body').on( 'click', 'th.default_amount-col a', function( e ) {
583
584 e.stopPropagation();
585
586 $('.default_amount-col input').prop('checked', false);
587
588 $(this).blur();
589
590 });
591
592 // if there are stripe keys already entered, allow fields to be added via ajax to allow user to view/edit them.
593
594 $( 'a#charitable-modify-keys' ).on( 'click', function( e ) {
595
596 e.stopPropagation();
597
598 var link = $(this);
599
600 link.css('pointer-events', 'none');
601 link.css('opacity', '0.25');
602
603 var data = {
604 action : 'charitable-' + $(this).data( 'charitable-action' ),
605 args : $(this).data( 'charitable-args' ),
606 nonce : $(this).data( 'nonce' )
607 };
608
609
610
611 $.ajax({
612 type: "POST",
613 data: data,
614 dataType: "json",
615 url: ajaxurl,
616 xhrFields: {
617 withCredentials: true
618 },
619 success: function (response) {
620
621 link.closest('tr').after( response.data );
622 link.closest('tr').hide();
623 }
624 }).fail(function (data) {
625 if ( window.console && window.console.log ) {
626 // console.log( 'failed' );
627 // console.log( data );
628 link.css('pointer-events', 'all');
629 link.css('opacity', '1.0');
630 }
631 });
632
633 });
634
635
636 if ( CHARITABLE_ADMIN.Datepicker ) {
637 $( '.charitable-datepicker' ).each( function() {
638 CHARITABLE_ADMIN.Datepicker( $(this ) );
639 });
640 }
641
642 /* check for valid dates and valid input on export and filter forms */
643
644 $(document).on( 'click', '#charitable-campaigns-export-modal form button', function( e ) {
645 e.preventDefault();
646 var form_invalid = false;
647 // check all text fields to ensure dates are proper.
648 $('#charitable-campaigns-export-modal form input[type=text]').each(function(){
649 if ( ( $(this).val() ).trim() !== '' ) {
650 isValidDate = dateIsValid( $(this).val() );
651 if ( isValidDate === false ) {
652 form_invalid = true;
653 $(this).val('');
654 }
655 }
656 })
657 if ( form_invalid === true ) {
658 var today = new Date(),
659 dd = ( '0' + today.getDate() ).slice(-2),
660 mm = ( '0' + ( today.getMonth()+1 ) ).slice(-2),
661 yyyy = today.getFullYear();
662 alert ('You have entered an invalid date format. Please use the following format: yyyy/mm/dd. For example: [' + yyyy + '/' + mm + '/' + dd + ']' );
663 } else {
664 $('#charitable-campaigns-export-modal form').submit();
665 }
666 });
667
668 $(document).on( 'click', '#charitable-campaigns-filter-modal form button', function( e ) {
669 e.preventDefault();
670 var form_invalid = false;
671 // check all text fields to ensure dates are proper.
672 $('#charitable-campaigns-filter-modal form input[type=text]').each(function(){
673 if ( ( $(this).val() ).trim() !== '' ) {
674 isValidDate = dateIsValid( $(this).val() );
675 if ( isValidDate === false ) {
676 form_invalid = true;
677 $(this).val('');
678 }
679 }
680 })
681 if ( form_invalid === true ) {
682 var today = new Date(),
683 dd = ( '0' + today.getDate() ).slice(-2),
684 mm = ( '0' + ( today.getMonth()+1 ) ).slice(-2),
685 yyyy = today.getFullYear();
686 alert ('You have entered an invalid date format. Please use the following format: yyyy/mm/dd. For example: [' + yyyy + '/' + mm + '/' + dd + ']' );
687 } else {
688 $('#charitable-campaigns-filter-modal form').submit();
689 }
690 });
691
692 $(document).on( 'click', '#charitable-donations-export-modal form button', function( e ) {
693 e.preventDefault();
694 var form_invalid = false;
695 // check all text fields to ensure dates are proper.
696 $('#charitable-donations-export-modal form input[type=text]').each(function(){
697 if ( ( $(this).val() ).trim() !== '' ) {
698 isValidDate = dateIsValid( $(this).val() );
699 if ( isValidDate === false ) {
700 form_invalid = true;
701 $(this).val('');
702 }
703 }
704 })
705 if ( form_invalid === true ) {
706 var today = new Date(),
707 dd = ( '0' + today.getDate() ).slice(-2),
708 mm = ( '0' + ( today.getMonth()+1 ) ).slice(-2),
709 yyyy = today.getFullYear();
710 alert ('You have entered an invalid date format. Please use the following format: yyyy/mm/dd. For example: [' + yyyy + '/' + mm + '/' + dd + ']' );
711 } else {
712 $('#charitable-donations-export-modal form').submit();
713 }
714 });
715
716 $(document).on( 'click', '#charitable-donations-filter-modal form button', function( e ) {
717 e.preventDefault();
718 var form_invalid = false;
719 // check all text fields to ensure dates are proper.
720 $('#charitable-donations-filter-modal form input[type=text]').each(function(){
721 if ( ( $(this).val() ).trim() !== '' ) {
722 isValidDate = dateIsValid( $(this).val() );
723 if ( isValidDate === false ) {
724 form_invalid = true;
725 $(this).val('');
726 }
727 }
728 })
729 if ( form_invalid === true ) {
730 var today = new Date(),
731 dd = ( '0' + today.getDate() ).slice(-2),
732 mm = ( '0' + ( today.getMonth()+1 ) ).slice(-2),
733 yyyy = today.getFullYear();
734 alert ('You have entered an invalid date format. Please use the following format: yyyy/mm/dd. For example: [' + yyyy + '/' + mm + '/' + dd + ']' );
735 } else {
736 $('#charitable-donations-filter-modal form').submit();
737 }
738 });
739
740 function dateIsValid( date_string ) {
741
742 const regex = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
743
744 if (date_string.match(regex) === null) {
745 return false;
746 }
747
748 const converted_date_string = date_string.replace(/\//g, '-');
749 const date = new Date(converted_date_string);
750 const timestamp = date.getTime();
751 const iso_date_string = date.toISOString();
752
753 if (typeof timestamp !== 'number' || Number.isNaN(timestamp)) {
754 return false;
755 }
756
757 return iso_date_string.startsWith(converted_date_string);
758 }
759
760 $( '#charitable-settings, body.post-type-campaign form#post, body.post-type-donation form#post' ).each( function(){
761 CHARITABLE_ADMIN.Settings( $(this) );
762 });
763
764 $('body.post-type-campaign .handlediv, body.post-type-donation .handlediv').remove();
765 $('body.post-type-campaign .hndle, body.post-type-donation .hndle').removeClass( 'hndle ui-sortable-handle' ).addClass( 'postbox-title' );
766
767 setup_advanced_meta_box();
768 setup_sortable_suggested_donations();
769 setup_sortable_suggested_donations_mini(); // might need to run this again when fields are added/removed
770 toggle_custom_donations_checkbox();
771 setup_charitable_ajax();
772 setup_charitable_toggle();
773 setup_dashboard_widgets();
774 setup_campaign_end_date_field();
775 setup_actions_form();
776 setup_select2();
777 setup_donor_select();
778 setup_currency_inputs();
779 setup_license_check();
780
781 /* view donor history on donation post type pages */
782
783 $(document).on( 'click', 'a.donor-list-view-donations', function( e ) {
784 e.preventDefault();
785 $( 'table.charitable-donor-history-table' ).toggle();
786 $(this).text($(this).text() == 'Hide Donations' ? 'Show Donations' : 'Hide Donations');
787 });
788
789 /* activate color picker on settings pages that need it */
790 if ( $( 'body.charitable_page_charitable-settings input.charitable-color-field' ).length ) {
791 $( 'input.charitable-color-field' ).wpColorPicker();
792 }
793
794 $('[data-charitable-add-row]').on( 'click', function() {
795 var type = $( this ).data( 'charitable-add-row' );
796
797 if ( 'suggested-amount' === type ) {
798 add_suggested_amount_row($(this));
799 }
800
801 return false;
802 });
803
804 $('.charitable-campaign-suggested-donations').on( 'click', '.charitable-delete-row', function() {
805 delete_suggested_amount_row( $(this) );
806 return false;
807 });
808
809 $('body').on( 'click', '[data-campaign-benefactor-delete]', function() {
810 var $block = $( this ).parents( '.charitable-benefactor' ),
811 data = {
812 action : 'charitable_delete_benefactor',
813 benefactor_id : $(this).data( 'campaign-benefactor-delete' ),
814 nonce : $(this).data( 'nonce' )
815 };
816
817 $.ajax({
818 type: "POST",
819 data: data,
820 dataType: "json",
821 url: ajaxurl,
822 xhrFields: {
823 withCredentials: true
824 },
825 success: function (response) {
826 if ( response.deleted ) {
827 $block.remove();
828 }
829 }
830 }).fail(function (data) {
831 if ( window.console && window.console.log ) {
832 // console.log( 'failed' );
833 // console.log( data );
834 }
835 });
836
837 return false;
838 });
839
840 $('#change-donation-status').on( 'change', function() {
841 $(this).parents( 'form' ).submit();
842 });
843
844 if ( $('table.wp-list-table.posts').length > 0 && 'undefined' !== typeof CHARITABLE && null !== CHARITABLE && 'undefined' !== typeof CHARITABLE.banner ) {
845 var banner_html = CHARITABLE.banner,
846 col_count = 0;
847
848 if ( banner_html === false || '' === banner_html) {
849 return;
850 }
851
852 $('table.wp-list-table.posts thead tr:nth-child(1) td').each(function () {
853 if ($(this).attr('colspan')) {
854 col_count += +$(this).attr('colspan');
855 } else {
856 col_count++;
857 }
858 });
859
860
861 $('table.wp-list-table.posts thead tr:nth-child(1) th').each(function () {
862 if ($(this).attr('colspan')) {
863 col_count += +$(this).attr('colspan');
864 } else {
865 col_count++;
866 }
867 });
868
869 $('table.wp-list-table.posts').append('<tr class="child"><td colspan="' + ( col_count ) + '">' + CHARITABLE.banner + '</td></tr>');
870 }
871 });
872
873 })( jQuery );