Comments List Table:

* Show count next to "Approved"
* Properly increment/decrement counts when row actions are clicked
* In `_wp_ajax_delete_comment_response()`, return the comment's `status` with the `supplemental` data
* Handle counts properly on each scenario of `undo`

See #11200.

Built from https://develop.svn.wordpress.org/trunk@33655


git-svn-id: http://core.svn.wordpress.org/trunk@33622 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-08-20 02:51:25 +00:00
parent 572a0a587a
commit df618f3461
5 changed files with 184 additions and 50 deletions

View File

@ -347,8 +347,21 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
$url = isset( $_POST['_url'] ) ? esc_url_raw( $_POST['_url'] ) : ''; $url = isset( $_POST['_url'] ) ? esc_url_raw( $_POST['_url'] ) : '';
// JS didn't send us everything we need to know. Just die with success message // JS didn't send us everything we need to know. Just die with success message
if ( !$total || !$per_page || !$page || !$url ) if ( ! $total || ! $per_page || ! $page || ! $url ) {
wp_die( time() ); $time = time();
$comment = get_comment( $comment_id );
$x = new WP_Ajax_Response( array(
'what' => 'comment',
// Here for completeness - not used.
'id' => $comment_id,
'supplemental' => array(
'status' => $comment ? $comment->comment_approved : '',
'time' => $time
)
) );
$x->send();
}
$total += $delta; $total += $delta;
if ( $total < 0 ) if ( $total < 0 )
@ -377,12 +390,14 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
// The time since the last comment count. // The time since the last comment count.
$time = time(); $time = time();
$comment = get_comment( $comment_id );
$x = new WP_Ajax_Response( array( $x = new WP_Ajax_Response( array(
'what' => 'comment', 'what' => 'comment',
// Here for completeness - not used. // Here for completeness - not used.
'id' => $comment_id, 'id' => $comment_id,
'supplemental' => array( 'supplemental' => array(
'status' => $comment ? $comment->comment_approved : '',
'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ), 'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
'total_pages' => ceil( $total / $per_page ), 'total_pages' => ceil( $total / $per_page ),
'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ), 'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),

View File

@ -198,7 +198,7 @@ class WP_Comments_List_Table extends WP_List_Table {
$stati = array( $stati = array(
'all' => _nx_noop('All', 'All', 'comments'), // singular not used 'all' => _nx_noop('All', 'All', 'comments'), // singular not used
'moderated' => _n_noop('Pending <span class="count">(<span class="pending-count">%s</span>)</span>', 'Pending <span class="count">(<span class="pending-count">%s</span>)</span>'), 'moderated' => _n_noop('Pending <span class="count">(<span class="pending-count">%s</span>)</span>', 'Pending <span class="count">(<span class="pending-count">%s</span>)</span>'),
'approved' => _n_noop('Approved', 'Approved'), // singular not used 'approved' => _n_noop('Approved <span class="count">(<span class="approved-count">%s</span>)</span>', 'Approved <span class="count">(<span class="approved-count">%s</span>)</span>'),
'spam' => _n_noop('Spam <span class="count">(<span class="spam-count">%s</span>)</span>', 'Spam <span class="count">(<span class="spam-count">%s</span>)</span>'), 'spam' => _n_noop('Spam <span class="count">(<span class="spam-count">%s</span>)</span>', 'Spam <span class="count">(<span class="spam-count">%s</span>)</span>'),
'trash' => _n_noop('Trash <span class="count">(<span class="trash-count">%s</span>)</span>', 'Trash <span class="count">(<span class="trash-count">%s</span>)</span>') 'trash' => _n_noop('Trash <span class="count">(<span class="trash-count">%s</span>)</span>', 'Trash <span class="count">(<span class="trash-count">%s</span>)</span>')
); );

View File

@ -12,6 +12,7 @@ setCommentsList = function() {
perPageInput = $('input[name="_per_page"]', '#comments-form'); perPageInput = $('input[name="_per_page"]', '#comments-form');
pageInput = $('input[name="_page"]', '#comments-form'); pageInput = $('input[name="_page"]', '#comments-form');
// this fires when viewing "All"
dimAfter = function( r, settings ) { dimAfter = function( r, settings ) {
var editRow, replyID, replyButton, var editRow, replyID, replyButton,
c = $( '#' + settings.element ); c = $( '#' + settings.element );
@ -34,6 +35,7 @@ setCommentsList = function() {
diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
updatePending( diff ); updatePending( diff );
updateCountText( 'span.approved-count', -1 * diff );
}; };
// Send current total, page, per_page and url // Send current total, page, per_page and url
@ -137,53 +139,166 @@ setCommentsList = function() {
}); });
}; };
updateCountText = function( selector, diff ) {
$( selector ).each(function() {
var a = $(this), n = getCount(a) + diff;
if ( n < 1 ) {
n = 0;
}
updateCount( a, n );
});
};
// In admin-ajax.php, we send back the unix time stamp instead of 1 on success // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
delAfter = function( r, settings ) { delAfter = function( r, settings ) {
var total_items_i18n, total, spam, trash, pending, var total_items_i18n, total,
untrash = $(settings.target).parent().is('span.untrash'), response = true === settings.parsed ? {} : settings.parsed.responses[0],
unspam = $(settings.target).parent().is('span.unspam'), commentStatus = true === settings.parsed ? '' : response.supplemental.status,
unapproved = $('#' + settings.element).is('.unapproved');
function getUpdate(s) { targetParent = $( settings.target ).parent(),
if ( $(settings.target).parent().is('span.' + s) ) commentRow = $('#' + settings.element),
return 1;
else if ( $('#' + settings.element).is('.' + s) )
return -1;
return 0; spamDiff, trashDiff, pendingDiff, approvedDiff,
approved = commentRow.hasClass( 'approved' ),
unapproved = commentRow.hasClass( 'unapproved' ),
spammed = commentRow.hasClass( 'spam' ),
trashed = commentRow.hasClass( 'trash' );
// the order of these checks is important
// .unspam can also have .approve or .unapprove
// .untrash can also have .approve or .unapprove
if ( targetParent.is( 'span.undo' ) ) {
// the comment was spammed
if ( targetParent.hasClass( 'unspam' ) ) {
spamDiff = -1;
if ( 'trash' === commentStatus ) {
trashDiff = 1;
} else if ( '1' === commentStatus ) {
approvedDiff = 1;
} else if ( '0' === commentStatus ) {
pendingDiff = 1;
}
// the comment was trashed
} else if ( targetParent.hasClass( 'untrash' ) ) {
trashDiff = -1;
if ( 'spam' === commentStatus ) {
spamDiff = 1;
} else if ( '1' === commentStatus ) {
approvedDiff = 1;
} else if ( '0' === commentStatus ) {
pendingDiff = 1;
}
}
// user clicked "Spam"
} else if ( targetParent.is( 'span.spam' ) ) {
// the comment is currently approved
if ( approved ) {
approvedDiff = -1;
// the comment is currently pending
} else if ( unapproved ) {
pendingDiff = -1;
// the comment was in the trash
} else if ( trashed ) {
trashDiff = -1;
}
// you can't spam an item on the spam screen
spamDiff = 1;
// user clicked "Unspam"
} else if ( targetParent.is( 'span.unspam' ) ) {
if ( approved ) {
pendingDiff = 1;
} else if ( unapproved ) {
approvedDiff = 1;
} else if ( trashed ) {
// the comment was previously approved
if ( targetParent.hasClass( 'approve' ) ) {
approvedDiff = 1;
// the comment was previously pending
} else if ( targetParent.hasClass( 'unapprove' ) ) {
pendingDiff = 1;
}
} else if ( spammed ) {
if ( targetParent.hasClass( 'approve' ) ) {
approvedDiff = 1;
} else if ( targetParent.hasClass( 'unapprove' ) ) {
pendingDiff = 1;
}
}
// you can Unspam an item on the spam screen
spamDiff = -1;
// user clicked "Trash"
} else if ( targetParent.is( 'span.trash' ) ) {
if ( approved ) {
approvedDiff = -1;
} else if ( unapproved ) {
pendingDiff = -1;
// the comment was in the spam queue
} else if ( spammed ) {
spamDiff = -1;
}
// you can't trash an item on the trash screen
trashDiff = 1;
// user clicked "Restore"
} else if ( targetParent.is( 'span.untrash' ) ) {
if ( approved ) {
pendingDiff = 1;
} else if ( unapproved ) {
approvedDiff = 1;
} else if ( trashed ) {
if ( targetParent.hasClass( 'approve' ) ) {
approvedDiff = 1;
} else if ( targetParent.hasClass( 'unapprove' ) ) {
pendingDiff = 1;
}
}
// you can't go from trash to spam
// you can untrash on the trash screen
trashDiff = -1;
// User clicked "Approve"
} else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) {
approvedDiff = 1;
pendingDiff = -1;
// User clicked "Unapprove"
} else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) {
approvedDiff = -1;
pendingDiff = 1;
// User clicked "Delete Permanently"
} else if ( targetParent.is( 'span.delete' ) ) {
if ( spammed ) {
spamDiff = -1;
} else if ( trashed ) {
trashDiff = -1;
}
} }
if ( untrash ) if ( pendingDiff ) {
trash = -1; updatePending( pendingDiff );
else
trash = getUpdate('trash');
if ( unspam )
spam = -1;
else
spam = getUpdate('spam');
if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) {
// a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending,
// or a trash/spam of a pending comment was undone
pending = 1;
} else if ( unapproved ) {
// a pending comment was trashed/spammed/approved
pending = -1;
} }
if ( pending ) if ( approvedDiff ) {
updatePending(pending); updateCountText( 'span.approved-count', approvedDiff );
}
$('span.spam-count').each( function() { if ( spamDiff ) {
var a = $(this), n = getCount(a) + spam; updateCountText( 'span.spam-count', spamDiff );
updateCount(a, n); }
});
$('span.trash-count').each( function() { if ( trashDiff ) {
var a = $(this), n = getCount(a) + trash; updateCountText( 'span.trash-count', trashDiff );
updateCount(a, n); }
});
if ( ! $('#dashboard_right_now').length ) { if ( ! $('#dashboard_right_now').length ) {
total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
@ -195,20 +310,24 @@ setCommentsList = function() {
if ( total < 0 ) if ( total < 0 )
total = 0; total = 0;
if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { if ( 'object' === typeof r ) {
total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || ''; if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) {
if ( total_items_i18n ) { total_items_i18n = response.supplemental.total_items_i18n || '';
$('.displaying-num').text( total_items_i18n ); if ( total_items_i18n ) {
$('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n ); $('.displaying-num').text( total_items_i18n );
$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val()); $('.total-pages').text( response.supplemental.total_pages_i18n );
$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val());
}
updateTotalCount( total, response.supplemental.time, true );
} else if ( response.supplemental.time ) {
updateTotalCount( total, response.supplemental.time, false );
} }
updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
} else { } else {
updateTotalCount( total, r, false ); updateTotalCount( total, r, false );
} }
} }
if ( ! theExtraList || theExtraList.size() === 0 || theExtraList.children().size() === 0 || untrash || unspam ) { if ( ! theExtraList || theExtraList.size() === 0 || theExtraList.children().size() === 0 ) {
return; return;
} }

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-alpha-33654'; $wp_version = '4.4-alpha-33655';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.