Use adminTable to refill #the-extra-comment-list. See #14637

git-svn-id: http://svn.automattic.com/wordpress/trunk@15509 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-08-19 00:06:51 +00:00
parent 071746cc11
commit 196de8fce6
8 changed files with 54 additions and 37 deletions

View File

@ -274,17 +274,6 @@ unset($status_links);
</form> </form>
<form id="get-extra-comments" method="post" action="" class="add:the-extra-comment-list:" style="display: none;">
<input type="hidden" name="s" value="<?php echo esc_attr($search); ?>" />
<input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
<input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
<input type="hidden" name="page" value="<?php echo esc_attr( $table->get_pagination_arg('page') ); ?>" />
<input type="hidden" name="per_page" value="1" />
<input type="hidden" name="p" value="<?php echo esc_attr( $post_id ); ?>" />
<input type="hidden" name="comment_type" value="<?php echo esc_attr( $comment_type ); ?>" />
<?php wp_nonce_field( 'add-comment', '_ajax_nonce', false ); ?>
</form>
<div id="ajax-response"></div> <div id="ajax-response"></div>
<?php } elseif ( 'moderated' == $comment_status ) { ?> <?php } elseif ( 'moderated' == $comment_status ) { ?>

View File

@ -1964,6 +1964,11 @@ class WP_Comments_Table extends WP_List_Table {
$comments_per_page = 20; $comments_per_page = 20;
$comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status ); $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
if ( isset( $_POST['number'] ) )
$number = (int) $_POST['number'];
else
$number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra
$page = $this->get_pagenum(); $page = $this->get_pagenum();
$start = $offset = ( $page - 1 ) * $comments_per_page; $start = $offset = ( $page - 1 ) * $comments_per_page;
@ -1972,7 +1977,7 @@ class WP_Comments_Table extends WP_List_Table {
'status' => ( 'moderated' == $comment_status ) ? 'hold' : $comment_status, // TODO: replace all instances of 'moderated' with 'hold' 'status' => ( 'moderated' == $comment_status ) ? 'hold' : $comment_status, // TODO: replace all instances of 'moderated' with 'hold'
'search' => $search, 'search' => $search,
'offset' => $start, 'offset' => $start,
'number' => $comments_per_page + 8, // Grab a few extra 'number' => $number,
'post_id' => $post_id, 'post_id' => $post_id,
'plural' => $comment_type, 'plural' => $comment_type,
'orderby' => @$_REQUEST['orderby'], 'orderby' => @$_REQUEST['orderby'],
@ -1983,10 +1988,10 @@ class WP_Comments_Table extends WP_List_Table {
update_comment_cache( $_comments ); update_comment_cache( $_comments );
$args['count'] = true; $this->items = array_slice( $_comments, 0, $comments_per_page );
$args['offset'] = 0; $this->extra_items = array_slice( $_comments, $comments_per_page );
$args['number'] = 0;
$total_comments = get_comments( $args ); $total_comments = get_comments( array_merge( $args, array('count' => true, 'offset' => 0, 'number' => 0) ) );
$_comment_post_ids = array(); $_comment_post_ids = array();
foreach ( $_comments as $_c ) { foreach ( $_comments as $_c ) {
@ -1995,9 +2000,6 @@ class WP_Comments_Table extends WP_List_Table {
$_comment_pending_count = get_pending_comments_num( $_comment_post_ids ); $_comment_pending_count = get_pending_comments_num( $_comment_post_ids );
$this->items = array_slice( $_comments, 0, $comments_per_page );
$this->extra_items = array_slice( $_comments, $comments_per_page );
$this->set_pagination_args( array( $this->set_pagination_args( array(
'total_items' => $total_comments, 'total_items' => $total_comments,
'per_page' => $comments_per_page, 'per_page' => $comments_per_page,
@ -2114,10 +2116,10 @@ class WP_Comments_Table extends WP_List_Table {
$this->display_tablenav( 'bottom' ); $this->display_tablenav( 'bottom' );
} }
function display_rows( $items = array() ) { function display_rows( $items = false ) {
global $mode, $comment_status; global $mode, $comment_status;
if ( empty( $items ) ) if ( false === $items )
$items = $this->items; $items = $this->items;
foreach ( $items as $comment ) foreach ( $items as $comment )

View File

@ -1,6 +1,6 @@
jQuery(document).ready(function($) { jQuery(document).ready(function($) {
var adminTable = { window.adminTable = {
init: function() { init: function() {
this.loading = false; this.loading = false;
@ -74,21 +74,31 @@ var adminTable = {
var data = $.query.get(); var data = $.query.get();
data['action'] = 'fetch-list';
data['list_args'] = list_args;
this._callback = callback; this._callback = callback;
this.fetch_list(
data,
$.proxy(this, 'handle_success'),
$.proxy(this, 'handle_error')
);
return true;
},
fetch_list: function(data, success_callback, error_callback) {
data = $.extend(data, {
'action': 'fetch-list',
'list_args': list_args,
});
$.ajax({ $.ajax({
url: ajaxurl, url: ajaxurl,
global: false, global: false,
dataType: 'json', dataType: 'json',
data: data, data: data,
success: $.proxy(this, 'handle_success'), success: success_callback,
error: $.proxy(this, 'handle_error') error: error_callback,
}); });
return true;
}, },
handle_success: function(response) { handle_success: function(response) {

View File

@ -1 +1 @@
jQuery(document).ready(function(b){var a={init:function(){this.loading=false;b("form").each(function(){this.reset()});if(""==b.query.GET("paged")){b.query.SET("paged",1)}this.set_total_pages();this.$tbody=b("#the-list, #the-comment-list");this.$overlay=b('<div id="loading-items>').html(adminTableL10n.loading).hide().prependTo(b("body"))},set_total_pages:function(){this.total_pages=parseInt(b(".total-pages").eq(0).text())},get_total_pages:function(){return this.total_pages},change_page:function(c){if(c<1||c>this.total_pages){return false}this.update_rows({paged:c})},change_search:function(c){this.update_rows({s:c},true,function(){b("h2 .subtitle").remove();if(c){b("h2").eq(0).append(b('<span class="subtitle">').html(adminTableL10n.search.replace("%s",this.htmlencode(c))))}})},htmlencode:function(c){return b("<div/>").text(c).html()},update_rows:function(d,c,g){if(this.loading){return false}var f=false;b.each(d,function(h,i){if(i!=b.query.GET(h)){b.query.SET(h,i);f=true}});if(!f){return false}this.show_overlay();if(c){b.query.SET("paged",1)}var e=b.query.get();e.action="fetch-list";e.list_args=list_args;this._callback=g;b.ajax({url:ajaxurl,global:false,dataType:"json",data:e,success:b.proxy(this,"handle_success"),error:b.proxy(this,"handle_error")});return true},handle_success:function(c){if("object"!=typeof c){this.handle_error()}else{this.hide_overlay();this.$tbody.html(c.rows);b(".displaying-num").html(c.total_items);b(".total-pages").html(c.total_pages);this.set_total_pages();b(".current-page").val(b.query.GET("paged"));if(this._callback){this._callback()}}},handle_error:function(){this.hide_overlay();b("h2").after('<div class="error ajax below-h2"><p>'+adminTableL10n.error+"</p></div>")},show_overlay:function(){this.loading=true;b(".error.ajax").remove();this.$overlay.css({width:this.$tbody.width()+"px",height:this.$tbody.height()-20+"px"}).css(this.$tbody.offset()).show()},hide_overlay:function(){this.loading=false;this.$overlay.hide()}};a.init();b(".tablenav-pages a").click(function(){var c=b.query.GET("paged");switch(b(this).attr("class")){case"first-page":c=1;break;case"prev-page":c-=1;break;case"next-page":c+=1;break;case"last-page":c=a.get_total_pages();break}a.change_page(c);return false});b(".current-page").keypress(function(c){if(13!=c.keyCode){return}a.change_page(parseInt(b(this).val()));return false});b("th a").click(function(){var e=b.query.GET("orderby"),c=b.query.GET("order"),d=b(this).parent("th");if(d.hasClass("sortable")){e=b.query.load(b(this).attr("href")).get("orderby");c="asc";b("th.sorted-desc, th.sorted-asc").removeClass("sorted-asc").removeClass("sorted-desc").addClass("sortable");d.removeClass("sortable").addClass("sorted-asc")}else{if(d.hasClass("sorted-asc")){c="desc";d.removeClass("sorted-asc").addClass("sorted-desc")}else{if(d.hasClass("sorted-desc")){c="asc";d.removeClass("sorted-desc").addClass("sorted-asc")}}}a.update_rows({orderby:e,order:c},true);return false});b(".search-box :submit").click(function(){a.change_search(b(this).parent(".search-box").find(":text").val());return false});b(".search-box :text").keypress(function(c){if(13!=c.keyCode){return}a.change_search(b(this).val());return false});b("#post-query-submit").click(function(){var d,e,c={};b(this).parents(".actions").find('select[name!="action"]').each(function(){var f=b(this);c[f.attr("name")]=f.val()});a.update_rows(c,true);return false});b(".view-switch a").click(function(){var c=b(this);a.update_rows({mode:b.query.load(c.attr("href")).get("mode")},false,function(){b(".view-switch .current").removeClass("current");c.addClass("current")});return false})}); var adminTable;jQuery(document).ready(function(a){adminTable={init:function(){this.loading=false;a("form").each(function(){this.reset()});if(""==a.query.GET("paged")){a.query.SET("paged",1)}this.set_total_pages();this.$tbody=a("#the-list, #the-comment-list");this.$overlay=a('<div id="loading-items>').html(adminTableL10n.loading).hide().prependTo(a("body"))},set_total_pages:function(){this.total_pages=parseInt(a(".total-pages").eq(0).text())},get_total_pages:function(){return this.total_pages},change_page:function(b){if(b<1||b>this.total_pages){return false}this.update_rows({paged:b})},change_search:function(b){this.update_rows({s:b},true,function(){a("h2 .subtitle").remove();if(b){a("h2").eq(0).append(a('<span class="subtitle">').html(adminTableL10n.search.replace("%s",this.htmlencode(b))))}})},htmlencode:function(b){return a("<div/>").text(b).html()},update_rows:function(c,b,f){if(this.loading){return false}var e=false;a.each(c,function(g,h){if(h!=a.query.GET(g)){a.query.SET(g,h);e=true}});if(!e){return false}this.show_overlay();if(b){a.query.SET("paged",1)}var d=a.query.get();this._callback=f;this.fetch_list(d,a.proxy(this,"handle_success"),a.proxy(this,"handle_error"));return true},fetch_list:function(c,d,b){c=a.extend(c,{action:"fetch-list",list_args:list_args,});a.ajax({url:ajaxurl,global:false,dataType:"json",data:c,success:d,error:b,})},handle_success:function(b){if("object"!=typeof b){this.handle_error()}else{this.hide_overlay();this.$tbody.html(b.rows);a(".displaying-num").html(b.total_items);a(".total-pages").html(b.total_pages);this.set_total_pages();a(".current-page").val(a.query.GET("paged"));if(this._callback){this._callback()}}},handle_error:function(){this.hide_overlay();a("h2").after('<div class="error ajax below-h2"><p>'+adminTableL10n.error+"</p></div>")},show_overlay:function(){this.loading=true;a(".error.ajax").remove();this.$overlay.css({width:this.$tbody.width()+"px",height:this.$tbody.height()-20+"px"}).css(this.$tbody.offset()).show()},hide_overlay:function(){this.loading=false;this.$overlay.hide()}};adminTable.init();a(".tablenav-pages a").click(function(){var b=a.query.GET("paged");switch(a(this).attr("class")){case"first-page":b=1;break;case"prev-page":b-=1;break;case"next-page":b+=1;break;case"last-page":b=adminTable.get_total_pages();break}adminTable.change_page(b);return false});a(".current-page").keypress(function(b){if(13!=b.keyCode){return}adminTable.change_page(parseInt(a(this).val()));return false});a("th a").click(function(){var d=a.query.GET("orderby"),b=a.query.GET("order"),c=a(this).parent("th");if(c.hasClass("sortable")){d=a.query.load(a(this).attr("href")).get("orderby");b="asc";a("th.sorted-desc, th.sorted-asc").removeClass("sorted-asc").removeClass("sorted-desc").addClass("sortable");c.removeClass("sortable").addClass("sorted-asc")}else{if(c.hasClass("sorted-asc")){b="desc";c.removeClass("sorted-asc").addClass("sorted-desc")}else{if(c.hasClass("sorted-desc")){b="asc";c.removeClass("sorted-desc").addClass("sorted-asc")}}}adminTable.update_rows({orderby:d,order:b},true);return false});a(".search-box :submit").click(function(){adminTable.change_search(a(this).parent(".search-box").find(":text").val());return false});a(".search-box :text").keypress(function(b){if(13!=b.keyCode){return}adminTable.change_search(a(this).val());return false});a("#post-query-submit").click(function(){var c,d,b={};a(this).parents(".actions").find('select[name!="action"]').each(function(){var e=a(this);b[e.attr("name")]=e.val()});adminTable.update_rows(b,true);return false});a(".view-switch a").click(function(){var b=a(this);adminTable.update_rows({mode:a.query.load(b.attr("href")).get("mode")},false,function(){a(".view-switch .current").removeClass("current");b.addClass("current")});return false})});

View File

@ -209,7 +209,14 @@ setCommentsList = function() {
} }
theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() ); theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() );
$('#get-extra-comments').submit();
// Refill the extra list
var args = $.query.get();
args.number = 1;
args.paged++;
adminTable.fetch_list(args, function(response) {
theExtraList.get(0).wpList.add( response.rows );
});
}; };
theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );

File diff suppressed because one or more lines are too long

View File

@ -259,11 +259,20 @@ wpList = {
e = $(e); e = $(e);
var list = $(this), old = false, _s = { pos: 0, id: 0, oldId: null }, ba, ref, color; var list = $(this), old = false, _s = { pos: 0, id: 0, oldId: null }, ba, ref, color;
if ( 'string' == typeof s ) { s = { what: s }; }
if ( 'string' == typeof s )
s = { what: s };
s = $.extend(_s, this.wpList.settings, s); s = $.extend(_s, this.wpList.settings, s);
if ( !e.size() || !s.what ) { return false; }
if ( s.oldId ) { old = $('#' + s.what + '-' + s.oldId); } if ( !e.size() || !s.what )
if ( s.id && ( s.id != s.oldId || !old || !old.size() ) ) { $('#' + s.what + '-' + s.id).remove(); } return false;
if ( s.oldId )
old = $('#' + s.what + '-' + s.oldId);
if ( s.id && ( s.id != s.oldId || !old || !old.size() ) )
$('#' + s.what + '-' + s.id).remove();
if ( old && old.size() ) { if ( old && old.size() ) {
old.before(e); old.before(e);

View File

@ -265,7 +265,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array('jquery'), '20100301' ); $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array('jquery'), '20100301' );
$scripts->add_data( 'user-profile', 'group', 1 ); $scripts->add_data( 'user-profile', 'group', 1 );
$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '20100418' ); $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'admin-table', 'jquery-ui-resizable', 'quicktags'), '20100818' );
$scripts->add_data( 'admin-comments', 'group', 1 ); $scripts->add_data( 'admin-comments', 'group', 1 );
$scripts->localize( 'admin-comments', 'adminCommentsL10n', array( $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']), 'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),