From 7c5fd789ac8debef4ebd3885b23cc49b83a5385d Mon Sep 17 00:00:00 2001 From: nacin Date: Wed, 12 Jan 2011 17:06:33 +0000 Subject: [PATCH] Keep sorting and paging for bulk actions. props garyc40, see #16166. git-svn-id: http://svn.automattic.com/wordpress/trunk@17270 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-comments.php | 2 +- wp-admin/edit-tags.php | 2 ++ wp-admin/edit.php | 2 +- wp-admin/includes/class-wp-list-table.php | 38 +++++++++++++++++------ wp-admin/js/list-table.dev.js | 7 ++++- wp-admin/js/list-table.js | 2 +- wp-admin/upload.php | 2 ++ wp-includes/script-loader.php | 2 +- 8 files changed, 42 insertions(+), 15 deletions(-) diff --git a/wp-admin/edit-comments.php b/wp-admin/edit-comments.php index 29e5f03284..561349f7a1 100644 --- a/wp-admin/edit-comments.php +++ b/wp-admin/edit-comments.php @@ -37,7 +37,7 @@ if ( $doaction ) { $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0; $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() ); - $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to ); + $redirect_to = $wp_list_table->add_query_args( $redirect_to ); foreach ( $comment_ids as $comment_id ) { // Check the permissions on each if ( !current_user_can( 'edit_comment', $comment_id ) ) diff --git a/wp-admin/edit-tags.php b/wp-admin/edit-tags.php index cfaba6ce5a..a0840daa37 100644 --- a/wp-admin/edit-tags.php +++ b/wp-admin/edit-tags.php @@ -78,6 +78,7 @@ case 'delete': wp_delete_term( $tag_ID, $taxonomy ); + $location = $wp_list_table->add_query_args( $location ); $location = add_query_arg( 'message', 2, $location ); wp_redirect( $location ); exit; @@ -104,6 +105,7 @@ case 'bulk-delete': } $location = add_query_arg( 'message', 6, $location ); + $location = $wp_list_table->add_query_args( $location ); wp_redirect( $location ); exit; diff --git a/wp-admin/edit.php b/wp-admin/edit.php index 5e0154f806..2fb8679246 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -41,7 +41,7 @@ if ( $doaction ) { check_admin_referer('bulk-posts'); $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() ); - $sendback = add_query_arg( 'paged', $pagenum, $sendback ); + $sendback = $wp_list_table->add_query_args( $sendback ); if ( strpos($sendback, 'post.php') !== false ) $sendback = admin_url($post_new_file); diff --git a/wp-admin/includes/class-wp-list-table.php b/wp-admin/includes/class-wp-list-table.php index b0965f00ea..7adc3ee6d8 100644 --- a/wp-admin/includes/class-wp-list-table.php +++ b/wp-admin/includes/class-wp-list-table.php @@ -614,6 +614,29 @@ class WP_List_Table { $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) ); return count( $columns ) - count( $hidden ); } + + function get_order_info() { + $current_orderby = isset( $_GET['orderby'] ) ? $_GET['orderby'] : ''; + + if ( ! $current_orderby ) + $current_order = ''; + elseif ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) + $current_order = 'desc'; + else + $current_order = 'asc'; + + return array( $current_orderby, $current_order ); + } + + function add_query_args( $location ) { + $pagenum = $this->get_pagenum(); + list( $current_orderby, $current_order ) = $this->get_order_info(); + $location = add_query_arg( 'paged', $pagenum, $location ); + if ( $current_orderby ) + $location = add_query_arg( array( 'orderby' => $current_orderby, 'order' => $current_order ), $location ); + + return $location; + } /** * Print column headers, accounting for hidden and sortable columns. @@ -630,15 +653,7 @@ class WP_List_Table { $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - if ( isset( $_GET['orderby'] ) ) - $current_orderby = $_GET['orderby']; - else - $current_orderby = ''; - - if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) - $current_order = 'desc'; - else - $current_order = 'asc'; + list( $current_orderby, $current_order ) = $this->get_order_info(); foreach ( $columns as $column_key => $column_display_name ) { $class = array( 'manage-column', "column-$column_key" ); @@ -733,8 +748,11 @@ class WP_List_Table { * @access protected */ function display_tablenav( $which ) { - if ( 'top' == $which ) + if ( 'top' == $which ) { wp_nonce_field( 'bulk-' . $this->_args['plural'] ); + list( $current_orderby, $current_order ) = $this->get_order_info(); + echo ''; + } ?>
diff --git a/wp-admin/js/list-table.dev.js b/wp-admin/js/list-table.dev.js index 32e9806940..233ea6163d 100644 --- a/wp-admin/js/list-table.dev.js +++ b/wp-admin/js/list-table.dev.js @@ -122,7 +122,9 @@ window.listTable = { if ( 'object' != typeof response ) { this.handle_error(); } else { - var tablenav = $('.tablenav-pages'); + var tablenav = $('.tablenav-pages'), + order = $.query.GET('order'), + orderby = order ? $.query.GET('orderby') : ''; this.stop_loading(); @@ -144,6 +146,9 @@ window.listTable = { tablenav.find('.first-page, .prev-page').toggleClass('disabled', 1 == $.query.GET('paged')); tablenav.find('.next-page, .last-page').toggleClass('disabled', response.total_pages == $.query.GET('paged')); + $('input[name=order]').val(order); + $('input[name=orderby]').val(orderby); + $('th.column-cb :input').attr('checked', false); if ( history.replaceState ) { diff --git a/wp-admin/js/list-table.js b/wp-admin/js/list-table.js index ab87daa73e..ef292b5912 100644 --- a/wp-admin/js/list-table.js +++ b/wp-admin/js/list-table.js @@ -1 +1 @@ -jQuery(document).ready(function(a){window.listTable={init:function(){this.loading=false;this.reset(".tablenav, .search-box, .wp-list-table");if(""==a.query.GET("paged")){a.query.SET("paged",1)}this.set_total_pages();this.$tbody=a("#the-list, #the-comment-list")},reset:function(d){d=a(d);a("input",d).each(function(){this.value=this.defaultValue;this.checked=this.defaultChecked});a("select",d).each(function(){var e=a("option",this),f=false;e.each(function(){this.selected=this.defaultSelected;f=f||this.defaultSelected});if(!this.multiple&&!f){e[0].selected=true}});a("textarea",d).each(function(){this.value=this.defaultValue})},set_total_pages:function(e){var d=a(".last-page").attr("href");if(d){this.total_pages=e||a.query.load(d).get("paged")}},get_total_pages:function(){return this.total_pages},htmlencode:function(d){return a("
").text(d).html()},update_rows:function(e,d,h){if(this.loading){return false}var g=false,f={};a.each(e,function(i,j){if(j!=a.query.GET(i)){a.query.SET(i,j);g=true}});if(!g){return false}this.start_loading();if(d){a.query.SET("paged",1)}a.each(a.query.get(),function(i,j){if(true===j){f[i]=""}else{f[i]=j}});this._callback=h;this.fetch_list(f,a.proxy(this,"handle_success"),a.proxy(this,"handle_error"));return true},fetch_list:function(e,f,d){e=a.extend(e,{action:"fetch-list",list_args:list_args,_ajax_fetch_list_nonce:a("#_ajax_fetch_list_nonce").val()});a.ajax({url:ajaxurl,global:false,dataType:"json",data:e,success:f,error:d})},handle_success:function(d){if("object"!=typeof d){this.handle_error()}else{var e=a(".tablenav-pages");this.stop_loading();a("div.updated, div.error").not(".persistent, .inline").remove();this.$tbody.html(d.rows);a(".displaying-num").html(d.total_items_i18n);a(".total-pages").html(d.total_pages_i18n);this.set_total_pages(d.total_pages);if(d.total_pages>1){e.removeClass("one-page")}a(".current-page").val(a.query.GET("paged"));e.find(".first-page, .prev-page").toggleClass("disabled",1==a.query.GET("paged"));e.find(".next-page, .last-page").toggleClass("disabled",d.total_pages==a.query.GET("paged"));a("th.column-cb :input").attr("checked",false);if(history.replaceState){history.replaceState({},"",location.pathname+a.query)}if(this._callback){this._callback()}}},handle_error:function(){this.stop_loading();a("h2").after('

'+listTableL10n.error+"

")},start_loading:function(){this.loading=true;a(".error.ajax").remove();a(".list-ajax-loading").css("visibility","visible")},stop_loading:function(){this.loading=false;a(".list-ajax-loading").css("visibility","hidden")}};listTable.init();function b(e,d){if(e<1){e=1}if(e>listTable.get_total_pages()){e=listTable.get_total_pages()}a(listTable).trigger("beforeChangePage");listTable.update_rows({paged:e},false,function(){if(d.parents(".tablenav.bottom").length){scrollTo(0,0)}a(listTable).trigger("changePage")})}a(".tablenav-pages a").click(function(){var e=a(this),d=a.query.GET("paged");switch(e.attr("class")){case"first-page":d=1;break;case"prev-page":d-=1;break;case"next-page":d+=1;break;case"last-page":d=listTable.get_total_pages();break}b(d,e);return false});a(".current-page").keypress(function(f){if(13!=f.keyCode){return}var d=a(this);b(parseInt(d.val())||1,d);return false});a("th.sortable a, th.sorted a").click(function(){function i(k){return a.query.load(k.find("a").attr("href")).get("order")}var f=a(this),h=f.parent("th"),g=h.index(),j=a.query.load(f.attr("href")).get("orderby"),e;h=h.closest("table").find("thead th:eq("+g+"), tfoot th:eq("+g+")");if(j==a.query.get("orderby")){e=("asc"==a.query.get("order"))?"desc":"asc"}else{e=i(h);var d=a("th.sorted");if(d.length){d.removeClass("sorted").addClass("sortable");d.removeClass("desc").removeClass("asc").addClass("asc"==i(d)?"desc":"asc")}h.removeClass("sortable").addClass("sorted")}h.removeClass("desc").removeClass("asc").addClass(e);listTable.update_rows({orderby:j,order:e},true);return false});function c(d){if("keypress"==d.type&&13!=d.keyCode){return}d.preventDefault();d.stopImmediatePropagation();var e=a(this).parent(".search-box").find(":input").serializeObject();listTable.update_rows(e,true,function(){if(a("h2.nav-tab-wrapper").length){return}if("site-users-network"==pagenow||"site-themes-network"==pagenow){a("h4.search-text").remove();if(e.s){a("ul.subsubsub").after(a('

').html(listTableL10n.search.replace("%s",this.htmlencode(e.s))))}}else{a("h2 .subtitle").remove();if(e.s){a("h2").append(a('').html(listTableL10n.search.replace("%s",this.htmlencode(e.s))))}}})}a(".search-box :submit").click(c);a(".search-box :text").keypress(c);a("#post-query-submit").click(function(){var d={};a(this).parents(".actions").find('select[name!="action"]').each(function(){var e=a(this);d[e.attr("name")]=e.val()});listTable.update_rows(d,true);return false});a(".view-switch a").click(function(){var d=a(this);listTable.update_rows({mode:a.query.load(d.attr("href")).get("mode")},false,function(){a(".view-switch .current").removeClass("current");d.addClass("current")});return false})}); \ No newline at end of file +jQuery(document).ready(function(a){window.listTable={init:function(){this.loading=false;this.reset(".tablenav, .search-box, .wp-list-table");if(""==a.query.GET("paged")){a.query.SET("paged",1)}this.set_total_pages();this.$tbody=a("#the-list, #the-comment-list")},reset:function(d){d=a(d);a("input",d).each(function(){this.value=this.defaultValue;this.checked=this.defaultChecked});a("select",d).each(function(){var e=a("option",this),f=false;e.each(function(){this.selected=this.defaultSelected;f=f||this.defaultSelected});if(!this.multiple&&!f){e[0].selected=true}});a("textarea",d).each(function(){this.value=this.defaultValue})},set_total_pages:function(e){var d=a(".last-page").attr("href");if(d){this.total_pages=e||a.query.load(d).get("paged")}},get_total_pages:function(){return this.total_pages},htmlencode:function(d){return a("
").text(d).html()},update_rows:function(e,d,h){if(this.loading){return false}var g=false,f={};a.each(e,function(i,j){if(j!=a.query.GET(i)){a.query.SET(i,j);g=true}});if(!g){return false}this.start_loading();if(d){a.query.SET("paged",1)}a.each(a.query.get(),function(i,j){if(true===j){f[i]=""}else{f[i]=j}});this._callback=h;this.fetch_list(f,a.proxy(this,"handle_success"),a.proxy(this,"handle_error"));return true},fetch_list:function(e,f,d){e=a.extend(e,{action:"fetch-list",list_args:list_args,_ajax_fetch_list_nonce:a("#_ajax_fetch_list_nonce").val()});a.ajax({url:ajaxurl,global:false,dataType:"json",data:e,success:f,error:d})},handle_success:function(e){if("object"!=typeof e){this.handle_error()}else{var f=a(".tablenav-pages"),d=a.query.GET("order"),g=d?a.query.GET("orderby"):"";this.stop_loading();a("div.updated, div.error").not(".persistent, .inline").remove();this.$tbody.html(e.rows);a(".displaying-num").html(e.total_items_i18n);a(".total-pages").html(e.total_pages_i18n);this.set_total_pages(e.total_pages);if(e.total_pages>1){f.removeClass("one-page")}a(".current-page").val(a.query.GET("paged"));f.find(".first-page, .prev-page").toggleClass("disabled",1==a.query.GET("paged"));f.find(".next-page, .last-page").toggleClass("disabled",e.total_pages==a.query.GET("paged"));a("input[name=order]").val(d);a("input[name=orderby]").val(g);a("th.column-cb :input").attr("checked",false);if(history.replaceState){history.replaceState({},"",location.pathname+a.query)}if(this._callback){this._callback()}}},handle_error:function(){this.stop_loading();a("h2").after('

'+listTableL10n.error+"

")},start_loading:function(){this.loading=true;a(".error.ajax").remove();a(".list-ajax-loading").css("visibility","visible")},stop_loading:function(){this.loading=false;a(".list-ajax-loading").css("visibility","hidden")}};listTable.init();function b(e,d){if(e<1){e=1}if(e>listTable.get_total_pages()){e=listTable.get_total_pages()}a(listTable).trigger("beforeChangePage");listTable.update_rows({paged:e},false,function(){if(d.parents(".tablenav.bottom").length){scrollTo(0,0)}a(listTable).trigger("changePage")})}a(".tablenav-pages a").click(function(){var e=a(this),d=a.query.GET("paged");switch(e.attr("class")){case"first-page":d=1;break;case"prev-page":d-=1;break;case"next-page":d+=1;break;case"last-page":d=listTable.get_total_pages();break}b(d,e);return false});a(".current-page").keypress(function(f){if(13!=f.keyCode){return}var d=a(this);b(parseInt(d.val())||1,d);return false});a("th.sortable a, th.sorted a").click(function(){function i(k){return a.query.load(k.find("a").attr("href")).get("order")}var f=a(this),h=f.parent("th"),g=h.index(),j=a.query.load(f.attr("href")).get("orderby"),e;h=h.closest("table").find("thead th:eq("+g+"), tfoot th:eq("+g+")");if(j==a.query.get("orderby")){e=("asc"==a.query.get("order"))?"desc":"asc"}else{e=i(h);var d=a("th.sorted");if(d.length){d.removeClass("sorted").addClass("sortable");d.removeClass("desc").removeClass("asc").addClass("asc"==i(d)?"desc":"asc")}h.removeClass("sortable").addClass("sorted")}h.removeClass("desc").removeClass("asc").addClass(e);listTable.update_rows({orderby:j,order:e},true);return false});function c(d){if("keypress"==d.type&&13!=d.keyCode){return}d.preventDefault();d.stopImmediatePropagation();var e=a(this).parent(".search-box").find(":input").serializeObject();listTable.update_rows(e,true,function(){if(a("h2.nav-tab-wrapper").length){return}if("site-users-network"==pagenow||"site-themes-network"==pagenow){a("h4.search-text").remove();if(e.s){a("ul.subsubsub").after(a('

').html(listTableL10n.search.replace("%s",this.htmlencode(e.s))))}}else{a("h2 .subtitle").remove();if(e.s){a("h2").append(a('').html(listTableL10n.search.replace("%s",this.htmlencode(e.s))))}}})}a(".search-box :submit").click(c);a(".search-box :text").keypress(c);a("#post-query-submit").click(function(){var d={};a(this).parents(".actions").find('select[name!="action"]').each(function(){var e=a(this);d[e.attr("name")]=e.val()});listTable.update_rows(d,true);return false});a(".view-switch a").click(function(){var d=a(this);listTable.update_rows({mode:a.query.load(d.attr("href")).get("mode")},false,function(){a(".view-switch .current").removeClass("current");d.addClass("current")});return false})}); \ No newline at end of file diff --git a/wp-admin/upload.php b/wp-admin/upload.php index f294614f29..fb85154680 100644 --- a/wp-admin/upload.php +++ b/wp-admin/upload.php @@ -83,6 +83,7 @@ if ( $doaction ) { $location = $referer; } + $location = $wp_list_table->add_query_args( $locations ); $location = add_query_arg( array( 'attached' => $attached ) , $location ); wp_redirect( $location ); exit; @@ -120,6 +121,7 @@ if ( $doaction ) { break; } + $location = $wp_list_table->add_query_args( $locations ); wp_redirect( $location ); exit; } elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) ) { diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index e6e978de4d..7ae61f2b63 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -302,7 +302,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20090106' ); $scripts->add_data( 'admin-custom-fields', 'group', 1 ); - $scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery-query', 'jquery-serialize-object' ), '20110111a' ); + $scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery-query', 'jquery-serialize-object' ), '20110112' ); $scripts->add_data( 'list-table', 'group', 1 ); $scripts->localize( 'list-table', 'listTableL10n', array( 'error' => __('An error has occurred while loading the items.'),