Column hiding for manage posts. see #7725

git-svn-id: http://svn.automattic.com/wordpress/trunk@8858 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-11 01:46:30 +00:00
parent 2f582d83e7
commit c862000e76
7 changed files with 174 additions and 27 deletions

View File

@ -704,6 +704,17 @@ case 'closed-postboxes' :
if ( is_array($hidden) )
update_usermeta($current_user->ID, 'meta-box-hidden_'.$page, $hidden);
break;
case 'hidden-columns' :
check_ajax_referer( 'hiddencolumns', 'hiddencolumnsnonce' );
$hidden = isset( $_POST['hidden'] )? $_POST['hidden'] : '';
$hidden = explode( ',', $_POST['hidden'] );
$page = isset( $_POST['page'] )? $_POST['page'] : '';
if ( !preg_match( '/^[a-z-]+$/', $page ) ) {
die(-1);
}
$current_user = wp_get_current_user();
if ( is_array($hidden) )
update_usermeta($current_user->ID, "manage-$page-columns-hidden", $hidden);
case 'get-permalink':
check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
$post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;

View File

@ -12,16 +12,24 @@ if ( ! defined('ABSPATH') ) die();
<thead>
<tr>
<?php $posts_columns = wp_manage_posts_columns(); ?>
<?php foreach($posts_columns as $post_column_key => $column_display_name) {
<?php
$posts_columns = wp_manage_posts_columns();
$hidden = (array) get_user_option( 'manage-post-columns-hidden' );
foreach ( $posts_columns as $post_column_key => $column_display_name ) {
if ( 'cb' === $post_column_key )
$class = ' class="check-column"';
elseif ( 'comments' === $post_column_key )
$class = ' class="num"';
$class = ' class="manage-column column-comments num"';
elseif ( 'modified' === $post_column_key )
$class = ' class="manage-column column-date"';
else
$class = '';
$class = " class=\"manage-column column-$post_column_key\"";
$style = '';
if ( in_array($post_column_key, $hidden) )
$style = ' style="display:none;"';
?>
<th scope="col"<?php echo $class; ?>><?php echo $column_display_name; ?></th>
<th scope="col"<?php echo "id=\"$post_column_key\""; echo $class; echo $style?>><?php echo $column_display_name; ?></th>
<?php } ?>
</tr>

View File

@ -51,7 +51,7 @@ $title = __('Posts');
$parent_file = 'edit.php';
wp_enqueue_script('admin-forms');
wp_enqueue_script('inline-edit');
wp_enqueue_script('posts');
list($post_stati, $avail_post_stati) = wp_edit_posts_query();
@ -74,6 +74,19 @@ else
<div class="wrap">
<form id="posts-filter" action="" method="get">
<div id="show-settings"><a href="#edit_settings" id="show-settings-link" class="hide-if-no-js"><?php _e('Show Settings') ?></a>
<a href="#edit_settings" id="hide-settings-link" class="hide-if-js hide-if-no-js"><?php _e('Hide Settings') ?></a></div>
<div id="edit-settings" class="hide-if-js hide-if-no-js">
<div id="edit-settings-wrap">
<h5><?php _e('Show on screen') ?></h5>
<div class="metabox-prefs">
<?php manage_columns_prefs('post') ?>
<br class="clear" />
</div></div>
</div>
<h2><?php
if ( is_single() ) {
printf(__('Comments on %s'), apply_filters( "the_title", $post->post_title));
@ -226,6 +239,8 @@ do_action('restrict_manage_posts');
<?php include( 'edit-post-rows.php' ); ?>
<?php wp_nonce_field( 'hiddencolumns', 'hiddencolumnsnonce', false ); ?>
</form>
<div id="ajax-response"></div>

View File

@ -416,7 +416,15 @@ function inline_edit_row( $type ) {
echo '<tr id="inline-edit" style="display: none">';
$columns = $type == 'post' ? wp_manage_posts_columns() : wp_manage_pages_columns();
$hidden = (array) get_user_option( "manage-$type-columns-hidden" );
foreach($columns as $column_name=>$column_display_name) {
$class = "class=\"$column_name column-$column_name\"";
$style = '';
if ( in_array($column_name, $hidden) )
$style = ' style="display:none;"';
$attributes = "$class$style";
switch($column_name) {
@ -426,20 +434,24 @@ function inline_edit_row( $type ) {
break;
case 'modified':
case 'date': ?>
<td class="date">
case 'date':
$attributes = 'class="date column-date"' . $style;
?>
<td class="date"<?php echo $style ?>>
<?php touch_time(1, 1, 4, 1); ?>
</td>
<?php
break;
case 'title': ?>
<td class="<?php echo $type ?>-title">
case 'title':
$attributes = "class=\"$type-title column-title\"" . $style;
?>
<td <?php echo $attributes ?>>
<div class="title">
<input type="text" name="post_title" class="title" value="" /><br />
<label><?php _e('Slug'); ?></label><input type="text" name="post_name" value="" class="slug" />
</div>
<?php if($type == 'page'): ?>
<?php if ($type == 'page'): ?>
<div class="other">
<label><?php _e('Parent'); ?></label>
<select name="post_parent">
@ -475,7 +487,7 @@ function inline_edit_row( $type ) {
break;
case 'categories': ?>
<td class="categories">
<td <?php echo $attributes ?>>
<ul class="categories">
<?php wp_category_checklist() ?>
</ul>
@ -484,14 +496,16 @@ function inline_edit_row( $type ) {
break;
case 'tags': ?>
<td class="tags">
<td <?php echo $attributes ?>>
<textarea name="tags_input"></textarea>
</td>
<?php
break;
case 'comments': ?>
<td class="comments num">
case 'comments':
$attributes = 'class="comments column-comments num"' . $style;
?>
<td <?php echo $attributes ?>>
<input title="Allow Comments" type="checkbox" name="comment_status" value="open" /><br />
<input title="Allow Pings" type="checkbox" name="ping_status" value="open" />
</td>
@ -499,7 +513,7 @@ function inline_edit_row( $type ) {
break;
case 'author': ?>
<td class="author">
<td <?php echo $attributes ?>>
<?php
$authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
if ( $authors && count( $authors ) > 1 ) {
@ -513,7 +527,7 @@ function inline_edit_row( $type ) {
break;
case 'status': ?>
<td class="status">
<td <?php echo $attributes ?>>
<select name="post_status">
<?php if ( current_user_can('publish_posts') ) : // Contributors only get "Unpublished" and "Pending Review" ?>
<option value='publish'><?php _e('Published') ?></option>
@ -674,9 +688,17 @@ function _post_row($a_post, $pending_comments, $mode) {
<tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim( $class . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">
<?php
$posts_columns = wp_manage_posts_columns();
foreach($posts_columns as $column_name=>$column_display_name) {
$hidden = (array) get_user_option( 'manage-post-columns-hidden' );
foreach ( $posts_columns as $column_name=>$column_display_name ) {
$class = "class=\"$column_name column-$column_name\"";
switch($column_name) {
$style = '';
if ( in_array($column_name, $hidden) )
$style = ' style="display:none;"';
$attributes = "$class$style";
switch ($column_name) {
case 'cb':
?>
@ -686,6 +708,7 @@ function _post_row($a_post, $pending_comments, $mode) {
case 'modified':
case 'date':
$attributes = 'class="date column-date"' . $style;
if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
$t_time = $h_time = __('Unpublished');
} else {
@ -709,15 +732,16 @@ function _post_row($a_post, $pending_comments, $mode) {
}
if ( 'excerpt' == $mode ) { ?>
<td class="date"><?php echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode) ?></td>
<td <?php echo $attributes ?>><?php echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode) ?></td>
<?php } else { ?>
<td class="date"><abbr title="<?php echo $t_time ?>"><?php echo apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) ?></abbr></td>
<td <?php echo $attributes ?>><abbr title="<?php echo $t_time ?>"><?php echo apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) ?></abbr></td>
<?php }
break;
case 'title':
$attributes = 'class="post-title column-title"' . $style;
?>
<td class="post-title"><strong><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; } ?></strong>
<td <?php echo $attributes ?>><strong><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; } ?></strong>
<?php
if ( !empty($post->post_password) ) { _e(' &#8212; <strong>Protected</strong>'); } elseif ('private' == $post->post_status) { _e(' &#8212; <strong>Private</strong>'); }
@ -742,7 +766,7 @@ function _post_row($a_post, $pending_comments, $mode) {
case 'categories':
?>
<td class="categories"><?php
<td <?php echo $attributes ?>><?php
$categories = get_the_category();
if ( !empty( $categories ) ) {
$out = array();
@ -758,7 +782,7 @@ function _post_row($a_post, $pending_comments, $mode) {
case 'tags':
?>
<td class="tags"><?php
<td <?php echo $attributes ?>><?php
$tags = get_the_tags();
if ( !empty( $tags ) ) {
$out = array();
@ -773,8 +797,9 @@ function _post_row($a_post, $pending_comments, $mode) {
break;
case 'comments':
$attributes = 'class="comments column-comments num"' . $style;
?>
<td class="comments num"><div class="post-com-count-wrapper">
<td <?php echo $attributes ?>><div class="post-com-count-wrapper">
<?php
$pending_phrase = sprintf( __('%s pending'), number_format( $pending_comments ) );
if ( $pending_comments )
@ -789,13 +814,13 @@ function _post_row($a_post, $pending_comments, $mode) {
case 'author':
?>
<td class="author"><a href="edit.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
<td <?php echo $attributes ?>><a href="edit.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
<?php
break;
case 'status':
?>
<td class="status">
<td <?php echo $attributes ?>>
<a href="<?php the_permalink(); ?>" title="<?php echo attribute_escape(sprintf(__('View "%s"'), $title)); ?>" rel="permalink">
<?php
switch ( $post->post_status ) {
@ -1917,4 +1942,28 @@ function do_settings_fields($page, $section) {
}
}
function manage_columns_prefs($page) {
if ( 'post' == $page )
$columns = wp_manage_posts_columns();
elseif ( 'page' == $page )
$columns = wp_manage_pages_columns();
elseif ( 'media' == $page )
$columns = wp_manage_media_columns();
else return;
$hidden = (array) get_user_option( "manage-$page-columns-hidden" );
foreach ( $columns as $column => $title ) {
// Can't hide these
if ( 'cb' == $column || 'title' == $column )
continue;
if ( 'comments' == $column )
$title = __('Comments');
$id = "$column-hide";
echo '<label for="' . $id . '">';
echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . (! in_array($column, $hidden) ? ' checked="checked"' : '') . ' />';
echo "$title</label>\n";
}
}
?>

33
wp-admin/js/columns.js Normal file
View File

@ -0,0 +1,33 @@
(function($) {
columns = {
init : function(page) {
$('.hide-column-tog').click( function() {
var column = jQuery(this).val();
var show = jQuery(this).attr('checked');
if ( show ) {
jQuery('.column-' + column).show();
} else {
jQuery('.column-' + column).hide();
}
save_manage_columns_state(page);
} );
if ( $.browser.msie ) {
$('#side-sortables').append( '<div id="make-it-tall"></div>' );
} else {
$('#side-sortables').append( '<div id="make-it-tall" style="margin-bottom: -2000px; padding-bottom: 2001px"></div>' );
}
$('#wpbody-content').css( 'overflow', 'hidden' );
}
}
}(jQuery));
function save_manage_columns_state(page) {
var hidden = jQuery('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
jQuery.post(columnsL10n.requestFile, {
action: 'hidden-columns',
hidden: hidden,
hiddencolumnsnonce: jQuery('#hiddencolumnsnonce').val(),
page: page
});
}

24
wp-admin/js/posts.js Normal file
View File

@ -0,0 +1,24 @@
jQuery(document).ready( function($) {
columns.init('post');
// Edit Settings
$('#show-settings-link').click(function () {
$('#edit-settings').slideDown('normal', function(){
$('#show-settings-link').hide();
$('#hide-settings-link').show();
});
$('#show-settings').addClass('show-settings-opened');
return false;
});
$('#hide-settings-link').click(function () {
$('#edit-settings').slideUp('normal', function(){
$('#hide-settings-link').hide();
$('#show-settings-link').show();
$('#show-settings').removeClass('show-settings-opened');
});
return false;
});
});

View File

@ -257,6 +257,13 @@ function wp_default_scripts( &$scripts ) {
'uid' => $userid,
'time' => time()
) );
$scripts->add( 'posts', '/wp-admin/js/posts.js', array('columns'), '20080910' );
$scripts->add( 'columns', '/wp-admin/js/columns.js', false, '20080910' );
$scripts->localize( 'columns', 'columnsL10n', array(
'requestFile' => admin_url('admin-ajax.php'),
) );
}
}