Better AJAX feedback messages and markup fixes. Props mdawaffe. fixes #3208

git-svn-id: http://svn.automattic.com/wordpress/trunk@4583 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-12-01 23:00:04 +00:00
parent d1245edae6
commit ccacbf47cd
8 changed files with 40 additions and 25 deletions

View File

@ -147,7 +147,7 @@ case 'add-cat' : // From Manage->Categories
'what' => 'cat',
'id' => $cat->cat_ID,
'data' => _cat_row( $cat, $level, $cat_full_name ),
'supplemental' => array('name' => $cat_full_name)
'supplemental' => array('name' => $cat_full_name, 'show-link' => sprintf(__( 'Category <a href="#%s">%s</a> added' ), "cat-$cat->cat_ID", $cat_full_name))
) );
$x->send();
break;
@ -211,10 +211,12 @@ case 'add-user' :
echo "<p>$message<p>";
exit;
}
$user_object = new WP_User( $user_id );
$x = new WP_Ajax_Response( array(
'what' => 'user',
'id' => $user_id,
'data' => user_row( $user_id )
'data' => user_row( $user_object ),
'supplemental' => array('show-link' => sprintf(__( 'User <a href="#%s">%s</a> added' ), "user-$user_id", $user_object->user_login))
) );
$x->send();
break;

View File

