This patch provides menu callbacks for providing the latest activity post in json format.
I've successfully used this to provide a nice way to update the 'activity all' page dynamically through an ajax call using the jquery plug-in attached and the following (needs work) theme override function.
function phptemplate_activity_page($activities, $table) {
drupal_add_js(drupal_get_path('theme', 'garland') .'/js/spy.js', 'theme');
drupal_add_js("
$(document).ready(function() {
$('table tbody').spy({
'ajax': '/activity/all/json',
'push': custom_push,
'method': 'json',
'limit': 1,
'timeout': 7500,
});
});
function custom_push(response) {
eval(\"var json = \" + response); // convert to JSON
alert(json);
// I'm being lazy here, but you get the idea:
// Build the HTML
var html = '<tr class=\"even\"><td>' + json.date + '</td><td>' + json.message + '</td></tr>';
// Prepend the HTML inside the container
$('table tbody').prepend(html);
}",
'inline');
return $table;
}
I would like to consider using this as the default 'activity all' theme because it's so flippin' sweet!
| Comment | File | Size | Author |
|---|---|---|---|
| spy.js_.txt | 4 KB | sirkitree | |
| activity_json.patch | 2.73 KB | sirkitree |
Comments
Comment #1
sirkitree commentedComment #2
sirkitree commentedI committed the JSON patch by accident actually... dern ide... was trying to commit to svn and it did cvs instead... back to the command line from now on... /sigh
I would still like to explore using this spy as default page view.
Comment #3
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #4
giggler commentedI ran the patch and got this:
Comment #5
sirkitree commentedThat's because it is already applied. hence this ticket being closed.
Comment #6
giggler commentedI installed the most recent and tried the above code and couldn't get it to work, maybe I did it wrong. I'll try again. Is it possible to get views to run spy.js?
http://leftlogic.com/lounge/articles/jquery_spy2
Comment #7
sirkitree commentedMake sure you use the dev version of the module if you want the json functionality. Hence why this issue's version is marked 5.x-3.x-dev
I'm sure you could get views to use spy.js. Help will not be provided here though as this is the activity module's issue queue.
Comment #8
giggler commentedI have 5.x-3.x-dev dated 3-20-08. This is what I did and it shows the activities but it doesn't seem to do the jquery spy fade in thing:
1. put the php function in template.php
2. created a new folder in garland theme called js
3. created a file in js folder called spy.js with the above txt file.
Do you have a working example? I'm not sure what I'm doing wrong. I also don't know what /activity/all/json is pointing to...
Thanks!
Comment #9
d0t101101 commentedThis is really cool, can't wait to get this implemented on my site. I suggest expanding on this to add a more a more visually pleasing interface, such as:
http://www.vimeo.com/home/right_now
Their use of action icons, avatars, and thumnbails ties things together well
Comment #10
d0t101101 commentedIn case this might help someone else:
I am using the following function in template.php:
This checks that the path equals /activity/all before it includes the JS for JSON real-time updates to the activity table. I ran into problems with the when using Activity on my user profile pages too - the old function would try to update all activity tables site-wide. This new function allows you to have 'my activity' on the profile pages, and the 'all activity' page refresh via JSON updates.
.
Comment #11
ColdSun commentedAny idea why this wont work on Drupal6? The source shows that the spy.js and the script itself are correctly being added to the activity/all (not a template.php issue), but nothing is updating.
Comment #12
d0t101101 commentedI too am having problems with D6 and spy.js... Has anyone managed to get this working?
Comment #13
ColdSun commentedThe spy.js script displays the same action twice if a new action has not been performed. Is there a way to prevent updates unless its a new entry?