The views_autorefresh submodule is not working in Drupal 7. If you try and use it, you will get: Call to undefined function drupal_query_string_encode() in /views_hacks/views_autorefresh/views_autorefresh.module on line 20

drupal_query_string_encode is superseded in Drupal 7 by drupal_http_build_query. Does anyone got a code that is working for this module?

Comments

steinmb’s picture

Title: views_autorefresh » views_autorefresh broken in D7

A more descriptive title perhaps.

neoglez’s picture

Yes, it hasn't been ported jet, that's why the 7 branch doesn't show in the project page.

steinmb’s picture

Priority: Major » Normal

I could see that :) still I decided to post an issues, so other might see this before turning on the submodule (nothing is stopping you from getting the code with 'drush dl views_hacks' + we could keep this as an meta-issue that we close when the submodule is ported/working.

neoglez’s picture

OK ;-)

drupalina’s picture

subscribing (I have the same isssue -- and waiting for the port)

JohnnyX’s picture

Maybe views_autorefresh could be done with jquery spy plugin to update/ add new content at the top/ bottom (with slide effect)? I dont't know if views hack (D6) refresh the hole view or update it like spy. It would be a great feature.

mhawker’s picture

subscribe

cm_is’s picture

subscribing

vali hutchison’s picture

i tried downloading the module and trying to update to D7 to no avail. for ref i changed

$query_string = drupal_query_string_encode($_REQUEST, array_merge(array('q', 'pass'), array_keys($_COOKIE)));

to

$query_string = drupal_http_build_query(drupal_get_query_parameters($_REQUEST, array_merge(array('q', 'pass'), array_keys($_COOKIE))));

as per http://drupal.org/update/modules/6/7#get_querystring

it gets rid of the errors mentioned above, but when i set up the view with AJAX switched on and the refresh code in the header, nothing happens.

dreadlocks1221’s picture

to get the script somewhat working I changed

Drupal.behaviors.views_autorefresh = function(context) {

to

Drupal.behaviors.views_autorefresh = {
attach: function(context, settings){

and added an extra } before })(jQuery);

The js tries to refresh but I get an error:

Drupal.Views.Ajax is undefined line 63

this error could be related to:
http://drupal.org/node/914360

as it doesnt seem like this function is present in the D7 views js

neoglez’s picture

Status: Active » Postponed (maintainer needs more info)

Could you give an export for this specific use case so i can test a port to D7 and eventually commit?

l00ph0le’s picture

Looking for this for a project as well...any idea on a port to D7?

alfiozzz’s picture

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /drupal/admin/structure/views/view/frontpage/preview/page/ajax
StatusText: Internal Server Error
ResponseText:

l00ph0le’s picture

StatusFileSize
new26.02 KB

Enabled the new D7 Dev ports...here is my errors...Picture is on the views page when configuring and saving, and the WSOD Fatal error.

Fatal error: Call to undefined function drupal_query_string_encode() in /home/hillsdal/public_html/drupal/sites/all/modules/views_hacks/views_autorefresh/views_autorefresh.module on line 20

kaizerking’s picture

I suggest to keep the title of the error , when i search for this in issue cases i didn't get this,
What we generally do is search the issue in titles or search with key word in bothe the cases we dont get this title.

I also have the same issue

kaizerking’s picture

PS :here is the error code i am getting in my view settings page
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /admin/structure/views/view/new_jobs/preview/page/ajax
StatusText: parsererror
ResponseText:
Fatal error: Call to undefined function drupal_query_string_encode() in E:\wamp\www\sites\all\modules\views_autorefresh\views_autorefresh.module on line 20

ironbuilt’s picture

Subscribe. Can I offer a bounty to get this resolved? ;)

mentor972’s picture

Component: General » Views Filters Auto-refresh
Status: Postponed (maintainer needs more info) » Active

New D7 dev version no longer has errors when you add the autorefresh code to Views Header, however, the view doesn't actually refresh.

Steps..

1) Turn on AJAX for view
2) Add Text Header PHP...

"

$interval = 5000; // 5000 msec = 5 sec
print theme('views_autorefresh', $interval);

"

3) Check box to display even with no result

4) Active view doesn't refresh.

Thoughts?

steinmb’s picture

Removing tags

mentor972’s picture

Already tried removing tags, but that just makes the code display in the header. Plus, Views Header states you need tags at the bottom.

Niremizov’s picture

Like mentor972 said, just nothing happens. Probably it is some how related with that inside views_autorefresh.js there is lines:

                    if (response.__callbacks) {
                      $.each(response.__callbacks, function(i, callback) {
                        eval(callback)(target, response);
                      });
                    }

And there is not property _callback... so nothing happens. Ajax response returns command objects, that we should invoke some how, i tried something like:

                    if (response) {
                        $.each(response, function(i, callback) {
                        var test = new Drupal.ajax();
                            Drupal.ajax.prototype.commands.invoke(Drupal.ajax, response[i], '');
                        });
                      }

But it didn't work, suppose we should create Drupal.ajax object first, or what?

rlmumford’s picture

Here's my code for views_autorefresh.js, It works for me. Hopefully it will be helpful

