Hi merlinofchaos,

Would it be possible to update a block view after a particulair ajax event has updated the data that this view is pulling in? This idea came from one of the maintainers from the flag module that suggested I should be able piggy back of the Views ajax capabilities. Hence the request here.

Issue reference: http://drupal.org/node/368644#comment-1239887 (explains his thoughts on Views integration)

Moofie (flag maintainer) wasn't sure himself if maybe this could already be achieved with views.

Regards,

Marius

Comments

merlinofchaos’s picture

The quick answer is yes, and the file that does it normally is ajax_view.js in the js directory. You will need to turn 'Use ajax' on; If you need a long answer detailing the javascript necessary that will take me a little longer, but in theory it should not be too difficult to study that file and figure out the command necessary to trigger a view refresh.

mariusooms’s picture

Thanks Merlin, that's already a big help to get the ball rolling.

Regards,

Marius

paganwinter’s picture

Subscribing...

paganwinter’s picture

Subscribing...

There's a Block Refresh module which refreshes a blocks content using JS. It has now been ported for D6 too.
Using this in combination with the Block Refresh module, it should be easily possible.
I am right now trying it out and will let you know if I am able to get it done...

Edit: I was able to successfully update a Views block upon flagging/unflagging a node. Along with Block Refresh I used the following code snippet given at the above mentioned article.

$(document).bind('flagGlobalAfterLinkUpdate', function(event, data) {
  block_refresh_manual(<name-of-the-block's-main-div>);
});
chrisroditis’s picture

Please allow me to expand on this issue by asking whether there is a more simple way to refresh a view, like calling a simple javascipt function with the id of the view as a parameter.
For us less inclined with ajax it would be heavens! I would appreciate any suggestions!

dgastudio’s picture

Subscribing...

youkho’s picture

Subscribe

dgastudio’s picture

done via component and custom js. Thanks.

chrisroditis’s picture

can you provide an example or a little more info please?

dgastudio’s picture

of course.

1. install module "component"
2. add this js code (in my case, in external js file.)

/*update fav block*/
$(document).bind('flagGlobalAfterLinkUpdate', function(event, data) {
  var base_url = (Drupal.setting && Drupal.setting.basePath) ||  'if u work on localhost, puth the folder where u have drupal installed, for example /mysite. if not, leave it in blank ';
  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) {
      $('#'+dom_id).after(newHtml).remove();
    });
  }
  if (data.flagName == 'name of your flag, in my case bookmarks') {
    if (blockExistsOnPage('views', 'name of views block, u can see it on views page, in my case: flag_bookmarks-block_1')) {
      refreshBlock('views', 'the same: flag_bookmarks-block_1');
    }
  }
});
/*wide?*/

done.

chrisroditis’s picture

thanks, I'll give it a shot!

Andrew Gorokhovets’s picture

Andrew Gorokhovets’s picture

Andrew Gorokhovets’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

cpliakas’s picture

One more resource, the Views Flag Refresh module automatically refreshes views via AJAX when certain flags are selected, so the code in that module is a good working example as well.

Thanks,
Chris

hlykos’s picture

sub

Makku01’s picture

The Link from comment above is broken. Any other idea how this could work?