Tripal v1.0 (6.x-1.0)
tripal_views_handler_filter_no_results.inc
Go to the documentation of this file.
00001 <?php
00002 
00009 class tripal_views_handler_filter_no_results extends views_handler_filter {
00010 
00014   function can_expose() {
00015     return FALSE;
00016   }
00017 
00021   function options_form(&$form, &$form_state) {
00022 
00023     $form['msg'] = array(
00024       '#type' => 'item',
00025       '#value' => t('This filter ensures that when the page is first loaded, there are no results '
00026         .'(query is not run). This imitates an advanced search form allowing users to first enter '
00027         .'filter values and then retrieve results. This is especially suited for views with a very '
00028         .'large number of results if left unfiltered since it removes the long load time before '
00029         .'even allowing users the ability to filter down the results.')
00030     );
00031 
00032     $form['apply_button'] = array(
00033       '#type' => 'textfield',
00034       '#title' => 'Apply Button Text',
00035       '#default_value' => isset($this->options['apply_button']) ? $this->options['apply_button'] : 'Search'
00036     );
00037 
00038     $form['no_results_text'] = array(
00039       '#type' => 'textarea',
00040       '#title' => 'Header Text before Search',
00041       '#description' => 'This text will replace the no results text when the view is first loaded (before the user clicks Apply/Search)',
00042       '#default_value' => isset($this->options['no_results_text']) ? $this->options['no_results_text'] : ''
00043     );
00044 
00045   }
00046 
00047   function query() {
00048     global $base_url;
00049 
00050     // Check that all filter types don't return arrays
00051     // If they do then just show results by default b/c there is no way to tell the
00052     // different between before and after submitted
00053     $all_arrays = TRUE;
00054     foreach ($this->view->exposed_raw_input as $v) {
00055       if (!is_array($v)) {
00056         $all_arrays = FALSE;
00057       }
00058     }
00059 
00060     if (empty($this->view->exposed_input) && !$all_arrays) {
00061       $this->view->executed = TRUE;
00062 
00063       $jquery_loaded = FALSE;
00064 
00065       // If set, change the no_results text
00066       if (!empty($this->options['apply_button'])) {
00067         if (!$jquery_loaded) {
00068           drupal_set_html_head('<script type="text/javascript" src="' . $base_url . '/misc/jquery.js"></script>');
00069           $jquery_loaded = TRUE;
00070         }
00071         $javascript = '<script type="text/javascript">'."\n"
00072           ."$(document).ready(function(){\n"
00073           ."  $('div.view-empty').html('" . addslashes($this->options['no_results_text']) . "');\n"
00074           ."});\n"
00075           .'</script>'."\n";
00076         drupal_set_html_head($javascript);
00077       }
00078     }
00079 
00080     // Set the Apply button text
00081     if (!empty($this->options['apply_button'])) {
00082       if (!$jquery_loaded) {
00083         drupal_set_html_head('<script type="text/javascript" src="' . $base_url . '/misc/jquery.js"></script>');
00084         $jquery_loaded = TRUE;
00085       }
00086       $javascript = '<script type="text/javascript">'."\n"
00087         ."$(document).ready(function(){\n"
00088         ."  $('div.views-submit-button').html(" . '"' . "<input type='submit' id='edit-submit-all-analysis' value='" . $this->options['apply_button'] . "' class='form-submit'>" . '"' . ");\n"
00089         ."});\n"
00090         .'</script>' . "\n";
00091       drupal_set_html_head($javascript);
00092     }
00093   }
00094 
00095 }
 All Classes Files Functions Variables