I think the handbook page describes exactly what I need, but I haven't understood it. I'm using panels 3 and want the flag-view-block in my right column to refresh, when the flag link in my left column is clicked.
1. Do I have to install the component module?
2. What do I have to change in this code on the handbook page?

$(document).bind('flagGlobalAfterLinkUpdate', function(event, data) {

  function blockExistsOnPage(module_name, block_id) {
    var dom_id = 'block-' + module_name + '-' + block_id;
    return $('#'+dom_id).length != 0;
  }

  function refreshBlock(module_name, block_id) {
    var dom_id = 'block-' + module_name + '-' + block_id;
    $.get(base_url + '?q=component/block/' + module_name + '/' + block_id, null, function(newHtml) {
      // Replace the old block with the new one.
      $('#'+dom_id).after(newHtml).remove();
    });
  }

  if (data.flagName == 'bookmarks') {
    if (blockExistsOnPage('views', 'flag_bookmarks-block_1')) {
      refreshBlock('views', 'flag_bookmarks-block_1');
    }
  }
});

Which block ID, module name and dom ID do I have to replace? In my css I found for my block in my panel the classes "view-display-id-block_1" "view-dom-id-1".

You see, I haven't really understood the code, but i'd like to get it working and i'd be thankful about your help.

Comments

Andrew Gorokhovets’s picture

Andrew Gorokhovets’s picture

Unfortunately this code non-working :-(
The same problem.

Andrew Gorokhovets’s picture

Title: Block refresh » Views, Block Ajax refresh
Version: 6.x-1.x-dev » 6.x-2.x-dev

I think this code on book page (http://drupal.org/node/336122 Example: Refreshing a block on the page, via AJAX) precisely contains errors.


$(document).bind('flagGlobalAfterLinkUpdate', function(event, data) {

  // The following line is needed for compatibility with Drupal 5,
  // which doesn't have 'Drupal.setting.basePath'. Drupal 5 users
  // must update the '/' to match their bash path.

  var base_url = (Drupal.setting && Drupal.setting.basePath) ||  '/';

  function blockExistsOnPage(module_name, block_id) {
    var dom_id = 'block-' + module_name + '-' + block_id;
    return $('#'+dom_id).length != 0;
  }

  function refreshBlock(module_name, block_id) {
    var dom_id = 'block-' + module_name + '-' + block_id;
    $.get(base_url + '?q=component/block/' + module_name + '/' + block_id, null, function(newHtml) {
      // Replace the old block with the new one.
      $('#'+dom_id).after(newHtml).remove();
    });
  }

  if (data.flagName == 'bookmarks') {
    if (blockExistsOnPage('views', 'flag_bookmarks-block_1')) {
      refreshBlock('views', 'flag_bookmarks-block_1');
    }
  }
});

For example
$.get(base_url + '?q=component/block/' + module_name + '/' + block_id, null, function(newHtml) {

Will return
http://localhosT?q=component/block/module_name/block_id

The slash after base_url is passed.
But here is not one error

Andrew Gorokhovets’s picture

component.module must be enable.

In Flag.tpl.php To press id="flag-checkbox"

<a href="<?php print $link_href; ?>" id="flag-checkbox" title="<?php print $link_title; ?>"  class="<?php print $flag_classes ?>" rel="nofollow"> 
     <?php print $link_text; ?> </a>
<code>

Fjags.js  in your theme

#block-views-sravnenie-block_1  - it's id views-block.

http://localhost/?q=component/block/views/sravnenie-block_1 - The url on which block is accessible, through component module

<code>

$ (function()
				 {
        			 $('#flag-checkbox').click(function()
															 {
																											
																 $('#block-views-sravnenie-block_1').load('http:/localhost/?q=component/block/views/sravnenie-block_1');
																 });
					 });

Now other problem...
Block Update becomes earlier than content flaged

Andrew Gorokhovets’s picture

Status: Active » Fixed
Michelangelo’s picture

If the unflag link is within the block being refreshed, after the first block refresh, click an unflag link again causes the whole page to be reloaded with the contents of the block. The url becomes that of the component.

The 'destination' url parameter in the unflag links is modified after the block refresh. Could this be the cause?

Andrew Gorokhovets’s picture

Status: Fixed » Needs review

Yes I cnow about this problem.I Still working.

YK85’s picture

+1 subscribing

ariedels’s picture

I too am having the problem with internal flags.

I am not well versed in jquery, but it would seem that one could do a find and replace on the output from the component module so that the flags were restored to their original.

i.e.

the original flag: ..../flag/flag/bookmark/234?destination=node&token=....

the script above in #3 changes it to:

.../flag/flag/remove/210?destination=component%2Fblock%2Fviews%2Fbookmark-block&token=....

If there a way to replace "component%2Fblock%2Fviews%2Fbookmark-block" with "node" in the jQuery functions before the new block gets updated?

henrijs.seso’s picture

there is a bug in code. use var base_url = (Drupal.settings && Drupal.settings.basePath) || '/'; in stead of var base_url = (Drupal.setting && Drupal.setting.basePath) || '/';

quicksketch’s picture

Status: Needs review » Fixed

I've updated the documentation at http://drupal.org/node/336122 to use Drupal.settings (plural) instead of Drupal.setting (singular). I've also updated the documentation to use Drupal.attachBehaviors() on the new HTML, making it so that the refreshed block will continue to operate if it contains JavaScript behaviors.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ceerwk’s picture

As per comment #9. I am also having this problem. Anyone have any ideas how to solve it? Thanks.

sambaynham’s picture

I can say that the code at http://ucenter.googllers.com/home/space.php?uid=4&do=blog&id=54 works flawlessly for me.

cpliakas’s picture

For Views at least, check out Views Flag Refresh for another possible solution to the problem.

Thanks,
Chris

gynekolog’s picture

Version: 6.x-2.x-dev » 7.x-3.2
Status: Closed (fixed) » Active

And so when I have non-views block and Flag 7.x-3.2?
I have classic block with name of actual logged user and with number flagged contents (own code). How can I refresh the block after flagging content?

excuse my english please

ivnish’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Closed as outdated because Drupal 7 is EOL