WordPress.org

Make WordPress Core

Changeset 17270


Ignore:
Timestamp:
01/12/11 17:06:33 (3 years ago)
Author:
nacin
Message:

Keep sorting and paging for bulk actions. props garyc40, see #16166.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-comments.php

    r17129 r17270  
    3838 
    3939    $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() ); 
    40     $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to ); 
     40    $redirect_to = $wp_list_table->add_query_args( $redirect_to ); 
    4141 
    4242    foreach ( $comment_ids as $comment_id ) { // Check the permissions on each 
  • trunk/wp-admin/edit-tags.php

    r17041 r17270  
    7979    wp_delete_term( $tag_ID, $taxonomy ); 
    8080 
     81    $location = $wp_list_table->add_query_args( $location ); 
    8182    $location = add_query_arg( 'message', 2, $location ); 
    8283    wp_redirect( $location ); 
     
    105106 
    106107    $location = add_query_arg( 'message', 6, $location ); 
     108    $location = $wp_list_table->add_query_args( $location ); 
    107109    wp_redirect( $location ); 
    108110    exit; 
  • trunk/wp-admin/edit.php

    r17006 r17270  
    4242 
    4343    $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() ); 
    44     $sendback = add_query_arg( 'paged', $pagenum, $sendback ); 
     44    $sendback = $wp_list_table->add_query_args( $sendback ); 
    4545    if ( strpos($sendback, 'post.php') !== false ) 
    4646        $sendback = admin_url($post_new_file); 
  • trunk/wp-admin/includes/class-wp-list-table.php

    r17268 r17270  
    615615        return count( $columns ) - count( $hidden ); 
    616616    } 
    617  
    618     /** 
    619      * Print column headers, accounting for hidden and sortable columns. 
    620      * 
    621      * @since 3.1.0 
    622      * @access protected 
    623      * 
    624      * @param bool $with_id Whether to set the id attribute or not 
    625      */ 
    626     function print_column_headers( $with_id = true ) { 
    627         $screen = get_current_screen(); 
    628  
    629         list( $columns, $hidden, $sortable ) = $this->get_column_info(); 
    630  
    631         $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
    632  
    633         if ( isset( $_GET['orderby'] ) ) 
    634             $current_orderby = $_GET['orderby']; 
    635         else 
    636             $current_orderby = ''; 
    637  
    638         if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) 
     617     
     618    function get_order_info() { 
     619        $current_orderby = isset( $_GET['orderby'] ) ? $_GET['orderby'] : ''; 
     620 
     621        if ( ! $current_orderby ) 
     622            $current_order = ''; 
     623        elseif ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) 
    639624            $current_order = 'desc'; 
    640625        else 
    641626            $current_order = 'asc'; 
     627 
     628        return array( $current_orderby, $current_order ); 
     629    } 
     630     
     631    function add_query_args( $location ) { 
     632        $pagenum = $this->get_pagenum(); 
     633        list( $current_orderby, $current_order ) = $this->get_order_info(); 
     634        $location = add_query_arg( 'paged', $pagenum, $location ); 
     635        if ( $current_orderby ) 
     636            $location = add_query_arg( array( 'orderby' => $current_orderby, 'order' => $current_order ), $location ); 
     637 
     638        return $location; 
     639    } 
     640 
     641    /** 
     642     * Print column headers, accounting for hidden and sortable columns. 
     643     * 
     644     * @since 3.1.0 
     645     * @access protected 
     646     * 
     647     * @param bool $with_id Whether to set the id attribute or not 
     648     */ 
     649    function print_column_headers( $with_id = true ) { 
     650        $screen = get_current_screen(); 
     651 
     652        list( $columns, $hidden, $sortable ) = $this->get_column_info(); 
     653 
     654        $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
     655 
     656        list( $current_orderby, $current_order ) = $this->get_order_info(); 
    642657 
    643658        foreach ( $columns as $column_key => $column_display_name ) { 
     
    734749     */ 
    735750    function display_tablenav( $which ) { 
    736         if ( 'top' == $which ) 
     751        if ( 'top' == $which ) { 
    737752            wp_nonce_field( 'bulk-' . $this->_args['plural'] ); 
     753            list( $current_orderby, $current_order ) = $this->get_order_info(); 
     754            echo '<input type="hidden" name="orderby" value="' . esc_attr( $current_orderby ) . '" /><input type="hidden" name="order" value="' . esc_attr( $current_order ) . '" />'; 
     755        } 
    738756?> 
    739757    <div class="tablenav <?php echo esc_attr( $which ); ?>"> 
  • trunk/wp-admin/js/list-table.dev.js

    r17255 r17270  
    123123            this.handle_error(); 
    124124        } else { 
    125             var tablenav = $('.tablenav-pages'); 
     125            var tablenav = $('.tablenav-pages'), 
     126                order = $.query.GET('order'), 
     127                orderby = order ? $.query.GET('orderby') : ''; 
    126128 
    127129            this.stop_loading(); 
     
    144146            tablenav.find('.first-page, .prev-page').toggleClass('disabled', 1 == $.query.GET('paged')); 
    145147            tablenav.find('.next-page, .last-page').toggleClass('disabled', response.total_pages == $.query.GET('paged')); 
     148 
     149            $('input[name=order]').val(order); 
     150            $('input[name=orderby]').val(orderby); 
    146151 
    147152            $('th.column-cb :input').attr('checked', false); 
  • trunk/wp-admin/js/list-table.js

    r17255 r17270  
    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("<div/>").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('<div class="error ajax below-h2"><p>'+listTableL10n.error+"</p></div>")},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('<h4 class="clear search-text">').html(listTableL10n.search.replace("%s",this.htmlencode(e.s))))}}else{a("h2 .subtitle").remove();if(e.s){a("h2").append(a('<span class="subtitle">').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})}); 
     1jQuery(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("<div/>").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('<div class="error ajax below-h2"><p>'+listTableL10n.error+"</p></div>")},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('<h4 class="clear search-text">').html(listTableL10n.search.replace("%s",this.htmlencode(e.s))))}}else{a("h2 .subtitle").remove();if(e.s){a("h2").append(a('<span class="subtitle">').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})}); 
  • trunk/wp-admin/upload.php

    r17129 r17270  
    8484                } 
    8585 
     86                $location = $wp_list_table->add_query_args( $locations ); 
    8687                $location = add_query_arg( array( 'attached' => $attached ) , $location ); 
    8788                wp_redirect( $location ); 
     
    121122    } 
    122123 
     124    $location = $wp_list_table->add_query_args( $locations ); 
    123125    wp_redirect( $location ); 
    124126    exit; 
  • trunk/wp-includes/script-loader.php

    r17266 r17270  
    303303        $scripts->add_data( 'admin-custom-fields', 'group', 1 ); 
    304304 
    305         $scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery-query', 'jquery-serialize-object' ), '20110111a' ); 
     305        $scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery-query', 'jquery-serialize-object' ), '20110112' ); 
    306306        $scripts->add_data( 'list-table', 'group', 1 ); 
    307307        $scripts->localize( 'list-table', 'listTableL10n', array( 
Note: See TracChangeset for help on using the changeset viewer.