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:
@@ -12,6 +12,7 @@ setCommentsList = function() {
|
||||
perPageInput = $('input[name="_per_page"]', '#comments-form');
|
||||
pageInput = $('input[name="_page"]', '#comments-form');
|
||||
|
||||
// this fires when viewing "All"
|
||||
dimAfter = function( r, settings ) {
|
||||
var editRow, replyID, replyButton,
|
||||
c = $( '#' + settings.element );
|
||||
@@ -34,6 +35,7 @@ setCommentsList = function() {
|
||||
|
||||
diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
|
||||
updatePending( diff );
|
||||
updateCountText( 'span.approved-count', -1 * diff );
|
||||
};
|
||||
|
||||
// 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
|
||||
delAfter = function( r, settings ) {
|
||||
var total_items_i18n, total, spam, trash, pending,
|
||||
untrash = $(settings.target).parent().is('span.untrash'),
|
||||
unspam = $(settings.target).parent().is('span.unspam'),
|
||||
unapproved = $('#' + settings.element).is('.unapproved');
|
||||
var total_items_i18n, total,
|
||||
response = true === settings.parsed ? {} : settings.parsed.responses[0],
|
||||
commentStatus = true === settings.parsed ? '' : response.supplemental.status,
|
||||
|
||||
function getUpdate(s) {
|
||||
if ( $(settings.target).parent().is('span.' + s) )
|
||||
return 1;
|
||||
else if ( $('#' + settings.element).is('.' + s) )
|
||||
return -1;
|
||||
targetParent = $( settings.target ).parent(),
|
||||
commentRow = $('#' + settings.element),
|
||||
|
||||
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 )
|
||||
trash = -1;
|
||||
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 ( pendingDiff ) {
|
||||
updatePending( pendingDiff );
|
||||
}
|
||||
|
||||
if ( pending )
|
||||
updatePending(pending);
|
||||
if ( approvedDiff ) {
|
||||
updateCountText( 'span.approved-count', approvedDiff );
|
||||
}
|
||||
|
||||
$('span.spam-count').each( function() {
|
||||
var a = $(this), n = getCount(a) + spam;
|
||||
updateCount(a, n);
|
||||
});
|
||||
if ( spamDiff ) {
|
||||
updateCountText( 'span.spam-count', spamDiff );
|
||||
}
|
||||
|
||||
$('span.trash-count').each( function() {
|
||||
var a = $(this), n = getCount(a) + trash;
|
||||
updateCount(a, n);
|
||||
});
|
||||
if ( trashDiff ) {
|
||||
updateCountText( 'span.trash-count', trashDiff );
|
||||
}
|
||||
|
||||
if ( ! $('#dashboard_right_now').length ) {
|
||||
total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
|
||||
@@ -195,20 +310,24 @@ setCommentsList = function() {
|
||||
if ( total < 0 )
|
||||
total = 0;
|
||||
|
||||
if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
|
||||
total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
|
||||
if ( total_items_i18n ) {
|
||||
$('.displaying-num').text( total_items_i18n );
|
||||
$('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
|
||||
$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
|
||||
if ( 'object' === typeof r ) {
|
||||
if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) {
|
||||
total_items_i18n = response.supplemental.total_items_i18n || '';
|
||||
if ( total_items_i18n ) {
|
||||
$('.displaying-num').text( total_items_i18n );
|
||||
$('.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 {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user