mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-04 18:05:45 +03:00
Hook up "Remove" button
This commit is contained in:
parent
d5c740ae84
commit
eacd2bf3f2
4 changed files with 59 additions and 11 deletions
|
@ -1,25 +1,54 @@
|
|||
/* global ajaxurl, FiveForTheFuture_ManageNonce, jQuery */
|
||||
/* global ajaxurl, FiveForTheFuture, jQuery */
|
||||
/* eslint no-alert: "off" */
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
function sendAjaxRequest( data, callback ) {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
data: Object.assign( {
|
||||
action: 'manage_contributors',
|
||||
pledge_id: data.pledgePost || 0,
|
||||
contributor_id: data.contributorPost || 0,
|
||||
manage_action: data.action || '',
|
||||
_ajax_nonce: FiveForTheFuture_ManageNonce,
|
||||
},
|
||||
_ajax_nonce: FiveForTheFuture.manageNonce,
|
||||
}, data ),
|
||||
success: callback,
|
||||
dataType: 'json',
|
||||
} );
|
||||
}
|
||||
|
||||
$( '.contributor-list [data-action="resend-contributor-confirmation"]' ).click( function( event ) {
|
||||
const container = document.getElementById( '5ftf-contributors' );
|
||||
|
||||
// Remove Contributor button action.
|
||||
$( container ).on( 'click', '[data-action="remove-contributor"]', function( event ) {
|
||||
event.preventDefault();
|
||||
sendAjaxRequest( event.currentTarget.dataset, function( response ) {
|
||||
|
||||
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 ) {
|
||||
if ( response.message ) {
|
||||
alert( response.message );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue