2019-11-12 23:18:16 +02:00
|
|
|
/* global ajaxurl, FiveForTheFuture, jQuery */
|
2019-11-12 23:17:29 +02:00
|
|
|
/* eslint no-alert: "off" */
|
|
|
|
jQuery( document ).ready( function( $ ) {
|
|
|
|
function sendAjaxRequest( data, callback ) {
|
|
|
|
$.ajax( {
|
|
|
|
type: 'POST',
|
|
|
|
url: ajaxurl,
|
2019-11-12 23:18:16 +02:00
|
|
|
data: Object.assign( {
|
2019-11-12 23:17:29 +02:00
|
|
|
action: 'manage_contributors',
|
2019-11-12 23:18:16 +02:00
|
|
|
_ajax_nonce: FiveForTheFuture.manageNonce,
|
|
|
|
}, data ),
|
2019-11-12 23:17:29 +02:00
|
|
|
success: callback,
|
|
|
|
dataType: 'json',
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2019-11-12 23:18:16 +02:00
|
|
|
const container = document.getElementById( '5ftf-contributors' );
|
|
|
|
|
|
|
|
// Remove Contributor button action.
|
|
|
|
$( container ).on( 'click', '[data-action="remove-contributor"]', function( event ) {
|
2019-11-12 23:17:29 +02:00
|
|
|
event.preventDefault();
|
2019-11-12 23:18:16 +02:00
|
|
|
|
|
|
|
const confirmMsg = event.currentTarget.dataset.confirm;
|
|
|
|
if ( confirmMsg && confirm( confirmMsg ) ) {
|
|
|
|
const data = event.currentTarget.dataset;
|
|
|
|
|
|
|
|
sendAjaxRequest( {
|
|
|
|
pledge_id: data.pledgePost || 0,
|
|
|
|
contributor_id: data.contributorPost || 0,
|
|
|
|
manage_action: data.action || '',
|
|
|
|
}, function( response ) {
|
|
|
|
if ( response.message ) {
|
|
|
|
alert( response.message );
|
|
|
|
}
|
|
|
|
if ( response.success ) {
|
|
|
|
$( event.currentTarget ).closest( 'li' ).remove();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Resend Contributor Confirmation button action.
|
|
|
|
$( container ).on( 'click', '[data-action="resend-contributor-confirmation"]', function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
const data = event.currentTarget.dataset;
|
|
|
|
|
|
|
|
sendAjaxRequest( {
|
|
|
|
pledge_id: data.pledgePost || 0,
|
|
|
|
contributor_id: data.contributorPost || 0,
|
|
|
|
manage_action: data.action || '',
|
|
|
|
}, function( response ) {
|
2019-11-12 23:17:29 +02:00
|
|
|
if ( response.message ) {
|
|
|
|
alert( response.message );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|