Index: views.module =================================================================== RCS file: /cvs/drupal/contributions/modules/views/views.module,v retrieving revision 1.231 diff -u -p -r1.231 views.module --- views.module 18 Mar 2008 15:52:39 -0000 1.231 +++ views.module 18 Mar 2008 18:23:16 -0000 @@ -156,14 +156,41 @@ function views_page() { $name = array_shift($args); $display_id = array_shift($args); + // Test for a header set by jQuery to determine if this is an AJAX request. + $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? TRUE : FALSE; + // Load the view if ($v = views_get_view($name)) { $view = drupal_clone($v); - return $view->execute_display($display_id, $args); - } - // Fallback; if we get here no view was found or handler was not valid. - return drupal_not_found(); + // Should we be using the 'preview' method? + $output = $view->execute_display($display_id, $args); + } + // No view was found or handler was not valid. + else { + $output = MENU_NOT_FOUND; + } + if (!$ajax) { + return $output; + } + else { + views_include('ajax'); + $object = new stdClass(); + $object->status = $output == MENU_NOT_FOUND ? FALSE : TRUE; + $object->display = ''; + if ($messages = theme('status_messages')) { + $object->display = '
'; + } + if ($output == MENU_NOT_FOUND) { + $object->status = FALSE; + } + else { + $object->status = TRUE; + $object->display .= $output; + } + $object->title = $view->get_title(); + views_ajax_render($object); + } } /** @@ -857,6 +884,9 @@ function views_exposed_form(&$form_state $form['#theme'] = views_theme_functions('views_exposed_form', $view, $display); + views_add_js('ajaxView'); + 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 18 Mar 2008 18:23:16 -0000 @@ -5,7 +5,7 @@ * 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/ajaxView.js =================================================================== RCS file: js/ajaxView.js diff -N js/ajaxView.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ js/ajaxView.js 18 Mar 2008 18:23:16 -0000 @@ -0,0 +1,55 @@ +// $Id: ajax.js,v 1.9 2008/03/17 21:43:04 merlinofchaos Exp $ +/** + * @file ajaxView.js + * + * Handles AJAX filter submission and response in Views. + */ + +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, data) { + + if (data.debug) { + alert(data.debug); + } + + // See if we have any settings to extend. Do this first so that behaviors + // can access the new settings easily. + + if (data.js) { + $.extend(Drupal.settings, data.js); + } + + // Check the 'display' for data. + if (data.status && data.display) { + var view = $(target).replaceWith(data.display).get(0); + Drupal.attachBehaviors(view); + } +} + +Drupal.behaviors.ViewsAjaxView = function() { + + $('form#views-exposed-form:not(.views-processed)') + .addClass('views-processed') + .submit(function() { + var url = $(this).attr('action'); + var target = $(this).parents('.view').get(0); + $(this).ajaxSubmit({ + url: url, + type: 'GET', + success: function(data) { + Drupal.Views.Ajax.ajaxViewResponse(target, data); + }, + error: function() { alert("An error occurred'"); }, + dataType: 'json' + }); + + return false; + }); +} 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 18 Mar 2008 18:23:16 -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')