summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2008-03-28 20:31:51 (GMT)
committer Earl Miles2008-03-28 20:31:51 (GMT)
commit27546380a216b2856b408b9dd549c0a1f1dab5ea (patch)
treed77cc554b5e2565ac428305d4a59099976a8123b
parentbd4caf58143d0b67d2d2e6b75561796c76e04d9d (diff)
Minor corrections, improvements to live preview
-rw-r--r--includes/admin.inc28
-rw-r--r--includes/view.inc4
-rw-r--r--js/ajax.js2
-rw-r--r--views.module8
4 files changed, 31 insertions, 11 deletions
diff --git a/includes/admin.inc b/includes/admin.inc
index 8be5972..5d3c977 100644
--- a/includes/admin.inc
+++ b/includes/admin.inc
@@ -104,9 +104,14 @@ function views_ui_list_views($arg = NULL) {
* @todo make this use a template
*/
function views_ui_preview($js, $view) {
+ $func_args = func_get_args();
+ array_shift($func_args); // $js
+ array_shift($func_args); // $view
+ $display_id = (count($func_args)) ? array_shift($func_args) : 'default';
+
$form_state = array(
- 'display_id' => 'default',
- 'args' => '',
+ 'display_id' => $display_id,
+ 'view_args' => $func_args ? implode('/', $func_args) : '',
're_render' => TRUE,
'no_redirect' => TRUE,
'view' => &$view,
@@ -115,8 +120,8 @@ function views_ui_preview($js, $view) {
$output = drupal_build_form('views_ui_preview_form', $form_state);
$args = array();
- if (!empty($form_state['args'])) {
- $args = explode('/', $form_state['args']);
+ if (!empty($form_state['view_args'])) {
+ $args = explode('/', $form_state['view_args']);
}
// Fix 'q' for paging so that it will go to the NON ajax live preview.
@@ -125,7 +130,18 @@ function views_ui_preview($js, $view) {
$errors = $view->validate();
if ($errors === TRUE) {
$view->ajax = $js;
+ // Make view links come back to preview.
+ $view->override_path = 'admin/build/views/nojs/preview/' . $view->name . '/' . $form_state['display_id'];
+ if ($form_state['view_args']) {
+ $view->override_path .= '/' . $form_state['view_args'];
+ }
+
+ // also override $_GET['q'] so we get the pager
+ $_GET['q'] = $view->override_path;
+
$preview = $view->preview($form_state['display_id'], $args);
+
+ // Get information from the preview for display.
if (!empty($view->build_info['query'])) {
$rows = array();
$query = db_prefix_tables($view->build_info['query']);
@@ -207,7 +223,7 @@ function views_ui_preview_form(&$form_state) {
$form['args'] = array(
'#type' => 'textfield',
'#title' => t('Arguments'),
- '#default_value' => $form_state['args'],
+ '#default_value' => $form_state['view_args'],
'#description' => t('Separate arguments with a / as though they were a URL path.'),
'#id' => 'preview-args',
);
@@ -230,7 +246,7 @@ function views_ui_preview_form(&$form_state) {
*/
function views_ui_preview_form_submit(&$form, &$form_state) {
$form_state['display_id'] = $form_state['values']['display_id'];
- $form_state['args'] = $form_state['values']['args'];
+ $form_state['view_args'] = $form_state['values']['args'];
}
/**
diff --git a/includes/view.inc b/includes/view.inc
index 4a5ac5e..7e2f026 100644
--- a/includes/view.inc
+++ b/includes/view.inc
@@ -744,6 +744,10 @@ class view extends views_db_object {
* Get the base path used for this view.
*/
function get_path() {
+ if (!empty($this->override_path)) {
+ return $this->override_path;
+ }
+
if (empty($this->display_handler)) {
if (!$this->set_display('default')) {
return FALSE;
diff --git a/js/ajax.js b/js/ajax.js
index 89565a3..addae68 100644
--- a/js/ajax.js
+++ b/js/ajax.js
@@ -189,7 +189,7 @@ Drupal.Views.updatePreviewForm = function() {
$(this).ajaxSubmit({
url: url,
data: '',
- type: 'POST',
+ type: 'GET',
success: Drupal.Views.Ajax.previewResponse,
error: function() { alert("An error occurred."); },
dataType: 'json'
diff --git a/views.module b/views.module
index bfa2083..1c58228 100644
--- a/views.module
+++ b/views.module
@@ -1008,8 +1008,8 @@ function views_date_sql_format($format, $field, $field_type = 'int', $set_offset
'i' => '%i',
's' => '%s',
);
- $format = str_replace($format, $replace);
- return "DATE_FORMAT($field, $format)";
+ $format = strtr($format, $replace);
+ return "DATE_FORMAT($field, '$format')";
case 'pgsql':
$replace = array(
'Y' => 'YY',
@@ -1019,8 +1019,8 @@ function views_date_sql_format($format, $field, $field_type = 'int', $set_offset
'i' => 'MI',
's' => 'SS',
);
- $format = str_replace($format, $replace);
- return "TO_CHAR($field, $format)";
+ $format = strtr($format, $replace);
+ return "TO_CHAR($field, '$format')";
}
}