<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [2370] trunk: Better activity delete usability.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>2370</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-01-19 20:38:20 +0000 (Tue, 19 Jan 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Better activity delete usability.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivitytemplatetagsphp">trunk/bp-activity/bp-activity-templatetags.php</a></li>
<li><a href="#trunkbpthemesbpdefault_incajaxphp">trunk/bp-themes/bp-default/_inc/ajax.php</a></li>
<li><a href="#trunkbpthemesbpdefault_incglobaljs">trunk/bp-themes/bp-default/_inc/global.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivitytemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-templatetags.php (2369 => 2370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-templatetags.php        2010-01-19 17:51:30 UTC (rev 2369)
+++ trunk/bp-activity/bp-activity-templatetags.php        2010-01-19 20:38:20 UTC (rev 2370)
</span><span class="lines">@@ -472,7 +472,7 @@
</span><span class="cx">
</span><span class="cx">                                 /* Delete link */
</span><span class="cx">                                 if ( is_site_admin() || $bp->loggedin_user->id == $comment->user_id )
</span><del>-                                        $content .= ' &middot; <a href="' . wp_nonce_url( $bp->activity->id . '/delete/?cid=' . $comment->id, 'delete_activity_comment' ) . '" class="delete acomment-delete">' . __( 'Delete', 'buddypress' ) . '</a>';
</del><ins>+                                        $content .= ' &middot; <a href="' . wp_nonce_url( $bp->activity->id . '/delete/?cid=' . $comment->id, 'bp_activity_delete_link' ) . '" class="delete acomment-delete">' . __( 'Delete', 'buddypress' ) . '</a>';
</ins><span class="cx">
</span><span class="cx">                                 $content .= '</div>';
</span><span class="cx">                                 $content .= '<div class="acomment-content">' . apply_filters( 'bp_get_activity_content', $comment->content ) . '</div>';
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_incajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/ajax.php (2369 => 2370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/ajax.php        2010-01-19 17:51:30 UTC (rev 2369)
+++ trunk/bp-themes/bp-default/_inc/ajax.php        2010-01-19 20:38:20 UTC (rev 2370)
</span><span class="lines">@@ -144,23 +144,24 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'wp_ajax_new_activity_comment', 'bp_dtheme_new_activity_comment' );
</span><span class="cx">
</span><del>-function bp_dtheme_delete_activity_comment() {
</del><ins>+function bp_dtheme_delete_activity() {
</ins><span class="cx">         /* Check the nonce */
</span><del>-        check_admin_referer( 'delete_activity_comment' );
</del><ins>+        check_admin_referer( 'bp_activity_delete_link' );
</ins><span class="cx">
</span><span class="cx">         if ( !is_user_logged_in() ) {
</span><span class="cx">                 echo '-1';
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if ( empty( $_POST['comment_id'] ) || !is_numeric( $_POST['comment_id'] ) || !bp_activity_delete_by_activity_id( $_POST['comment_id'] ) ) {
-                echo '-1<div class="error"><p>' . __( 'There was a problem deleting that comment. Please try again.', 'buddypress' ) . '</p></div>';
</del><ins>+        if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) || !bp_activity_delete_by_activity_id( $_POST['id'] ) ) {
+                echo '-1<div class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>';
</ins><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         return true;
</span><span class="cx"> }
</span><del>-add_action( 'wp_ajax_delete_activity_comment', 'bp_dtheme_delete_activity_comment' );
</del><ins>+add_action( 'wp_ajax_delete_activity_comment', 'bp_dtheme_delete_activity' );
+add_action( 'wp_ajax_delete_activity', 'bp_dtheme_delete_activity' );
</ins><span class="cx">
</span><span class="cx"> function bp_dtheme_activity_loop( $type = 'all', $filter = false, $query_string = false, $per_page = 20, $page = 1 ) {
</span><span class="cx">         global $bp;
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_incglobaljs"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/global.js (2369 => 2370)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/global.js        2010-01-19 17:51:30 UTC (rev 2369)
+++ trunk/bp-themes/bp-default/_inc/global.js        2010-01-19 20:38:20 UTC (rev 2370)
</span><span class="lines">@@ -184,6 +184,37 @@
</span><span class="cx">                         return false;
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                /* Delete activity stream items */
+                if ( target.hasClass('delete-activity') ) {
+                        var li = target.parents('div.activity ul li');
+                        var id = li.attr('id').substr( 9, li.attr('id').length );
+                        var link_href = target.attr('href');
+
+                        var nonce = link_href.split('_wpnonce=');
+                                nonce = nonce[1];
+
+                        target.addClass('loading');
+
+                        j.post( ajaxurl, {
+                                action: 'delete_activity',
+                                'cookie': encodeURIComponent(document.cookie),
+                                'id': id,
+                                '_wpnonce': nonce
+                        },
+                        function(response) {
+                                target.removeClass('loading');
+
+                                if ( response[0] + response[1] == '-1' ) {
+                                        li.prepend( response.substr( 2, response.length ) );
+                                        li.children('div#message').hide().fadeIn(200);
+                                } else {
+                                        li.slideUp(200);
+                                }
+                        });
+
+                        return false;
+                }
+
</ins><span class="cx">                 /* Load more updates at the end of the page */
</span><span class="cx">                 if ( target.parent().attr('class') == 'load-more' ) {
</span><span class="cx">                         j("li.load-more span.ajax-loader").show();
</span><span class="lines">@@ -395,10 +426,10 @@
</span><span class="cx">                         j('div.activity-comments ul div.error').remove();
</span><span class="cx">
</span><span class="cx">                         j.post( ajaxurl, {
</span><del>-                                action: 'delete_activity_comment',
</del><ins>+                                action: 'delete_activity',
</ins><span class="cx">                                 'cookie': encodeURIComponent(document.cookie),
</span><span class="cx">                                 '_wpnonce': nonce,
</span><del>-                                'comment_id': comment_id
</del><ins>+                                'id': comment_id
</ins><span class="cx">                         },
</span><span class="cx">                         function(response)
</span><span class="cx">                         {
</span></span></pre>
</div>
</div>
</body>
</html>