Manage Pledge: Enable pledge admins to edit contributors from manage form (#108)

* Add contributor management to manage form
* Check `pledge_id` to prevent returning all contributors
* Return a plain text error string – this is used in an alert box, so it can't contain HTML
* Hide confirmation when pledge is a draft
* Only enqueue script if the user is authorized
This commit is contained in:
Kelly Dwan 2019-11-26 12:57:14 -05:00
parent 286e6d55ef
commit 544fe39199
8 changed files with 110 additions and 18 deletions

View file

@ -1,6 +1,12 @@
/* global ajaxurl, FiveForTheFuture, fftfContributors, jQuery */
/* eslint no-alert: "off" */
jQuery( document ).ready( function( $ ) {
let ajaxurl = window.ajaxurl;
// Set the ajax url if the global is undefined.
if ( 'undefined' === typeof ajaxurl ) {
ajaxurl = FiveForTheFuture.ajaxurl;
}
/**
* Render the contributor lists using the contributors template into the pledge-contributors container. This
* uses `_renderContributors` to render a list of contributors per status (published, pending).
@ -68,6 +74,7 @@ jQuery( document ).ready( function( $ ) {
action: 'manage-contributors',
pledge_id: FiveForTheFuture.pledgeId,
_ajax_nonce: FiveForTheFuture.manageNonce,
_token: FiveForTheFuture.authToken,
}, data ),
success: callback,
dataType: 'json',
@ -83,17 +90,19 @@ jQuery( document ).ready( function( $ ) {
return;
}
// Clear the error message field.
$( '#add-contrib-message' ).html( '' );
sendAjaxRequest( {
contributors: contribs,
manage_action: 'add-contributor',
}, function( response ) {
if ( ! response.success ) {
const $message = $( '<div>' )
.attr( 'id', 'add-contrib-message' )
.addClass( 'notice notice-error notice-alt' )
.append( $( '<p>' ).text( response.message ) );
$( '#add-contrib-message' ).replaceWith( $message );
$( '#add-contrib-message' ).html( $message );
} else if ( response.contributors ) {
render( response.contributors, container );
$( '#5ftf-pledge-contributors' ).val( '' );