Browse Source

Merge branch '6.x-0.4-dev' of git.drupal.org:sandbox/spficklin/1337878 into 6.x-0.4-dev

stephen 13 years ago
parent
commit
d9685d1509

+ 24 - 1
base/tripal_core/tripal_core.views.inc

@@ -73,6 +73,11 @@ function tripal_core_views_handlers() {
       'parent' => 'views_handler_filter_string',
      ),
      
+     // Other Custom Handlers
+     'views_handler_filter_no_results' => array(
+      'parent' => 'views_handler_filter'
+     ),
+     
      // Old Handlers
      'views_handler_field_node_optional' => array(
        'parent' => 'views_handler_field_node',
@@ -161,7 +166,25 @@ function tripal_core_views_handlers() {
    ),
  );
 }
-    
+
+
+function tripal_core_views_data () {
+  
+  // Define Global Fields -------------
+  // Filter handler that lets the admin say: 
+  // "Show no results until they enter search parameters"
+  $data['views']['search_results'] = array(
+    'title' => t('Search Results'),
+    'help' => t('Delay results until Apply/Search is clicked by the user.'),
+    'filter' => array(
+      'handler' => 'views_handler_filter_no_results',
+    ),
+  );
+  
+  return $data;
+  
+}
+
 /**
  * Implements hook_views_pre_render
  *

+ 79 - 0
base/tripal_core/views/handlers/views_handler_filter_no_results.inc

@@ -0,0 +1,79 @@
+<?php
+
+class views_handler_filter_no_results extends views_handler_filter {
+
+  /**
+   * Ensure this filter is not exposed
+   */
+  function can_expose() {
+    return FALSE;
+  }
+  
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    
+    $form['msg'] = array(
+      '#type' => 'item',
+      '#value' => t('This filter ensures that when the page is first loaded, there are no results '
+        .'(query is not run). This imitates an advanced search form allowing users to first enter '
+        .'filter values and then retrieve results. This is especially suited for views with a very '
+        .'large number of results if left unfiltered since it removes the long load time before '
+        .'even allowing users the ability to filter down the results.')
+    );
+    
+    $form['apply_button'] = array(
+      '#type' => 'textfield',
+      '#title' => 'Apply Button Text',
+      '#default_value' => isset($this->options['apply_button']) ? $this->options['apply_button'] : 'Search'
+    );
+    
+    $form['no_results_text'] = array(
+      '#type' => 'textarea',
+      '#title' => 'Header Text before Search',
+      '#description' => 'This text will replace the no results text when the view is first loaded (before the user clicks Apply/Search)',
+      '#default_value' => isset($this->options['no_results_text']) ? $this->options['no_results_text'] : ''
+    );
+    
+  }
+  
+  function query() {
+    global $base_url;
+    
+    if (empty($this->view->exposed_input)) {
+      $this->view->executed = TRUE;
+      
+      $jquery_loaded = FALSE;
+      
+      // If set, change the no_results text
+      if (!empty($this->options['apply_button'])) {
+        if (!$jquery_loaded) {
+          drupal_set_html_head('<script type="text/javascript" src="'.$base_url.'/misc/jquery.js"></script>');
+          $jquery_loaded = TRUE;
+        }
+        $javascript = '<script type="text/javascript">'."\n"
+          ."$(document).ready(function(){\n"
+          ."  $('div.view-empty').html('".addslashes($this->options['no_results_text'])."');\n"
+          ."});\n"
+          .'</script>'."\n";
+        drupal_set_html_head($javascript);
+      }
+    }
+    
+    // Set the Apply button text
+    if (!empty($this->options['apply_button'])) {
+      if (!$jquery_loaded) {
+        drupal_set_html_head('<script type="text/javascript" src="'.$base_url.'/misc/jquery.js"></script>');
+        $jquery_loaded = TRUE;
+      }
+      $javascript = '<script type="text/javascript">'."\n"
+        ."$(document).ready(function(){\n"
+        ."  $('div.views-submit-button').html(".'"'."<input type='submit' id='edit-submit-all-analysis' value='".$this->options['apply_button']."' class='form-submit'>".'"'.");\n"
+        ."});\n"
+        .'</script>'."\n";
+      drupal_set_html_head($javascript);
+    }
+  }
+
+}

+ 1 - 1
extensions/tripal_analysis_blast/node-chado_analysis_blast.tpl.php

@@ -85,7 +85,7 @@ if (Drupal.jsEnabled) {
 <div id="tripal_analysis_blast_details" class="tripal_details">
 
    <!-- Basic Details Theme -->
-   <?php include('templates/tripal_analysis_blast_base.tpl.php');?>
+   <?php include('theme/tripal_analysis_blast/tripal_analysis_blast_base.tpl.php');?>
 
    <?php print $content ?>
 </div>