@ -814,11 +814,13 @@ function user_row( $user_object, $style = '' ) {
if ( $numposts > 0 ) {
$r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
$r .= sprintf( __('View %1$s %2$s' ), $numposts, __ngettext( 'post', 'posts', $numposts ));
$r .= '</a>';
}
$r .= "</td>\n\t\t<td>";
$edit_link = add_query_arg( 'wp_http_referer', wp_specialchars( urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" );
if ( current_user_can( 'edit_user', $user_object->ID ) )
if ( current_user_can( 'edit_user', $user_object->ID ) ) {
$edit_link = wp_specialchars( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=$user_object->ID" ) );
$r .= "<a href='$edit_link' class='edit'>".__( 'Edit' )."</a>";
}
$r .= "</td>\n\t</tr>";
return $r;
}

View File

@ -16,6 +16,7 @@ if ( ! empty($cat_ID) ) {
<div class="wrap">
<h2><?php echo $heading ?></h2>
<div id="ajax-response"></div>
<?php echo $form ?>
<input type="hidden" name="action" value="<?php echo $action ?>" />
<input type="hidden" name="cat_ID" value="<?php echo $category->cat_ID ?>" />
@ -41,7 +42,6 @@ if ( ! empty($cat_ID) ) {
</tr>
</table>
<p class="submit"><input type="submit" name="submit" value="<?php echo $submit_text ?>" /></p>
<div id="ajax-response"></div>
<?php do_action('edit_category_form', $category); ?>
</form>
</div>

View File

@ -2,7 +2,8 @@ addLoadEvent(function() {
theListEls = document.getElementsByTagName('tbody');
theUserLists = new Array();
for ( var l = 0; l < theListEls.length; l++ ) {
theUserLists[theListEls[l].id] = new listMan(theListEls[l].id);
if ( theListEls[l].id )
theUserLists[theListEls[l].id] = new listMan(theListEls[l].id);
}
addUserInputs = document.getElementById('adduser').getElementsByTagName('input');
for ( var i = 0; i < addUserInputs.length; i++ ) {

View File

@ -376,7 +376,7 @@ default:
foreach($roleclasses as $role => $roleclass) {
uksort($roleclass, "strnatcasecmp");
?>
<tbody>
<tr>
<?php if ( !empty($role) ) : ?>
<th colspan="7"><h3><?php echo $wp_roles->role_names[$role]; ?></h3></th>
@ -392,7 +392,7 @@ foreach($roleclasses as $role => $roleclass) {
<th><?php _e('Website') ?></th>
<th colspan="2" style="text-align: center"><?php _e('Actions') ?></th>
</tr>
</thead>
</tbody>
<tbody id="role-<?php echo $role; ?>"><?php
$style = '';
foreach ( (array) $roleclass as $user_object ) {
@ -437,7 +437,19 @@ foreach ( (array) $roleclass as $user_object ) {
<div class="wrap">
<h2 id="add-new-user"><?php _e('Add New User') ?></h2>
<?php if ( is_wp_error( $add_user_errors ) ) : ?>
<div class="error">
<?php
foreach ( $add_user_errors->get_error_messages() as $message )
echo "<p>$message</p>";
?>
</div>
<?php endif; ?>
<div id="ajax-response"></div>
<div class="narrow">
<?php echo '<p>'.sprintf(__('Users can <a href="%1$s">register themselves</a> or you can manually create users here.'), get_option('siteurl').'/wp-register.php').'</p>'; ?>
<form action="#add-new-user" method="post" name="adduser" id="adduser">
<?php wp_nonce_field('add-user') ?>
@ -488,18 +500,9 @@ foreach ( (array) $roleclass as $user_object ) {
<?php echo $referer; ?>
<input name="adduser" type="submit" id="addusersub" value="<?php _e('Add User &raquo;') ?>" />
</p>
</div>
</form>
<?php if ( is_wp_error( $add_user_errors ) ) : ?>
<div class="error">
<?php
foreach ( $add_user_errors->get_error_messages() as $message )
echo "<p>$message</p>";
?>
</div>
<?php endif; ?>
<div id="ajax-response"></div>
</div>
</div>
<?php

View File

@ -180,7 +180,7 @@ function wp_dropdown_categories($args = '') {
$output = '';
if ( ! empty($categories) ) {
$output = "<select name='$name' class='$class'>\n";
$output = "<select name='$name' id='$name' class='$class'>\n";
if ( $show_option_all ) {
$show_option_all = apply_filters('list_cats', $show_option_all);

View File

@ -37,6 +37,8 @@ Object.extend(listMan.prototype, {
ajaxAdd.addOnComplete( function(transport) {
var newItems = $A(transport.responseXML.getElementsByTagName(what));
if ( newItems ) {
var showLinkMessage = '';
var m = '';
newItems.each( function(i) {
var id = i.getAttribute('id');
var exists = $(what+'-'+id);
@ -44,10 +46,15 @@ Object.extend(listMan.prototype, {
tempObj.replaceListItem( exists, getNodeValue(i,'response_data'), update );
else
tempObj.addListItem( getNodeValue(i, 'response_data') );
if ( tempObj.showLink )
tempObj.showLink = id;
m = getNodeValue(i, 'show-link');
showLinkMessage += showLinkMessage ? "<br />\n" : '';
if ( m )
showLinkMessage += m;
else
showLinkMessage += "<a href='#" + what + '-' + id + "'><?php echo js_escape(__('Jump to new item')); ?>";
});
ajaxAdd.myResponseElement.update(tempObj.showLink ? ( "<div id='jumplink' class='updated fade'><p><a href='#" + what + '-' + tempObj.showLink + "'><?php js_escape(__('Jump to new item')); ?></a></p></div>" ) : '');
if ( tempObj.showLink && showLinkMessage )
ajaxAdd.myResponseElement.update("<div id='jumplink' class='updated fade'><p>" + showLinkMessage + "</p></div>");
}
if ( tempObj.addComplete && typeof tempObj.addComplete == 'function' )
tempObj.addComplete( what, where, update, transport );

View File

@ -21,16 +21,16 @@ class WP_Scripts {
$this->add( 'prototype', '/wp-includes/js/prototype.compressed.js', false, '1.5.0');
$this->add( 'autosave', '/wp-includes/js/autosave.js.php', array('prototype', 'sack'), '4508');
$this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), '4459');
$this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '4459');
$this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '4583');
if ( is_admin() ) {
$this->add( 'dbx-admin-key', '/wp-admin/dbx-admin-key-js.php', array('dbx'), '3651' );
$this->add( 'ajaxcat', '/wp-admin/cat-js.php', array('listman'), '3684' );
$this->add( 'admin-categories', '/wp-admin/categories.js', array('listman'), '3684' );
$this->add( 'admin-custom-fields', '/wp-admin/custom-fields.js', array('listman'), '3733' );
$this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '3847' );
$this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '3684' );
$this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '4583' );
$this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' );
$this->add( 'upload', '/wp-admin/upload-js.php', array('prototype'), '####' );
$this->add( 'upload', '/wp-admin/upload-js.php', array('prototype'), '4535' );
}
}