? views-ajax1.patch
? views-ajax2.patch
Index: views.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/views/views.module,v
retrieving revision 1.232
diff -u -p -r1.232 views.module
--- views.module	20 Mar 2008 16:24:18 -0000	1.232
+++ views.module	21 Mar 2008 04:50:28 -0000
@@ -107,6 +107,14 @@ function views_menu() {
     list($view, $display_id) = $data;
     $items += $view->execute_hook_menu($display_id);
   }
+  $items['views/ajax'] = array(
+    'title' => t('Views'),
+    'page callback' => 'views_ajax',
+    'access callback' => 'user_access',
+    'access arguments' => array('access content'),
+    'description' => t('Ajax callback for view loading.'),
+    'type' => MENU_CALLBACK,
+  );
   return $items;
 }
 
@@ -243,6 +251,46 @@ function views_access($view, $account = 
 }
 
 /**
+ * Menu callback to load a view via AJAX.
+ */
+function views_ajax() {
+  $name = $_REQUEST['view_name'];
+  $display_id = $_REQUEST['view_display_id'];
+  $path = $_REQUEST['view_path'];
+  views_include('ajax');
+  $object = new stdClass();
+
+  $object->status = FALSE;
+  $object->display = '';
+
+  // Load the view.
+  if ($v = views_get_view($name)) {
+    $view = drupal_clone($v);
+    if ($view->access($display_id)) {
+
+      // Fix 'q' for paging.
+      $_GET['q'] = $path;
+    
+      $errors = $view->validate();
+      if ($errors === TRUE) {
+        $object->status = TRUE;
+        $object->title = $view->get_title();
+        $object->display .= $view->preview($display_id);
+      }
+      else {
+        foreach ($errors as $error) {
+          drupal_set_message($error, 'error');
+        }
+      }
+    }
+  }
+  $messages = theme('status_messages');
+  $object->messages = $messages ? '<div class="views-messages">'. $messages .'</div>' : '';
+
+  views_ajax_render($object);
+}
+
+/**
  * Set the current 'page view' that is being displayed so that it is easy
  * for other modules or the theme to identify.
  */
@@ -882,6 +930,9 @@ function views_exposed_form(&$form_state
 
   $form['#theme'] = views_theme_functions('views_exposed_form', $view, $display);
 
+  views_add_js('ajax_view');
+  drupal_add_js('misc/jquery.form.js');
+
   return $form;
 }
 
Index: js/ajax.js
===================================================================
RCS file: /cvs/drupal/contributions/modules/views/js/ajax.js,v
retrieving revision 1.9
diff -u -p -r1.9 ajax.js
--- js/ajax.js	17 Mar 2008 21:43:04 -0000	1.9
+++ js/ajax.js	21 Mar 2008 04:50:28 -0000
@@ -1,11 +1,11 @@
 // $Id: ajax.js,v 1.9 2008/03/17 21:43:04 merlinofchaos Exp $
 /**
-* @file ajax.inc
-*
-* Handles AJAX submission and response in Views UI.
-*/
+ * @file ajax_admin.js
+ *
+ * Handles AJAX submission and response in Views UI.
+ */
 
