On the fly list manipulation. Delete in style. Mad props to mdawaffe. Applies to #1634

git-svn-id: http://svn.automattic.com/wordpress/trunk@2832 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-08-31 02:39:17 +00:00
parent 5fd72f93fb
commit c7771dcaaf
11 changed files with 219 additions and 27 deletions

View File

@ -442,12 +442,12 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) {
$count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");
$pad = str_repeat('— ', $level);
if ( current_user_can('manage_categories') )
$edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>" . __('Edit') . "</a></td><td><a href='categories.php?action=delete&amp;cat_ID=$category->cat_ID' onclick=\"return confirm('". sprintf(__("You are about to delete the category \'%s\'. All of its posts will go to the default category.\\n \'OK\' to delete, \'Cancel\' to stop."), $wpdb->escape($category->cat_name)) . "')\" class='delete'>" . __('Delete') . "</a>";
$edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->cat_ID' class='edit'>" . __('Edit') . "</a></td><td><a href='categories.php?action=delete&amp;cat_ID=$category->cat_ID' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . sprintf(__("You are about to delete the category &quot;%s&quot;. All of its posts will go to the default category.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars($category->cat_name, 1)) . "' );\" class='delete'>" . __('Delete') . "</a>";
else
$edit = '';
$class = ('alternate' == $class) ? '' : 'alternate';
echo "<tr class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td>
echo "<tr id='cat-$category->cat_ID' class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td>
<td>$category->category_description</td>
<td>$count</td>
<td>$edit</td>
@ -473,7 +473,7 @@ function page_rows( $parent = 0, $level = 0, $pages = 0 ) {
$id = $post->ID;
$class = ('alternate' == $class) ? '' : 'alternate';
?>
<tr class='<?php echo $class; ?>'>
<tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
<th scope="row"><?php echo $post->ID; ?></th>
<td>
<?php echo $pad; ?><?php the_title() ?>
@ -482,7 +482,7 @@ function page_rows( $parent = 0, $level = 0, $pages = 0 ) {
<td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>
<td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td>
<td><?php if ( current_user_can('edit_pages') ) { echo "<a href='post.php?action=edit&amp;post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>
<td><?php if ( current_user_can('edit_pages') ) { echo "<a href='post.php?action=delete&amp;post=$id' class='delete' onclick=\"return confirm('" . sprintf(__("You are about to delete this post \'%s\'\\n \'OK\' to delete, \'Cancel\' to stop."), the_title('','',0)) . "')\">" . __('Delete') . "</a>"; } ?></td>
<td><?php if ( current_user_can('edit_pages') ) { echo "<a href='post.php?action=delete&amp;post=$id' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars(get_the_title('','',0), 1)) . "' );\">" . __('Delete') . "</a>"; } ?></td>
</tr>
<?php

View File

@ -76,6 +76,8 @@ addLoadEvent(blurry);
//]]>
</script>
<script type="text/javascript" src="../wp-includes/js/fat.js"></script>
<script type="text/javascript" src="../wp-includes/js/tw-sack.js"></script>
<script type="text/javascript" src="list-manipulation.js"></script>
<?php if ( isset( $editing ) ) : ?>
<?php if ( 'true' == get_user_option('rich_editing') ) :?>
<script type="text/javascript" src="../wp-includes/js/tinymce/tiny_mce_src.js"></script>
@ -104,7 +106,6 @@ tinyMCE.init({
<script type="text/javascript" src="../wp-includes/js/dbx-key.js"></script>
<?php if ( current_user_can('manage_categories') ) : ?>
<script type="text/javascript" src="../wp-includes/js/tw-sack.js"></script>
<script type="text/javascript">
var ajaxCat = new sack();
var newcat;

View File

@ -120,7 +120,7 @@ $messages[3] = __('Category updated.');
<?php else : ?>
<h2><?php _e('Categories') ?> </h2>
<?php endif; ?>
<table width="100%" cellpadding="3" cellspacing="3">
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
<tr>
<th scope="col"><?php _e('ID') ?></th>
<th scope="col"><?php _e('Name') ?></th>
@ -133,6 +133,8 @@ cat_rows();
?>
</table>
<div id="ajax-response"></div>
</div>
<?php if ( current_user_can('manage_categories') ) : ?>

View File

@ -76,7 +76,7 @@ if ('view' == $mode) {
else
$start = '';
echo "<ol class='commentlist' $start>";
echo "<ol id='the-list' class='commentlist' $start>";
$i = 0;
foreach ($comments as $comment) {
++$i; $class = '';
@ -86,7 +86,7 @@ if ('view' == $mode) {
$class .= ' unapproved';
if ($i % 2)
$class .= ' alternate';
echo "<li class='$class'>";
echo "<li id='comment-$comment->comment_ID' class='$class'>";
?>
<p><strong><?php _e('Name:') ?></strong> <?php comment_author() ?> <?php if ($comment->comment_author_email) { ?>| <strong><?php _e('E-mail:') ?></strong> <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url ) { ?> | <strong><?php _e('URI:') ?></strong> <?php comment_author_url_link() ?> <?php } ?>| <strong><?php _e('IP:') ?></strong> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
@ -97,7 +97,7 @@ if ('view' == $mode) {
echo " | <a href=\"post.php?action=editcomment&amp;comment=".$comment->comment_ID."\">" . __('Edit Comment') . "</a>";
}
if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
echo " | <a href=\"post.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return confirm('" . sprintf(__("You are about to delete this comment by \'%s\'\\n \'Cancel\' to stop, \'OK\' to delete."), $comment->comment_author) . "')\">" . __('Delete Comment') . "</a> &#8212; ";
echo " | <a href=\"post.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return deleteSomething( 'comment', $comment->comment_ID, '" . sprintf(__("You are about to delete this comment by &quot;%s&quot;.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete."), wp_specialchars( $comment->comment_author, 1 )) . "' );\">" . __('Delete Comment') . "</a> &#8212; ";
} // end if any comments to show
// Get post title
if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
@ -111,6 +111,8 @@ if ('view' == $mode) {
<?php } // end foreach ?>
</ol>
<div id="ajax-response"></div>
<?php
} else {
@ -168,4 +170,4 @@ if ('view' == $mode) {
</div>
<?php include('admin-footer.php'); ?>
<?php include('admin-footer.php'); ?>

View File

@ -14,7 +14,7 @@ $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'sta
if ($posts) {
?>
<table width="100%" cellpadding="3" cellspacing="3">
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
<tr>
<th scope="col"><?php _e('ID') ?></th>
<th scope="col"><?php _e('Title') ?></th>
@ -26,6 +26,9 @@ if ($posts) {
</tr>
<?php page_rows(); ?>
</table>
<div id="ajax-response"></div>
<?php
} else {
?>
@ -38,4 +41,4 @@ if ($posts) {
</div>
<?php include('admin-footer.php'); ?>
<?php include('admin-footer.php'); ?>

View File

@ -128,7 +128,7 @@ $posts_columns['control_delete'] = '';
?>
<table width="100%" cellpadding="3" cellspacing="3">
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
<tr>
<?php foreach($posts_columns as $column_display_name) { ?>
@ -142,7 +142,7 @@ $bgcolor = '';
foreach ($posts as $post) { start_wp();
$class = ('alternate' == $class) ? '' : 'alternate';
?>
<tr class='<?php echo $class; ?>'>
<tr id='post-<?php echo $id; ?>' class='<?php echo $class; ?>'>
<?php
@ -202,7 +202,7 @@ foreach($posts_columns as $column_name=>$column_display_name) {
case 'control_delete':
?>
<td><?php if ( current_user_can('edit_post',$post->ID) ) { echo "<a href='post.php?action=delete&amp;post=$id' class='delete' onclick=\"return confirm('" . sprintf(__("You are about to delete this post \'%s\'\\n \'OK\' to delete, \'Cancel\' to stop."), wp_specialchars(get_the_title('', ''), 1) ) . "')\">" . __('Delete') . "</a>"; } ?></td>
<td><?php if ( current_user_can('edit_post',$post->ID) ) { echo "<a href='post.php?action=delete&amp;post=$id' class='delete' onclick=\"return deleteSomething( 'post', " . $id . ", '" . sprintf(__("You are about to delete this post &quot;%s&quot;.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars(get_the_title('', ''), 1) ) . "' );\">" . __('Delete') . "</a>"; } ?></td>
<?php
break;
@ -225,7 +225,9 @@ foreach($posts_columns as $column_name=>$column_display_name) {
<?php
} // end if ($posts)
?>
</table>
</table>
<div id="ajax-response"></div>
<div class="navigation">
<div class="alignleft"><?php next_posts_link(__('&laquo; Previous Entries')) ?></div>

View File

@ -276,7 +276,7 @@ switch ($action) {
<div class="wrap">
<h2><?php _e('Link Categories:') ?></h2>
<table width="100%" cellpadding="5" cellspacing="0" border="0">
<table id="the-list" width="100%" cellpadding="5" cellspacing="0" border="0">
<tr>
<th rowspan="2" valign="bottom"><?php _e('Name') ?></th>
<th rowspan="2" valign="bottom"><?php _e('ID') ?></th>
@ -334,7 +334,7 @@ foreach ($results as $row) {
break;
}
?>
<tr valign="middle" align="center" <?php echo $style ?> style="border-bottom: 1px dotted #9C9A9C;">
<tr id="link-category-<?php echo $row->cat_id; ?>" valign="middle" align="center" <?php echo $style ?> style="border-bottom: 1px dotted #9C9A9C;">
<td><?php echo wp_specialchars($row->cat_name)?></td>
<td ><?php echo $row->cat_id?></td>
<td><?php echo $row->auto_toggle == 'Y' ? __('Yes') : __('No') ?></td>
@ -349,7 +349,7 @@ foreach ($results as $row) {
<td nowrap="nowrap"><?php echo htmlentities($row->text_after_all)?></td>
<td><?php echo $row->list_limit ?></td>
<td><a href="link-categories.php?cat_id=<?php echo $row->cat_id?>&amp;action=Edit" class="edit"><?php _e('Edit') ?></a></td>
<td><a href="link-categories.php?cat_id=<?php echo $row->cat_id?>&amp;action=Delete" onclick="return confirm('<?php _e("You are about to delete this category.\\n \'Cancel\' to stop, \'OK\' to delete.") ?>');" class="delete"><?php _e('Delete') ?></a></td>
<td><a href="link-categories.php?cat_id=<?php echo $row->cat_id?>&amp;action=Delete" onclick="return deleteSomething( 'link category', <?php echo $row->cat_id . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; link category.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete."), wp_specialchars($row->cat_name,1)); ?>' );" class="delete"><?php _e('Delete') ?></a></td>
</tr>
<?php
++$i;
@ -358,6 +358,8 @@ foreach ($results as $row) {
</table>
<p><?php _e('These are the defaults for when you call a link category with no additional arguments. All of these settings may be overwritten.') ?></p>
<div id="ajax-response"></div>
</div>
<div class="wrap">

View File

@ -629,7 +629,7 @@ function checkAll(form)
<input type="hidden" name="action" value="" />
<input type="hidden" name="order_by" value="<?php echo wp_specialchars($order_by, 1); ?>" />
<input type="hidden" name="cat_id" value="<?php echo (int) $cat_id ?>" />
<table width="100%" cellpadding="3" cellspacing="3">
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
<tr>
<th width="15%"><?php _e('Name') ?></th>
<th><?php _e('URI') ?></th>
@ -671,9 +671,9 @@ function checkAll(form)
$image = ($link->link_image != null) ? __('Yes') : __('No');
$visible = ($link->link_visible == 'Y') ? __('Yes') : __('No');
++$i;
$style = ($i % 2) ? ' class="alternate"' : '';
$style = ($i % 2) ? '' : ' class="alternate"';
?>
<tr valign="middle" <?php echo $style; ?>>
<tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>>
<td><strong><?php echo $link->link_name; ?></strong><br />
<?php
echo sprintf(__('Description: %s'), $link->link_description) . "</td>";
@ -688,17 +688,19 @@ LINKS;
if ($show_buttons) {
echo '<td><a href="link-manager.php?link_id=' . $link->link_id . '&amp;action=linkedit" class="edit">' . __('Edit') . '</a></td>';
echo '<td><a href="link-manager.php?link_id=' . $link->link_id . '&amp;action=Delete"' . " onclick=\"return confirm('" . __("You are about to delete this link.\\n \'Cancel\' to stop, \'OK\' to delete.") . "');" . '" class="delete">' . __('Delete') . '</a></td>';
echo '<td><a href="link-manager.php?link_id=' . $link->link_id . '&amp;action=Delete"' . " onclick=\"return deleteSomething( 'link', $link->link_id , '" . sprintf(__("You are about to delete the &quot;%s&quot; link to %s.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete."), wp_specialchars($link->link_name,1), wp_specialchars($link->link_url)) . '\' );" class="delete">' . __('Delete') . '</a></td>';
echo '<td><input type="checkbox" name="linkcheck[]" value="' . $link->link_id . '" /></td>';
} else {
echo "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>\n";
}
echo "\n\t</tr>";
echo "\n </tr>\n";
}
}
?>
</table>
<div id="ajax-response"></div>
</div>
<div class="wrap">

View File

@ -0,0 +1,96 @@
var listItems;
var reg_color = '#FFFFFF';
var alt_color = '#F1F1F1';
addLoadEvent(getListItems);
function deleteSomething( what, id, message ) {
what.replace('-', ' ');
if (!message) message = 'Are you sure you want to delete this ' + what + '?';
if ( confirm(message) ) {
return ajaxDelete( what.replace(' ', '-'), id );
} else {
return false;
}
}
function getResponseElement() {
var p = document.getElementById('ajax-response-p');
if (!p) {
p = document.createElement('p');
p.id = 'ajax-response-p';
document.getElementById('ajax-response').appendChild(p);
return p;
}
}
function ajaxDelete(what, id) {
ajaxDel = new sack('list-manipulation.php');
if ( ajaxDel.failed ) return true;
ajaxDel.myResponseElement = getResponseElement();
ajaxDel.method = 'POST';
ajaxDel.onLoading = function() { ajaxDel.myResponseElement.innerHTML = 'Sending Data...'; };
ajaxDel.onLoaded = function() { ajaxDel.myResponseElement.innerHTML = 'Data Sent...'; };
ajaxDel.onInteractive = function() { ajaxDel.myResponseElement.innerHTML = 'Processing Data...'; };
ajaxDel.onCompletion = function() { removeThisItem( what + '-' + id ); };
ajaxDel.runAJAX('action=delete-' + what + '&id=' + id);
return false;
}
function removeThisItem(id) {
var response = ajaxDel.response;
if ( isNaN(response) ) { alert(response); }
response = parseInt(response, 10);
if ( -1 == response ) { ajaxDel.myResponseElement.innerHTML = "You don't have permission to do that."; }
else if ( 0 == response ) { ajaxDel.myResponseElement.interHTML = "Something odd happened. Try refreshing the page? Either that or what you tried to delete never existed in the first place."; }
else if ( 1 == response ) {
item = document.getElementById(id);
Fat.fade_element(item.id,null,700,'#FF3333');
setTimeout('item.parentNode.removeChild(item)', 705);
var pos = getListPos(id);
listItems.splice(pos,1);
recolorList(pos);
ajaxDel.myResponseElement.parentNode.removeChild(ajaxDel.myResponseElement);
}
}
function getListPos(id) {
for (var i = 0; i < listItems.length; i++) {
if (id == listItems[i]) {
var pos = i;
break;
}
}
return pos;
}
function getListItems() {
if (list) return;
listItems = new Array();
var extra = false;
var list = document.getElementById('the-list');
if (!list) { var list = document.getElementById('the-list-x'); extra = true; }
if (list) {
var items = list.getElementsByTagName('tr');
if (!items[0]) { items = list.getElementsByTagName('li'); }
for (var i=0; i<items.length; i++) { listItems.push(items[i].id); }
if (extra) { listItems.splice(0,1); }
}
}
function recolorList(pos,dur,from) {
if (!pos) pos = 0;
if (!from) {
reg_from = alt_color;
alt_from = reg_color;
} else {
reg_from = from;
alt_from = from;
}
for (var i = pos; i < listItems.length; i++) {
if (i % 2 == 1) Fat.fade_element(listItems[i],null,dur,reg_from,reg_color);
else Fat.fade_element(listItems[i],null,dur,alt_from,alt_color);
}
}

View File

@ -0,0 +1,80 @@
<?php
require_once('../wp-config.php');
require_once('admin-functions.php');
get_currentuserinfo();
if ( !$current_user )
die('-1');
function grab_results() {
global $ajax_results;
$ajax_results = func_get_arg(0);
}
function get_out_now() { exit; }
add_action('shutdown', 'get_out_now', -1);
// check_admin_referer();
switch ( $_POST['action'] ) :
case 'delete-link' :
$id = (int) $_POST['id'];
if ( !current_user_can('manage_links') )
die ('-1');
if ( $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$id'") )
die('1');
else die('0');
break;
case 'delete-post' :
case 'delete-page' :
$id = (int) $_POST['id'];
if ( !current_user_can('edit_post', $post_id) )
die('-1');
if ( wp_delete_post($id) )
die('1');
else die('0');
break;
case 'delete-cat' :
if ( !current_user_can('manage_categories') )
die ('-1');
$id = (int) $_POST['id'];
$cat_name = get_catname($cat_ID);
if ( wp_delete_category($id) )
die('1');
else die('0');
break;
case 'delete-comment' :
$id = (int) $_POST['id'];
if ( !$comment = get_comment($id) )
die('0');
if ( !current_user_can('edit_post', $comment->comment_post_ID) )
die('-1');
if ( wp_set_comment_status($comment->comment_ID, "delete") ) {
do_action('delete_comment', $comment->comment_ID);
die('1');
} else {
die('0');
}
break;
case 'delete-link-category' :
$id = (int) $_POST['id'];
if ( 1 == $id )
die('0');
if ( !current_user_can('manage_links') )
die('-1');
if ( $wpdb->query("DELETE FROM $wpdb->linkcategories WHERE cat_id='$id'") ) {
$wpdb->query("UPDATE $wpdb->links SET link_category=1 WHERE link_category='$id'");
die('1');
} else {
die('0');
}
break;
endswitch;
?>

View File

@ -130,7 +130,7 @@ if ($comments) {
<h2><?php _e('Moderation Queue') ?></h2>
<form name="approval" action="moderation.php" method="post">
<input type="hidden" name="action" value="update" />
<ol id="comments" class="commentlist">
<ol id="the-list" class="commentlist">
<?php
$i = 0;
foreach($comments as $comment) {
@ -147,7 +147,7 @@ $i = 0;
echo '<a href="post.php?action=editcomment&amp;comment='.$comment->comment_ID.'">' . __('Edit') . '</a> | ';?>
<a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php _e('View Post') ?></a> |
<?php
echo " <a href=\"post.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return confirm('" . sprintf(__("You are about to delete this comment by \'%s\'\\n \'Cancel\' to stop, \'OK\' to delete."), $comment->comment_author) . "')\">" . __('Delete just this comment') . "</a> | "; ?> <?php _e('Bulk action:') ?>
echo " <a href=\"post.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return deleteSomething( 'comment', $comment->comment_ID, '" . sprintf(__("You are about to delete this comment by &quot;%s&quot;.\\n&quot;Cancel&quot; to stop, &quot;OK&quot; to delete."), wp_specialchars($comment->comment_author, 1)) . "' );\">" . __('Delete just this comment') . "</a> | "; ?> <?php _e('Bulk action:') ?>
<input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-approve" value="approve" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-approve"><?php _e('Approve') ?></label>
<input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-spam" value="spam" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-spam"><?php _e('Spam') ?></label>
<input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-delete" value="delete" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-delete"><?php _e('Delete') ?></label>
@ -160,6 +160,8 @@ echo " <a href=\"post.php?action=deletecomment&amp;p=".$comment->comment_post_ID
?>
</ol>
<div id="ajax-response"></div>
<p class="submit"><input type="submit" name="submit" value="<?php _e('Moderate Comments &raquo;') ?>" /></p>
<script type="text/javascript">
// <![CDATA[
@ -216,4 +218,4 @@ break;
}
include('admin-footer.php') ?>
include('admin-footer.php') ?>