PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.14
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.14
1.8.13.1 1.8.13 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 All 212 releases
charitable / assets / js / charitable-admin.js

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

817 lines 22.1 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 var setup_sortable_suggested_donations = function(){
354 $('.charitable-campaign-suggested-donations tbody').sortable({
355 items: "tr:not(.to-copy)",
356 handle: ".handle",
357 stop: function( event, ui ) {
358 reindex_rows();
359 }
360
361 });
362 };
363
364 var add_suggested_amount_row = function( $button ) {
365 var $table = $button.closest( '.charitable-campaign-suggested-donations' ).find('tbody');
366 var $clone = $table.find('tr.to-copy').clone().removeClass('to-copy hidden');
367 $table.find( '.no-suggested-amounts' ).hide();
368 $table.append( $clone );
369 reindex_rows();
370 toggle_custom_donations_checkbox();
371 };
372
373 var delete_suggested_amount_row = function($button) {
374
375 $button.closest( 'tr' ).remove();
376 var $table = $button.closest('.charitable-campaign-suggested-donations').find('tbody');
377 if( $table.find( 'tr:not(.to-copy)' ).length == 1 ){
378 $table.find( '.no-suggested-amounts' ).removeClass('hidden').show();
379 }
380 reindex_rows();
381 toggle_custom_donations_checkbox();
382 };
383
384 var reindex_rows = function(){
385 $('.charitable-campaign-suggested-donations tbody').each(function(){
386 $(this).children('tr').not('.no-suggested-amounts .to-copy').each(function(index) {
387
388 $(this).find('input[name="_campaign_suggested_donations_default[]"').val( index );
389 $(this).data('index', index );
390 $(this).find('input').each(function(i) {
391 this.name = this.name.replace(/(\[\d\])/, '[' + index + ']');
392 });
393 });
394 });
395 };
396
397 var setup_dashboard_widgets = function() {
398 var $widget = $( '#charitable_dashboard_donations' );
399
400 if ( $widget.length ) {
401 $.ajax({
402 type: "GET",
403 data: {
404 action: 'charitable_load_dashboard_donations_widget'
405 },
406 url: ajaxurl,
407 success: function (response) {
408 $widget.find( '.inside' ).html( response );
409 }
410 });
411 }
412 };
413
414 var setup_actions_form = function() {
415 var $form = $( '.charitable-actions-form-wrapper' ),
416 $select,
417 $submit,
418 $button;
419
420 if ( ! $form.length ) {
421 return;
422 }
423
424 $select = $form.find( '.charitable-action-select' );
425 $submit = $form.find( '.charitable-actions-submit' );
426 $button = $submit.find( 'button' );
427
428 $submit.hide();
429
430 $select.on( 'change', function() {
431 var action = $select.val(),
432 text = $select.find( 'option:selected' ).data( 'button-text');
433
434 if ( '' === action ) {
435 $submit.hide();
436 return;
437 }
438
439 $form.find( '.charitable-action-fields' ).each( function() {
440 var $el = $( this );
441 $el.toggle( action === $el.data( 'type' ) );
442 });
443
444 if ( text ) {
445 $button.text( text );
446 } else {
447 $button.text( $button.prop( 'title' ) );
448 }
449
450 $submit.show();
451 });
452 }
453
454 var setup_select2 = function() {
455 if ( ! $.fn.select2 ) {
456 return;
457 }
458
459 $( '.select2 select, select.select2' ).select2();
460 }
461
462 var setup_donor_select = function() {
463 var user_fields;
464
465 var get_user_fields = function() {
466 if ( 'object' === typeof user_fields ) {
467 return user_fields;
468 }
469
470 user_fields = [];
471
472 $( '#charitable-user-fields-wrap' ).find( 'select,input,textarea' ).each( function() {
473 user_fields.push(this.name);
474 });
475
476 return user_fields;
477 };
478
479 $( '.charitable-admin-donation-form #donor-id' ).on( 'change', function() {
480 var donor_id = $(this).val(),
481 $user_fields,
482 field;
483
484 if ( '' === donor_id || 'new' === donor_id ) {
485 return;
486 }
487
488 $user_fields = $( '#charitable-user-fields-wrap' );
489 $user_fields.addClass( 'loading-data' );
490
491 data = {
492 action : 'charitable_get_donor_data',
493 donor_id : donor_id,
494 fields : get_user_fields(),
495 nonce : $(this).data( 'nonce' )
496 };
497
498 $.ajax({
499 type: 'POST',
500 data: data,
501 dataType: 'json',
502 url: ajaxurl,
503 xhrFields: {
504 withCredentials: true
505 },
506 success: function (response) {
507 if ( response.success ) {
508 for ( field in response.data ) {
509 $user_fields.find( "[name=" + field + "]" ).val( response.data[field] );
510 }
511 }
512 $user_fields.removeClass( 'loading-data' );
513 }
514 }).fail(function (data) {
515 if ( window.console && window.console.log ) {
516 // console.log( data );
517 $user_fields.removeClass( 'loading-data' );
518 }
519 });
520 });
521 }
522
523 var setup_currency_inputs = function() {
524 if ( 'undefined' === typeof accounting ) {
525 return;
526 }
527
528 var unformat = function( amount ) {
529 return Math.abs( parseFloat( accounting.unformat( amount, CHARITABLE.currency_format_decimal_sep ) ) );
530 }
531
532 var format = function( amount ) {
533 return accounting.formatMoney( amount, {
534 symbol : '',
535 decimal : CHARITABLE.currency_format_decimal_sep,
536 thousand : CHARITABLE.currency_format_thousand_sep,
537 precision : CHARITABLE.currency_format_num_decimals,
538 format : CHARITABLE.currency_format
539 }).trim();
540 }
541
542 $( 'body' ).on( 'change', '.currency-input', function() {
543 var amount = unformat( $( this ).val() );
544
545 if ( $.trim( amount ) > 0 ) {
546 $( this ).val( format( amount ) );
547 }
548 } );
549
550 $( '.currency-input' ).trigger( 'change' );
551 };
552
553 $(document).ready( function(){
554
555 $('body').on( 'click', 'th.default_amount-col a', function( e ) {
556
557 e.stopPropagation();
558
559 $('.default_amount-col input').prop('checked', false);
560
561 $(this).blur();
562
563 });
564
565 // if there are stripe keys already entered, allow fields to be added via ajax to allow user to view/edit them.
566
567 $( 'a#charitable-modify-keys' ).on( 'click', function( e ) {
568
569 e.stopPropagation();
570
571 var link = $(this);
572
573 link.css('pointer-events', 'none');
574 link.css('opacity', '0.25');
575
576 var data = {
577 action : 'charitable-' + $(this).data( 'charitable-action' ),
578 args : $(this).data( 'charitable-args' ),
579 nonce : $(this).data( 'nonce' )
580 };
581
582
583
584 $.ajax({
585 type: "POST",
586 data: data,
587 dataType: "json",
588 url: ajaxurl,
589 xhrFields: {
590 withCredentials: true
591 },
592 success: function (response) {
593
594 link.closest('tr').after( response.data );
595 link.closest('tr').hide();
596 }
597 }).fail(function (data) {
598 if ( window.console && window.console.log ) {
599 // console.log( 'failed' );
600 // console.log( data );
601 link.css('pointer-events', 'all');
602 link.css('opacity', '1.0');
603 }
604 });
605
606 });
607
608
609 if ( CHARITABLE_ADMIN.Datepicker ) {
610 $( '.charitable-datepicker' ).each( function() {
611 CHARITABLE_ADMIN.Datepicker( $(this ) );
612 });
613 }
614
615 /* check for valid dates and valid input on export and filter forms */
616
617 $(document).on( 'click', '#charitable-campaigns-export-modal form button', function( e ) {
618 e.preventDefault();
619 var form_invalid = false;
620 // check all text fields to ensure dates are proper.
621 $('#charitable-campaigns-export-modal form input[type=text]').each(function(){
622 if ( ( $(this).val() ).trim() !== '' ) {
623 isValidDate = dateIsValid( $(this).val() );
624 if ( isValidDate === false ) {
625 form_invalid = true;
626 $(this).val('');
627 }
628 }
629 })
630 if ( form_invalid === true ) {
631 var today = new Date(),
632 dd = ( '0' + today.getDate() ).slice(-2),
633 mm = ( '0' + ( today.getMonth()+1 ) ).slice(-2),
634 yyyy = today.getFullYear();
635 alert ('You have entered an invalid date format. Please use the following format: yyyy/mm/dd. For example: [' + yyyy + '/' + mm + '/' + dd + ']' );
636 } else {
637 $('#charitable-campaigns-export-modal form').submit();
638 }
639 });
640
641 $(document).on( 'click', '#charitable-campaigns-filter-modal form button', function( e ) {
642 e.preventDefault();
643 var form_invalid = false;
644 // check all text fields to ensure dates are proper.
645 $('#charitable-campaigns-filter-modal form input[type=text]').each(function(){
646 if ( ( $(this).val() ).trim() !== '' ) {
647 isValidDate = dateIsValid( $(this).val() );
648 if ( isValidDate === false ) {
649 form_invalid = true;
650 $(this).val('');
651 }
652 }
653 })
654 if ( form_invalid === true ) {
655 var today = new Date(),
656 dd = ( '0' + today.getDate() ).slice(-2),
657 mm = ( '0' + ( today.getMonth()+1 ) ).slice(-2),
658 yyyy = today.getFullYear();
659 alert ('You have entered an invalid date format. Please use the following format: yyyy/mm/dd. For example: [' + yyyy + '/' + mm + '/' + dd + ']' );
660 } else {
661 $('#charitable-campaigns-filter-modal form').submit();
662 }
663 });
664
665 $(document).on( 'click', '#charitable-donations-export-modal form button', function( e ) {
666 e.preventDefault();
667 var form_invalid = false;
668 // check all text fields to ensure dates are proper.
669 $('#charitable-donations-export-modal form input[type=text]').each(function(){
670 if ( ( $(this).val() ).trim() !== '' ) {
671 isValidDate = dateIsValid( $(this).val() );
672 if ( isValidDate === false ) {
673 form_invalid = true;
674 $(this).val('');
675 }
676 }
677 })
678 if ( form_invalid === true ) {
679 var today = new Date(),
680 dd = ( '0' + today.getDate() ).slice(-2),
681 mm = ( '0' + ( today.getMonth()+1 ) ).slice(-2),
682 yyyy = today.getFullYear();
683 alert ('You have entered an invalid date format. Please use the following format: yyyy/mm/dd. For example: [' + yyyy + '/' + mm + '/' + dd + ']' );
684 } else {
685 $('#charitable-donations-export-modal form').submit();
686 }
687 });
688
689 $(document).on( 'click', '#charitable-donations-filter-modal form button', function( e ) {
690 e.preventDefault();
691 var form_invalid = false;
692 // check all text fields to ensure dates are proper.
693 $('#charitable-donations-filter-modal form input[type=text]').each(function(){
694 if ( ( $(this).val() ).trim() !== '' ) {
695 isValidDate = dateIsValid( $(this).val() );
696 if ( isValidDate === false ) {
697 form_invalid = true;
698 $(this).val('');
699 }
700 }
701 })
702 if ( form_invalid === true ) {
703 var today = new Date(),
704 dd = ( '0' + today.getDate() ).slice(-2),
705 mm = ( '0' + ( today.getMonth()+1 ) ).slice(-2),
706 yyyy = today.getFullYear();
707 alert ('You have entered an invalid date format. Please use the following format: yyyy/mm/dd. For example: [' + yyyy + '/' + mm + '/' + dd + ']' );
708 } else {
709 $('#charitable-donations-filter-modal form').submit();
710 }
711 });
712
713 function dateIsValid( date_string ) {
714
715 const regex = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
716
717 if (date_string.match(regex) === null) {
718 return false;
719 }
720
721 const converted_date_string = date_string.replace(/\//g, '-');
722 const date = new Date(converted_date_string);
723 const timestamp = date.getTime();
724 const iso_date_string = date.toISOString();
725
726 if (typeof timestamp !== 'number' || Number.isNaN(timestamp)) {
727 return false;
728 }
729
730 return iso_date_string.startsWith(converted_date_string);
731 }
732
733 $( '#charitable-settings, body.post-type-campaign form#post, body.post-type-donation form#post' ).each( function(){
734 CHARITABLE_ADMIN.Settings( $(this) );
735 });
736
737 $('body.post-type-campaign .handlediv, body.post-type-donation .handlediv').remove();
738 $('body.post-type-campaign .hndle, body.post-type-donation .hndle').removeClass( 'hndle ui-sortable-handle' ).addClass( 'postbox-title' );
739
740 setup_advanced_meta_box();
741 setup_sortable_suggested_donations();
742 toggle_custom_donations_checkbox();
743 setup_charitable_ajax();
744 setup_charitable_toggle();
745 setup_dashboard_widgets();
746 setup_campaign_end_date_field();
747 setup_actions_form();
748 setup_select2();
749 setup_donor_select();
750 setup_currency_inputs();
751 setup_license_check();
752
753 /* view donor history on donation post type pages */
754
755 $(document).on( 'click', 'a.donor-list-view-donations', function( e ) {
756 e.preventDefault();
757 $( 'table.charitable-donor-history-table' ).toggle();
758 $(this).text($(this).text() == 'Hide Donations' ? 'Show Donations' : 'Hide Donations');
759 });
760
761 /* activate color picker on settings pages that need it */
762 if ( $( 'body.charitable_page_charitable-settings input.charitable-color-field' ).length ) {
763 $( 'input.charitable-color-field' ).wpColorPicker();
764 }
765
766 $('[data-charitable-add-row]').on( 'click', function() {
767 var type = $( this ).data( 'charitable-add-row' );
768
769 if ( 'suggested-amount' === type ) {
770 add_suggested_amount_row($(this));
771 }
772
773 return false;
774 });
775
776 $('.charitable-campaign-suggested-donations').on( 'click', '.charitable-delete-row', function() {
777 delete_suggested_amount_row( $(this) );
778 return false;
779 });
780
781 $('body').on( 'click', '[data-campaign-benefactor-delete]', function() {
782 var $block = $( this ).parents( '.charitable-benefactor' ),
783 data = {
784 action : 'charitable_delete_benefactor',
785 benefactor_id : $(this).data( 'campaign-benefactor-delete' ),
786 nonce : $(this).data( 'nonce' )
787 };
788
789 $.ajax({
790 type: "POST",
791 data: data,
792 dataType: "json",
793 url: ajaxurl,
794 xhrFields: {
795 withCredentials: true
796 },
797 success: function (response) {
798 if ( response.deleted ) {
799 $block.remove();
800 }
801 }
802 }).fail(function (data) {
803 if ( window.console && window.console.log ) {
804 // console.log( 'failed' );
805 // console.log( data );
806 }
807 });
808
809 return false;
810 });
811
812 $('#change-donation-status').on( 'change', function() {
813 $(this).parents( 'form' ).submit();
814 });
815 });
816
817 })( jQuery );