in AKS-Demos/WordPress-Demo/Code/public/wp-admin/js/edit-comments.js [477:697]
delAfter = function( r, settings ) {
var total_items_i18n, total, animated, animatedCallback,
response = true === settings.parsed ? {} : settings.parsed.responses[0],
commentStatus = true === settings.parsed ? '' : response.supplemental.status,
commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
newTotal = true === settings.parsed ? '' : response.supplemental,
targetParent = $( settings.target ).parent(),
commentRow = $('#' + settings.element),
spamDiff, trashDiff, pendingDiff, approvedDiff,
/*
* As `wpList` toggles only the `unapproved` class, the approved comment
* rows can have both the `approved` and `unapproved` classes.
*/
approved = commentRow.hasClass( 'approved' ) && ! commentRow.hasClass( 'unapproved' ),
unapproved = commentRow.hasClass( 'unapproved' ),
spammed = commentRow.hasClass( 'spam' ),
trashed = commentRow.hasClass( 'trash' ),
undoing = false; // Ticket #35904.
updateDashboardText( newTotal );
updateInModerationText( newTotal );
/*
* 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;
}
}
undoing = true;
// 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 ( pendingDiff ) {
updatePending( pendingDiff, commentPostId );
updateCountText( 'span.all-count', pendingDiff );
}
if ( approvedDiff ) {
updateApproved( approvedDiff, commentPostId );
updateCountText( 'span.all-count', approvedDiff );
}
if ( spamDiff ) {
updateCountText( 'span.spam-count', spamDiff );
}
if ( trashDiff ) {
updateCountText( 'span.trash-count', trashDiff );
}
if (
( ( 'trash' === settings.data.comment_status ) && !getCount( $( 'span.trash-count' ) ) ) ||
( ( 'spam' === settings.data.comment_status ) && !getCount( $( 'span.spam-count' ) ) )
) {
$( '#delete_all' ).hide();
}
if ( ! isDashboard ) {
total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
if ( $(settings.target).parent().is('span.undo') )
total++;
else
total--;
if ( total < 0 )
total = 0;
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.replace( ' ', String.fromCharCode( 160 ) ) );
$('.total-pages').text( response.supplemental.total_pages_i18n.replace( ' ', String.fromCharCode( 160 ) ) );
$('.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 );
}
} else {
updateTotalCount( total, r, false );
}
}
if ( ! theExtraList || theExtraList.length === 0 || theExtraList.children().length === 0 || undoing ) {
return;
}
theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() );
refillTheExtraList();
animated = $( ':animated', '#the-comment-list' );
animatedCallback = function() {
if ( ! $( '#the-comment-list tr:visible' ).length ) {
theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() );
}
};
if ( animated.length ) {
animated.promise().done( animatedCallback );
} else {
animatedCallback();
}
};