-Drupal.Views.Ajax = {};
+Drupal.Views.Ajax = Drupal.Views.Ajax || {};
 
 /**
  * Handles the simple process of setting the ajax form area with new data.
Index: js/ajax_view.js
===================================================================
RCS file: js/ajax_view.js
diff -N js/ajax_view.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ js/ajax_view.js	21 Mar 2008 04:50:29 -0000
@@ -0,0 +1,77 @@
+// $Id: $
+
+/**
+ * @file ajaxView.js
+ *
+ * Handles AJAX fetching of views, including filter submission and response.
+ */
+
+Drupal.Views.Ajax = Drupal.Views.Ajax || {};
+
+/**
+ * An ajax responder that accepts a packet of JSON data and acts appropriately.
+ *
+ * The following fields control behavior.
+ * - 'display': Display the associated data in the view area.
+ */
+Drupal.Views.Ajax.ajaxViewResponse = function(target, response) {
+
+  if (response.debug) {
+    alert(response.debug);
+  }
+
+  // Check the 'display' for data.
+  if (response.status && response.display) {
+    var view = $(target).replaceWith(response.display).get(0);
+    Drupal.attachBehaviors(view);
+  }
+};
+
+/**
+ * Helper function to return the last portion of a class.
+ */
+Drupal.Views.getClassSuffix = function (elt, prefix) {
+  var className = elt.className.split(' ');
+  for (var i in className) {
+    if (className[i].indexOf(prefix) == 0) {
+      return className[i].substring(prefix.length);
+    }
+  }
+  return false;
+}
+
+/**
+ * Ajax behavior for views. 
+ */
+Drupal.behaviors.ViewsAjaxView = function() {
+
+  $('form#views-exposed-form:not(.views-processed)')
+    .addClass('views-processed')
+    .each(function() {
+      var name;
+      var displayId;
+      var target = $(this).parents('.view').get(0);
+      // Parse view name and display id from the className.
+      var name = Drupal.Views.getClassSuffix(target, 'view-id-');
+      var displayId = Drupal.Views.getClassSuffix(target, 'view-display-id-');
+      if (name && displayId) {
+        $(this)
+          .append('<input type="hidden" name="view_name" value="'+ name +'"/>')
+          .append('<input type="hidden" name="view_display_id" value="'+ displayId +'"/>')
+          .append('<input type="hidden" name="view_path" value="'+ Drupal.settings.views.q +'"/>')
+          .submit(function () {
+            $(this).ajaxSubmit({
+              url: Drupal.settings.views.ajax_path,
+              type: 'GET',
+              success: function(response) {
+                Drupal.Views.Ajax.ajaxViewResponse(target, response);
+              },
+              error: function() { alert("An error occurred"); },
+              dataType: 'json'
+            });
+
+            return false;
+          });
+      }
+    });
+};
\ No newline at end of file
Index: js/base.js
===================================================================
RCS file: /cvs/drupal/contributions/modules/views/js/base.js,v
retrieving revision 1.3
diff -u -p -r1.3 base.js
--- js/base.js	13 Feb 2008 06:30:37 -0000	1.3
+++ js/base.js	21 Mar 2008 04:50:29 -0000
@@ -5,9 +5,11 @@ Drupal.Views = {};
  */
 
 Drupal.behaviors.viewsTabs = function (context) {
-  $('#views-tabset:not(.views-processed)').addClass('views-processed').tabs({
-    selectedClass: 'active'
-  });
+  if ($.ui && $.ui.tabs) {
+    $('#views-tabset:not(.views-processed)').addClass('views-processed').tabs({
+      selectedClass: 'active'
+    });
+  }
 
   $('a.views-remove-link')
     .addClass('views-processed')
Index: theme/theme.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/views/theme/theme.inc,v
retrieving revision 1.18
diff -u -p -r1.18 theme.inc
--- theme/theme.inc	18 Mar 2008 16:20:38 -0000	1.18
+++ theme/theme.inc	21 Mar 2008 04:50:29 -0000
@@ -26,6 +26,8 @@ function template_preprocess_views_view(
 
   $vars['rows']       = $view->style_handler->render($view->result);
   $vars['css_name']   = views_css_safe($view->name);
+  $vars['name']       = $view->name;
+  $vars['display_id'] = $view->current_display;
 
   if (!$vars['rows']) {
     $vars['empty']    = $view->display_handler->render_empty();
@@ -56,6 +58,9 @@ function template_preprocess_views_view(
     $vars['pager']    = theme('pager', $view->exposed_input, $view->pager['items_per_page'], $view->pager['element']);
   }
 
+  $settings = array('views' => array('ajax_path' => url('views/ajax'), 'q' => $_GET['q']));
+
+  drupal_add_js($settings, 'setting');
 }
 
 /**
Index: theme/views-view.tpl.php
===================================================================
RCS file: /cvs/drupal/contributions/modules/views/theme/views-view.tpl.php,v
retrieving revision 1.5
diff -u -p -r1.5 views-view.tpl.php
--- theme/views-view.tpl.php	20 Feb 2008 01:08:25 -0000	1.5
+++ theme/views-view.tpl.php	21 Mar 2008 04:50:29 -0000
@@ -16,7 +16,7 @@
  * @ingroup views_templates
  */
 ?>
-<div class="view view-<?php print $css_name; ?>">
+<div class="view view-<?php print $css_name; ?> view-id-<?php print $name; ?> view-display-id-<?php print $display_id; ?>">
   <?php if ($header): ?>
     <div class="view-header">
       <?php print $header; ?>