(function ($) {
// START jQuery

Drupal.behaviors.views_autorefresh = {
  attach: function(context, settings) {
    if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) {
      var ajax_path = Drupal.settings.views.ajax_path;
      // If there are multiple views this might've ended up showing up multiple times.
      if (ajax_path.constructor.toString().indexOf("Array") != -1) {
        ajax_path = ajax_path[0];
      }
      $.each(Drupal.settings.views.ajaxViews, function(i, settings) {
        var view = '.view-dom-id-' + settings.view_dom_id;
        if (!$(view).size()) {
          // Backward compatibility: if 'views-view.tpl.php' is old and doesn't
          // contain the 'view-dom-id-#' class, we fall back to the old way of
          // locating the view:
          view = '.view-id-' + settings.view_name + '.view-display-id-' + settings.view_display_id;
        }
        $(view).filter(':not(.views-autorefresh-processed)')
          // Don't attach to nested views. Doing so would attach multiple behaviors
          // to a given element.
          .filter(function() {
            // If there is at least one parent with a view class, this view
            // is nested (e.g., an attachment). Bail.
            return !$(this).parents('.view').size();
          })
          .each(function() {
            // Set a reference that will work in subsequent calls.
            var target = this;
            $(this)
              .addClass('views-autorefresh-processed')
              // Process pager, tablesort, and attachment summary links.
              .find('.auto-refresh a')
              .each(function () {
                var viewData = { 'js': 1 };
                // Construct an object using the settings defaults and then overriding
                // with data specific to the link.
                $.extend(
                  viewData,
                  Drupal.Views.parseQueryString($(this).attr('href')),
                  // Extract argument data from the URL.
                  Drupal.Views.parseViewArgs($(this).attr('href'), settings.view_base_path),
                  // Settings must be used last to avoid sending url aliases to the server.
                  settings
                );
                
                $.extend(viewData, Drupal.Views.parseViewArgs($(this).attr('href'), settings.view_base_path));
                $(this).addClass('views-throbbing');
                var base = view;
                var element_settings = {};
                element_settings.url = ajax_path;
                element_settings.event = 'click';
                element_settings.selector = base;
                element_settings.submit = viewData;
                  
                var ajax = new Drupal.ajax(base, this, element_settings);
                
                // Make a copy of the old function so we can still call it:
                ajax.old_success = ajax.success;
                
                // Now replace it with our own.
                ajax.success = function (response, status) {
                  // Scroll to the top of the view. This will allow users
                  // to browse newly loaded content after e.g. clicking a pager
                  // link.
                  var offset = $(target).offset();
                  // We can't guarantee that the scrollable object should be
                  // the body, as the view could be embedded in something
                  // more complex such as a modal popup. Recurse up the DOM
                  // and scroll the first element that has a non-zero top.
                  var scrollTarget = target;
                  while ($(scrollTarget).scrollTop() == 0 && $(scrollTarget).parent()) {
                    scrollTarget = $(scrollTarget).parent()
                  }
                  // Only scroll upward
                  if (offset.top - 10 < $(scrollTarget).scrollTop()) {
                    $(scrollTarget).animate({scrollTop: (offset.top - 10)}, 500);
                  }
                  this.old_success(response, status);
                }
                
                Drupal.ajax[base] = ajax;
                
              }); // .each function () {
        }); // $view.filter().each
      });

      // Set the autorefresh timer.
      var timer = setTimeout('autorefresh()', Drupal.settings.views_autorefresh.interval);
      autorefresh = function() {
        $(".auto-refresh a").click();
        clearTimer(timer);
      }
    }
  }
}

// END jQuery
})(jQuery);
aggentle’s picture

rlmumford, that works a treat.

I tried the standard alpha release install with no joy. I replaced the packaged views_autorefresh.js file with your code and both my block and page views are auto-refreshing nicely.

Thanks to all.

Niremizov’s picture

Thx rlmumford espessialy for example of useing Drupal.ajax.
There is error in Chrome, "clearTimer is not defined" -- replace it with clearTimeout.

PS: if someone searching for more examples and explanations of useing Drupal.ajax, you schould see.

Cristian.Andrei’s picture

Component: Views Filters Auto-refresh » General
Status: Active » Needs review
StatusFileSize
new9.01 KB

here's a patch (contains the important bits people mentioned above) for the views-autorefresh.js that will work on D7. Tested on a vanilla install. Apply it in the views_hacks root directory.

Thank you all for the contribution.

Cristian.Andrei’s picture

Component: General » Views Auto-Refresh

forgot to mark the right component

Cristian.Andrei’s picture

Assigned: infojunkie » Unassigned
StatusFileSize
new8.9 KB

there's some legacy stuff from my testing in the last patch. This patch is clean, so use this instead of the one in comment #25.

steinmb’s picture

I'll test it on a larger site this weekend and let you know. Unable to give any proper code review then js is my native language. Kitos! :)

infojunkie’s picture

Assigned: Unassigned » infojunkie

Thanks for this patch. As I'm about to use Views Auto-Refresh on a D7 project myself, I will be reviewing it shortly.

infojunkie’s picture

Assigned: Unassigned » infojunkie
Status: Needs review » Fixed

Committed to latest dev, with some changes. Thanks!

The Views Auto-Refresh module in D6 had greatly progressed since this version though, including a ping URL and a progressive refresh mechanism. These functionalities are not included in this commit. I am working on them.

infojunkie’s picture

infojunkie’s picture

Added support for incremental refresh. This completes the port of Views Auto-Refresh. Please open new issues if you encounter problems.

JohnnyX’s picture

Great news! Thanks! I'll test it soon.

JohnnyX’s picture

Anxy documentation how to use it?

JohnnyX’s picture

Articles also correct for D7 module?

An alternative way could be nodejs integration? I haven't work with nodejs, but it sounds like a good solution... but needs nodejs installed at server.
http://drupal.org/sandbox/julien/1502728

infojunkie’s picture

Nodejs is not needed. A simple PHP script suffices. You should read the articles :-)

JohnnyX’s picture

I have take a look at the articles and tried it with a simple complete refresh test, but it doesn't work. PHP code displayed at the view and not executed. Also doesn't work with views_php module installed.

I'll try it again...

Status: Fixed » Closed (fixed)

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

infojunkie’s picture

Project: Views Hacks » Views Auto-Refresh
Component: Views Auto-Refresh » Code