Rewrite ajax_view.js based on ctools AJAX

nedjo - September 29, 2009 - 17:22
Project:Views
Version:6.x-3.x-dev
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:active
Description

#343542: Enable AJAX self-refreshing views adds some new complexity to ajax_view.js. In preparation for D7, there's a move to start using CTools.

To ease the upgrade, we should look at rewriting ajax_view.js to duplicate what CTools is doing.

#1

merlinofchaos - September 29, 2009 - 17:26

For 2.x, I think we should duplicate CTools ajax.inc and ajax-responder.js, and in 3.x actually rely on CTools for this functionality.

#2

drewish - September 29, 2009 - 18:52

subscribe

#3

dixon_ - October 28, 2009 - 01:44

+1 for creating a dependency on CTools for 3.x and share the code base for stuff like this.

#4

nedjo - October 28, 2009 - 05:11

I've taken a first look at requirements.

Currently we have a separate menu callback for AJAX requests and special handling in the JS to parse out view attributes, which are passed along with the request as post variables.

The basic changes needed look to be:

1. Use a single callback for nojs and ajax requests. Rewrite to test for 'ajax' and conditionally use ctools_ajax_render(). The most obvious place to put this would be views_page() (which we would then have to add access tests to and expose to the menu system). Something like:

<?php
  ctools_include
('ajax');
 
// Load the view
 
if ($view = views_get_view($name)) {
   
$output = $view->execute_display($display_id, $args);
    if (
$type == 'ajax') {
     
$commands = array();
     
$commands[] = ctools_ajax_command_replace('#some-div', $return);
     
ctools_ajax_render($commands);
    }
    else {
     
ctools_add_js('ajax-responder');
      return
$output;
    }
  }
?>

2. Append /nojs to all views links and to the target of exposed filter forms.

3. Also append to these links and target the minimum data to identify the request. This is what I'm not so sure of. Currently we're posting a lot of data to views_ajax: view_name, view_display_id, view_args, view_path, view_dom_id, pager_element. Append all this to URLs? Ugly. Do we need to register the current view path as an alias of this ugly real path?

4. Add ctools-use-ajax class to relevant links (views pager, table header, and summary attachment links) and add ajax properties to exposed filter forms.

Does this sound vaguely right? What do we do about passing the view identification information to a callback?

#5

dereine - October 28, 2009 - 06:21

I would wait until d7views is ready, because the js there should have been converted to the new ajax framework, which was created out of ctools ajax.

#6

merlinofchaos - November 9, 2009 - 20:36

Most of that work has already been done (except for preview which should not be difficult) and could potentially just be backported to D6.

 
 

Drupal is a registered trademark of Dries Buytaert.