Hi there, need some help. I have two usecases on my site where I need to Flag something, and have the page (or a portion thereof) refresh based on the Flag. I first tried a heavy-handed solution: Have the Flag trigger a Rule that refreshed the entire page. I couldn't get it to work, and I'd really rather not serve up all that data again if it can be avoided. Further research gave me this page: http://drupal.org/node/336122 (The Flag JavaScript API)
This seems to describe what I want--but I'm totally lost. I haven't used JavaScript at all since 1998. I use the PHP API and am able to hack my way to what I want, but I don't even know where to look in this thing. Hopefully someone can help me learn here.
I'll just present one use case in this support request. I'm sure I can duplicate this for the second use case myself.
I have two comment flags: Like and Dislike. They are printed in the comment itself, and I have printed a flag counter next to each one. This all works, but in order to see the count go up, I have to refresh the page. Here is the surrounding code, from my comment.tpl.php file.
<div class="comment-content">
<div class="comment-header">
<div class="comment-author segment">
<?php print $author; ?>
</div><!-- /comment-author -->
<?php if ($new): ?
<div class="new segment">
<?php print $new ?>
</div>
<?php endif; ?>
<div class="comment-time segment">
<?php echo t('!interval ago', array('!interval' => format_interval(time() - $comment->created))); ?>
</div><!-- /.comment-time -->
<div class="flag-abuse">
<?php print flag_create_link('abuse', $comment->cid); ?>
</div><!-- /.flag-abuse -->
<!-- THIS IS THE SECTION I NEED HELP WITH -->
<div class="updown">
<div class="flag-like segment">
<span class="like-count"><?php print $like->get_count($comment->cid); ?></span>
<?php print flag_create_link('like', $comment->cid); ?>
</div><!-- /.flag-like -->
<div class="dislike segment">
<?php print flag_create_link('dislike', $comment->cid); ?>
<span class="like-count"><?php print $dislike->get_count($comment->cid); ?></span>
</div><!-- /.flag-dislike -->
</div><!-- /.updown -->
</div><!-- /.comment-header" -->
So really, I need to know how to automatically refresh <?php print $dislike->get_count($comment->cid); ?> when someone clicks the dislike flag.
Thanks so much for your help!
Comments
Custom Module
You are going to need to write a small module to accomplish this. The module needs to handle the AJAX callback to grab the flag count. The flag data passed back in the flagGlobalAfterLinkUpdate does not include the count but the content_id. So, the module will need to have a page callback with an id parameters to grab the count and send it back.
Thanks for the response. That
Thanks for the response. That sounds beyond my current skill level. I'll add This to my list of bounties I need to finish the project off.
Anthony Pero
Project Lead
Virtuosic Media
http://www.virtuosic.me/
Vote
You might want to consider using something like Vote Up/Down (http://drupal.org/project/vote_up_down). It seems like there is a 7.x version in dev.
Thanks for the response, but
Thanks for the response, but that is just one use case among 2 or 3. I did look at the vote up/down module. I really just need to learn how to do this. I should know enough JavaScript to be able to refresh the page.
Anthony Pero
Project Lead
Virtuosic Media
http://www.virtuosic.me/