diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 06df8afb45..a11b542699 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -12,6 +12,7 @@ * @since unknown */ define('DOING_AJAX', true); +define('WP_ADMIN', true); require_once('../wp-load.php'); require_once('includes/admin.php'); @@ -715,6 +716,24 @@ case 'sample-permalink': $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : ''; die(get_sample_permalink_html($post_id, $title, $slug)); break; +case 'inline-data': + get_inline_data( explode(',', $_POST['posts']) ); + die(); +break; +case 'inline-save': + inline_save_row( $_POST ); + if ( 'page' == $_POST['post_type'] ) { + $post = array(); + $post[] = get_post($_POST['post_ID']); + page_rows( $post ); + } elseif ( 'post' == $_POST['post_type'] ) { + $mode = $_POST['post_view']; + $post = array(); + $post[] = get_post($_POST['post_ID']); + post_rows($post); + } + die(); +break; case 'meta-box-order': check_ajax_referer( 'meta-box-order' ); update_user_option( $GLOBALS['current_user']->ID, "meta-box-order_$_POST[page]", $_POST['order'] ); diff --git a/wp-admin/edit-pages.php b/wp-admin/edit-pages.php index 989cd69a27..becbd3f283 100644 --- a/wp-admin/edit-pages.php +++ b/wp-admin/edit-pages.php @@ -44,6 +44,7 @@ if ( isset($_GET['action']) && isset($_GET['delete']) ) { $title = __('Pages'); $parent_file = 'edit.php'; wp_enqueue_script('admin-forms'); +wp_enqueue_script('inline-edit'); $post_stati = array( // array( adj, noun ) 'publish' => array(__('Published'), __('Published pages'), __ngettext_noop('Published (%s)', 'Published (%s)')), @@ -153,6 +154,7 @@ if ( $page_links )
@@ -187,6 +189,7 @@ if ($posts) { + diff --git a/wp-admin/edit-post-rows.php b/wp-admin/edit-post-rows.php index c6fcd3cb1f..2319c760c3 100644 --- a/wp-admin/edit-post-rows.php +++ b/wp-admin/edit-post-rows.php @@ -27,6 +27,9 @@ if ( ! defined('ABSPATH') ) die(); + + + diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 4e83a1a6c6..6b638c2974 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -9,29 +9,34 @@ * @since 2.6 * * @param bool $update Are we updating a pre-existing post? + * @param post_data array Array of post data. Defaults to the contents of $_POST * @return object|bool WP_Error on failure, true on success. */ -function _wp_translate_postdata( $update = false ) { - if ( $update ) - $_POST['ID'] = (int) $_POST['post_ID']; - $_POST['post_content'] = $_POST['content']; - $_POST['post_excerpt'] = $_POST['excerpt']; - $_POST['post_parent'] = isset($_POST['parent_id'])? $_POST['parent_id'] : ''; - if ( isset($_POST['trackback_url']) ) - $_POST['to_ping'] = $_POST['trackback_url']; +function _wp_translate_postdata( $update = false, &$post_data = null ) { - if (!empty ( $_POST['post_author_override'] ) ) { - $_POST['post_author'] = (int) $_POST['post_author_override']; + if ( empty($post_data) ) + $post_data = &$_POST; + + if ( $update ) + $post_data['ID'] = (int) $post_data['post_ID']; + $post_data['post_content'] = $post_data['content']; + $post_data['post_excerpt'] = $post_data['excerpt']; + $post_data['post_parent'] = isset($post_data['parent_id'])? $post_data['parent_id'] : ''; + if ( isset($post_data['trackback_url']) ) + $post_data['to_ping'] = $post_data['trackback_url']; + + if (!empty ( $post_data['post_author_override'] ) ) { + $post_data['post_author'] = (int) $post_data['post_author_override']; } else { - if (!empty ( $_POST['post_author'] ) ) { - $_POST['post_author'] = (int) $_POST['post_author']; + if (!empty ( $post_data['post_author'] ) ) { + $post_data['post_author'] = (int) $post_data['post_author']; } else { - $_POST['post_author'] = (int) $_POST['user_ID']; + $post_data['post_author'] = (int) $post_data['user_ID']; } } - if ( isset($_POST['user_ID']) && ($_POST['post_author'] != $_POST['user_ID']) ) { - if ( 'page' == $_POST['post_type'] ) { + if ( isset($post_data['user_ID']) && ($post_data['post_author'] != $post_data['user_ID']) ) { + if ( 'page' == $post_data['post_type'] ) { if ( !current_user_can( 'edit_others_pages' ) ) { return new WP_Error( 'edit_others_pages', $update ? __( 'You are not allowed to edit pages as this user.' ) : @@ -49,51 +54,51 @@ function _wp_translate_postdata( $update = false ) { } // What to do based on which button they pressed - if ( isset($_POST['saveasdraft']) && '' != $_POST['saveasdraft'] ) - $_POST['post_status'] = 'draft'; - if ( isset($_POST['saveasprivate']) && '' != $_POST['saveasprivate'] ) - $_POST['post_status'] = 'private'; - if ( isset($_POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) ) - $_POST['post_status'] = 'publish'; - if ( isset($_POST['advanced']) && '' != $_POST['advanced'] ) - $_POST['post_status'] = 'draft'; + if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] ) + $post_data['post_status'] = 'draft'; + if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] ) + $post_data['post_status'] = 'private'; + if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( $post_data['post_status'] != 'private' ) ) + $post_data['post_status'] = 'publish'; + if ( isset($post_data['advanced']) && '' != $post_data['advanced'] ) + $post_data['post_status'] = 'draft'; - $previous_status = get_post_field('post_status', $_POST['ID']); + $previous_status = get_post_field('post_status', $post_data['ID']); // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published. // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts. - if ( 'page' == $_POST['post_type'] ) { - if ( 'publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) ) + if ( 'page' == $post_data['post_type'] ) { + if ( 'publish' == $post_data['post_status'] && !current_user_can( 'publish_pages' ) ) if ( $previous_status != 'publish' OR !current_user_can( 'edit_published_pages') ) - $_POST['post_status'] = 'pending'; + $post_data['post_status'] = 'pending'; } else { - if ( isset($_POST['post_status']) && ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' )) ) : + if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( 'publish_posts' )) ) : // Stop attempts to publish new posts, but allow already published posts to be saved if appropriate. if ( $previous_status != 'publish' OR !current_user_can( 'edit_published_posts') ) - $_POST['post_status'] = 'pending'; + $post_data['post_status'] = 'pending'; endif; } - if (!isset( $_POST['comment_status'] )) - $_POST['comment_status'] = 'closed'; + if (!isset( $post_data['comment_status'] )) + $post_data['comment_status'] = 'closed'; - if (!isset( $_POST['ping_status'] )) - $_POST['ping_status'] = 'closed'; + if (!isset( $post_data['ping_status'] )) + $post_data['ping_status'] = 'closed'; foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) { - if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) { - $_POST['edit_date'] = '1'; + if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) { + $post_data['edit_date'] = '1'; break; } } - if ( !empty( $_POST['edit_date'] ) ) { - $aa = $_POST['aa']; - $mm = $_POST['mm']; - $jj = $_POST['jj']; - $hh = $_POST['hh']; - $mn = $_POST['mn']; - $ss = $_POST['ss']; + if ( !empty( $post_data['edit_date'] ) ) { + $aa = $post_data['aa']; + $mm = $post_data['mm']; + $jj = $post_data['jj']; + $hh = $post_data['hh']; + $mn = $post_data['mn']; + $ss = $post_data['ss']; $aa = ($aa <= 0 ) ? date('Y') : $aa; $mm = ($mm <= 0 ) ? date('n') : $mm; $jj = ($jj > 31 ) ? 31 : $jj; @@ -101,8 +106,8 @@ function _wp_translate_postdata( $update = false ) { $hh = ($hh > 23 ) ? $hh -24 : $hh; $mn = ($mn > 59 ) ? $mn -60 : $mn; $ss = ($ss > 59 ) ? $ss -60 : $ss; - $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); - $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] ); + $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); + $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] ); } return true; @@ -110,11 +115,14 @@ function _wp_translate_postdata( $update = false ) { // Update an existing post with values provided in $_POST. -function edit_post() { +function edit_post( $post_data = null ) { - $post_ID = (int) $_POST['post_ID']; + if ( empty($post_data) ) + $post_data = &$_POST; - if ( 'page' == $_POST['post_type'] ) { + $post_ID = (int) $post_data['post_ID']; + + if ( 'page' == $post_data['post_type'] ) { if ( !current_user_can( 'edit_page', $post_ID ) ) wp_die( __('You are not allowed to edit this page.' )); } else { @@ -123,7 +131,7 @@ function edit_post() { } // Autosave shouldn't save too soon after a real save - if ( 'autosave' == $_POST['action'] ) { + if ( 'autosave' == $post_data['action'] ) { $post =& get_post( $post_ID ); $now = time(); $then = strtotime($post->post_date_gmt . ' +0000'); @@ -132,24 +140,24 @@ function edit_post() { return $post_ID; } - $translated = _wp_translate_postdata( true ); + $translated = _wp_translate_postdata( true, $post_data ); if ( is_wp_error($translated) ) wp_die( $translated->get_error_message() ); // Meta Stuff - if ( isset($_POST['meta']) && $_POST['meta'] ) { - foreach ( $_POST['meta'] as $key => $value ) + if ( isset($post_data['meta']) && $post_data['meta'] ) { + foreach ( $post_data['meta'] as $key => $value ) update_meta( $key, $value['key'], $value['value'] ); } - if ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) { - foreach ( $_POST['deletemeta'] as $key => $value ) + if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) { + foreach ( $post_data['deletemeta'] as $key => $value ) delete_meta( $key ); } add_meta( $post_ID ); - wp_update_post( $_POST ); + wp_update_post( $post_data ); // Reunite any orphaned attachments with their parent if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) @@ -163,7 +171,7 @@ function edit_post() { wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID ); if ( current_user_can( 'edit_others_posts' ) ) { - if ( !empty($_POST['sticky']) ) + if ( !empty($post_data['sticky']) ) stick_post($post_ID); else unstick_post($post_ID); diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index c599cd76cc..d4cfd977e6 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -350,7 +350,7 @@ function wp_manage_posts_columns() { $posts_columns['modified'] = __('Submitted'); else $posts_columns['date'] = __('Date'); - //$posts_columns['author'] = __('Author'); + $posts_columns['author'] = __('Author'); $posts_columns['categories'] = __('Categories'); $posts_columns['tags'] = __('Tags'); if ( !isset($_GET['post_status']) || !in_array($_GET['post_status'], array('pending', 'draft', 'future')) ) @@ -406,23 +406,248 @@ function wp_manage_pages_columns() { return $posts_columns; } -function post_rows() { +function inline_edit_row( $type ) { + global $current_user; + + if ( 'post' == $type ) + $post = get_default_post_to_edit(); + else + $post = get_default_page_to_edit(); + + echo ''; + $columns = $type == 'post' ? wp_manage_posts_columns() : wp_manage_pages_columns(); + foreach($columns as $column_name=>$column_display_name) { + + switch($column_name) { + + case 'cb': ?> + + + + + + + +
+
+ +
+ +
+ +
+ + +
+
+ + +
+ +
+ ' . __('Save') . ''; + $actions['cancel'] = '' . __('Cancel') . ''; + $action_count = count($actions); + $i = 0; + foreach ( $actions as $action => $link ) { + ++$i; + ( $i == $action_count ) ? $sep = '' : $sep = ' | '; + echo "$link$sep"; + } + ?> + + + + + + + + + + + +
+ + + + + id ); // TODO: ROLE SYSTEM + if ( $authors && count( $authors ) > 1 ) { + wp_dropdown_users( array('include' => $authors, 'name' => 'post_author', 'class'=> 'author', 'selected' => $post->post_author) ); + } else { + echo $current_user->user_nicename.''; + } + ?> + + + + + +

+ + +

+ + + + + + + ID) ) { echo "" . __('Edit') . ""; } ?> + + ID) ) { echo "ID) . "' class='delete'>" . __('Delete') . ""; } ?> + + ID); ?> + '; +} + +function inline_save_row( $data ) { + // get the original post content + $post = get_post( $data['post_ID'], ARRAY_A ); + $data['content'] = $post['post_content']; + + // statuses + if ( 'page' == $data['post_type'] && 'private' == $data['page_private'] ) + $data['post_status'] = 'private'; + if ( empty($data['comment_status']) ) + $data['comment_status'] = 'closed'; + if ( empty($data['ping_status']) ) + $data['ping_status'] = 'closed'; + + // rename + $data['user_ID'] = $GLOBALS['user_ID']; + $data['excerpt'] = $data['post_excerpt']; + $data['trackback_url'] = $data['to_ping']; + $data['parent_id'] = $data['post_parent']; + + // update the post + $_POST = $data; + edit_post(); +} + +// outputs XML of the post/page data ready for use in the inline editor +// accepts array of post IDs +function get_inline_data($posts) { + global $post; + + header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); + echo "\n"; + echo "\n"; + + foreach ($posts as $ID) { + $GLOBALS['post'] = get_post($ID); + $GLOBALS['post_ID'] = $ID; + + if ( ($post->post_type == 'post' && !current_user_can('edit_post', $ID)) || + ($post->post_type == 'page' && !current_user_can('edit_page', $ID)) || + ($post->post_type != 'post' && $post->post_type != 'page')) + continue; + + echo " \n"; + echo " " . wp_specialchars($post->post_title, 1) . "\n"; + echo " $post->post_name\n"; + echo " $post->post_author\n"; + echo " $post->comment_status\n"; + echo " $post->ping_status\n"; + echo " $post->post_status\n"; + echo " " . mysql2date( 'd', $post->post_date ) . "\n"; + echo " " . mysql2date( 'm', $post->post_date ) . "\n"; + echo " " . mysql2date( 'Y', $post->post_date ) . "\n"; + echo " " . mysql2date( 'H', $post->post_date ) . "\n"; + echo " " . mysql2date( 'i', $post->post_date ) . "\n"; + if( $post->post_type == 'post' ) { + echo ' ' . wp_specialchars(get_tags_to_edit( $post->ID ), 1) . "\n"; + echo ' ' . implode( ',', wp_get_post_categories( $post->ID ) ) . "\n"; + echo ' ' . (is_sticky($post->ID) ? 'sticky' : '') . "\n"; + } + if( $post->post_type == 'page' ) { + echo " $post->post_parent\n"; + echo ' ' . wp_specialchars(get_post_meta( $post->ID, '_wp_page_template', true ), 1) . "\n"; + echo " " . wp_specialchars($post->post_password, 1) . "\n"; + echo " $post->menu_order\n"; + } + echo " \n"; + } + + echo ''; +} + +function post_rows( $posts = array() ) { global $wp_query, $post, $mode; add_filter('the_title','wp_specialchars'); // Create array of post IDs. $post_ids = array(); - foreach ( $wp_query->posts as $a_post ) + + if ( empty($posts) ) + $posts = &$wp_query->posts; + + foreach ( $posts as $a_post ) $post_ids[] = $a_post->ID; $comment_pending_count = get_pending_comments_num($post_ids); - if ( empty($comment_pending_count[$post->ID]) ) + if ( empty($comment_pending_count) ) $comment_pending_count = array(); - while ( have_posts() ) { - the_post(); - + foreach ( $posts as $post ) { if ( empty($comment_pending_count[$post->ID]) ) $comment_pending_count[$post->ID] = 0; @@ -436,6 +661,7 @@ function _post_row($a_post, $pending_comments, $mode) { $global_post = $post; $post = $a_post; + setup_postdata($post); $class = 'alternate' == $class ? '' : 'alternate'; global $current_user; @@ -483,9 +709,9 @@ function _post_row($a_post, $pending_comments, $mode) { } if ( 'excerpt' == $mode ) { ?> - + - + ID . '">' . __('Edit') . ''; + $actions['inline'] = '' . __('Quick Edit') . ''; $actions['delete'] = "ID) . "' onclick=\"if ( confirm('" . js_escape(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this draft '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this post '%s'\n 'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . ""; $action_count = count($actions); $i = 0; @@ -515,7 +742,7 @@ function _post_row($a_post, $pending_comments, $mode) { case 'categories': ?> - - -
+
- + - + " rel="permalink"> post_status ) { @@ -654,7 +881,7 @@ foreach ($posts_columns as $column_name=>$column_display_name) { case 'cb': ?> - + $column_display_name) { } } ?> - + $column_display_name) { $actions = array(); $actions['edit'] = '' . __('Edit') . ''; + $actions['inline'] = '' . __('Quick Edit') . ''; $actions['delete'] = "ID) . "' onclick=\"if ( confirm('" . js_escape(sprintf( ('draft' == $page->post_status) ? __("You are about to delete this draft '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this page '%s'\n 'Cancel' to stop, 'OK' to delete."), $page->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . ""; $action_count = count($actions); $i = 0; @@ -711,7 +939,7 @@ foreach ($posts_columns as $column_name=>$column_display_name) { case 'comments': ?> -
+
ID ); $pending_phrase = sprintf( __('%s pending'), number_format( $left ) ); @@ -727,13 +955,13 @@ foreach ($posts_columns as $column_name=>$column_display_name) { case 'author': ?> - + - + " rel="permalink"> post_status ) { @@ -1240,7 +1468,7 @@ function meta_form() { } -function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) { +function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { global $wp_locale, $post, $comment; if ( $for_post ) @@ -1261,7 +1489,7 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) { $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj ); $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj ); - $month = "\n"; for ( $i = 1; $i < 13; $i = $i +1 ) { $month .= "\t\t\t" . '"; + echo "\n\t"; parent_dropdown( $default, $item->ID, $level +1 ); } } else { diff --git a/wp-admin/js/forms.js b/wp-admin/js/forms.js index efd56a7bbe..a586bd8016 100644 --- a/wp-admin/js/forms.js +++ b/wp-admin/js/forms.js @@ -1,12 +1,12 @@ function checkAll(jQ) { // use attr( checked, fn ) - jQuery(jQ).find( 'tbody:visible :checkbox' ).attr( 'checked', function() { + jQuery(jQ).find( 'tbody:visible .check-column :checkbox' ).attr( 'checked', function() { return jQuery(this).attr( 'checked' ) ? '' : 'checked'; } ); } jQuery( function($) { var lastClicked = false; - $( 'tbody :checkbox' ).click( function(e) { + $( 'tbody .check-column :checkbox' ).click( function(e) { if ( 'undefined' == e.shiftKey ) { return true; } if ( e.shiftKey ) { if ( !lastClicked ) { return true; } diff --git a/wp-admin/js/inline-edit.js b/wp-admin/js/inline-edit.js new file mode 100644 index 0000000000..d8328c1062 --- /dev/null +++ b/wp-admin/js/inline-edit.js @@ -0,0 +1,186 @@ +var postType = null; +var postView = null; +var postsXml = null; +var inlineRows = null; + +jQuery(document).ready(function() { + postType = window.location.href.indexOf('edit.php') == -1 ? 'page' : 'post'; + postView = window.location.href.indexOf('mode=excerpt') == -1 ? 'list' : 'excerpt'; + + // get IDs of all editable rows + inlineRows = jQuery('table.widefat .check-column :checkbox[name="post[]"]').parents('tr'); + + // prepare the edit row + var blankRow = jQuery('#inline-edit'); + jQuery('ul.categories *', blankRow).removeAttr('id'); + jQuery('ul.categories label', blankRow).removeAttr('for'); + blankRow.attr('title', 'Double-click to cancel') + .dblclick(function() { toggleRow(this); }) + .keypress(function(event) { if(event.which == 13) return saveRow(this); }); + jQuery('span.cancel a', blankRow).click(function() { return revertRow(this); }); + jQuery('span.save a', blankRow).click(function() { return saveRow(this); }); + + // add events and get data + inlineRows.dblclick(function() { toggleRow(this); }); + addEvents(inlineRows); + + // get data + getInlineData('all'); +}); + +function toggleRow(el) { + jQuery('#'+postType+'-'+getRowId(el)).css('display') == 'none' ? revertRow(el) : editRow(el); +} + +// add events to links and make rows double-clickable +function addEvents(rows) { + rows.each(function() { + var row = jQuery(this); + jQuery('a.editinline', row).click(function() { editRow(this); return false; }); + row.attr('title', 'Double-click to edit'); + }); +} + +function getInlineData(id) { + if(id == 'all') { + var editable = []; + inlineRows.each(function(i) { editable[i] = getRowId(this); }); + id = editable.join(','); + } + + if(id == '') + return false; + + jQuery.post('admin-ajax.php', + { + action: 'inline-data', + posts: id + }, + function(xml) { + if(id.indexOf(',') == -1) { + var newData = jQuery(xml).find('post[id="'+id+'"]'); + jQuery(postsXml).find('post[id="'+id+'"]').replaceWith(newData); + } else { + postsXml = xml; + } + }, 'xml' + ); +} + +function editRow(id) { + if(typeof(id) == 'object') + id = getRowId(id); + + var blankRow = jQuery('#inline-edit'); + + var fields = ['post_title', 'post_name', 'post_author', 'post_status', 'jj', 'mm', 'aa', 'hh', 'mn']; + if(postType == 'page') fields.push('post_parent', 'menu_order', 'page_template', 'post_password'); + if(postType == 'post') fields.push('tags_input'); + + // add the new blank row + var editRow = blankRow.clone(true); + jQuery(editRow).attr('id', 'edit-'+id).addClass('inline').show(); + if(jQuery('#'+postType+'-'+id).hasClass('alternate')) + jQuery(editRow).addClass('alternate'); + jQuery('#'+postType+'-'+id).hide().after(editRow); + + // populate the data + var rowData = jQuery(postsXml).find('post[id="'+id+'"]'); + for(var f = 0; f < fields.length; f++) { + jQuery(':input[name="'+fields[f]+'"]', editRow).val(jQuery(fields[f], rowData).text()); + } + + // ping, comments, and privacy + if(jQuery('comment_status', rowData).text() == 'open') + jQuery('input[name="comment_status"]', editRow).select(); + if(jQuery('ping_status', rowData).text() == 'open') + jQuery('input[name="ping_status"]', editRow).select(); + if(jQuery('sticky', rowData).text() == 'sticky') + jQuery('input[name="sticky"]', editRow).select(); + + // categories + var categories = jQuery('post_category', rowData).text().split(','); + jQuery(categories).each(function() { + jQuery('ul.categories :checkbox[value="'+this+'"]', editRow).select(); + }); + + // handle the post status + var status = jQuery('post_status', rowData).text(); + if(status != 'future') jQuery('select[name="post_status"] option[value="future"]', editRow).remove(); + if(status == 'private') jQuery('input[name="page_private"]', editRow).select(); + + // enable autocomplete for tags + if(postType == 'post') { + jQuery('tr.inline textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } ); + } + + // remove the current page and children from the parent dropdown + var pageOpt = jQuery('select[name="post_parent"] option[value="'+id+'"]', editRow); + if(pageOpt.length > 0) { + var pageLevel = pageOpt[0].className.split('-')[1]; + var nextPage = pageOpt; var pageLoop = true; + while(pageLoop) { + var nextPage = nextPage.next('option'); + var nextLevel = nextPage[0].className.split('-')[1]; + if(nextLevel <= pageLevel) + pageLoop = false; + else { + nextPage.remove(); + nextPage = pageOpt; + } + } + pageOpt.remove(); + } + + return false; +} + +function saveRow(id) { + if(typeof(id) == 'object') + id = getRowId(id); + + jQuery('#edit-'+id+' .check-column').html('Saving...'); + + var params = { + action: 'inline-save', + post_type: postType, + post_ID: id, + edit_date: 'true', + post_view: postView + }; + + var fields = jQuery('#edit-'+id+' :input').fieldSerialize(); + params = fields + '&' + jQuery.param(params); + + // make ajax request + jQuery.post('admin-ajax.php', params, + function(html) { + var row = jQuery('#'+postType+'-'+id); + jQuery('#edit-'+id).hide(); + html = jQuery(html).html(); + row.html(html).show(); + row.animate( { backgroundColor: '#FFFBCC' }, 200) + .animate( { backgroundColor: row.css('background-color') }, 500); + getInlineData(id); + addEvents(row); + } + ); + + return false; +} + +function revertRow(id) { + if(typeof(id) == 'object') + id = getRowId(id); + + jQuery('#edit-'+id).remove(); + jQuery('#'+postType+'-'+id).show(); + + return false; +} + +function getRowId(obj) { + var id = obj.tagName == 'TR' ? obj.id : jQuery(obj).parents('tr').attr('id'); + var parts = id.split('-'); + return parts[parts.length - 1]; +} \ No newline at end of file diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css index 34fc53c7a2..35f493c571 100644 --- a/wp-admin/wp-admin.css +++ b/wp-admin/wp-admin.css @@ -2139,3 +2139,122 @@ p#post-search-prep { .metabox-prefs label input { margin: 0 5px 0 2px; } + + +/* Inline Editor */ + +.inline { + font-size: 10px; +} + +.inline td { + padding-right: 4px; + padding-left: 7px; +} + +.inline input, .inline select, .inline textarea { + font-size: 10px !important; + padding: 2px; + border: 1px solid #ddd; +} + +.inline td.date { + width: 87px; +} + +.inline td.page-title { + width: 495px; +} + +.inline td.post-title input.title { + width: 250px; +} + +.inline td.post-title input.slug { + width: 222px; + float: right; +} + +.inline div.title { + float: left; +} + +.inline div.title input.title { + font-size: 12px !important; +} + +.inline div.title label { + float: left; + margin-top: 4px; +} + +.inline td.page-title input.slug { + width: 123px; + float: right; +} + +.inline div.other, .inline div.more { + width: 190px; + float: left; + padding-left: 5px; +} + +.inline div.other label, .inline div.more label { + display: block; float: left; + width: 54px; + margin-top: 4px; +} + +.inline div.other select { + width: 133px; +} + +.inline div.more { + width: 125px; +} + +.inline div.more input { + width: 60px; +} + +.inline td.author select { + width: 110px; +} + +.inline ul.categories { + list-style: none; + padding: 0; margin: 0; + height: 65px; + overflow: auto; + font-size: 10px; +} + +.inline ul.categories ul.children { + list-style: none; + padding-left: 15px; +} + +.inline ul.categories li { + margin-bottom: 2px; +} + +.inline ul.categories input { + vertical-align: middle; + padding: 0; border: 0; +} + +.inline td.tags textarea { + height: 58px; width: 100%; +} + +.inline td.comments { + padding-left: 0; +} + +.inline td.status select { + width: 98px; +} + +.inline td.status input { + vertical-align: middle; +} \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 64d13aa6b8..b3ef41cdca 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -241,6 +241,8 @@ function wp_default_scripts( &$scripts ) { )); $scripts->add( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'jquery' ), '20080625' ); + + $scripts->add( 'inline-edit', '/wp-admin/js/inline-edit.js', array( 'jquery', 'jquery-form', 'suggest' ), '20080812' ); $scripts->add( 'plugin-install', '/wp-admin/js/plugin-install.js', array( 'thickbox', 'jquery' ), '20080803' ); $scripts->localize( 'plugin-install', 'plugininstallL10n', array(