Browse Source

Added new sequence_combo form element and fixed the sequence filter:

spficklin 12 years ago
parent
commit
affa8ffc15

+ 77 - 0
tripal_views/includes/tripal_views_form_elements.inc

@@ -15,6 +15,12 @@ function tripal_views_elements() {
     '#process' => array('expand_file_upload_combo'),
     '#process' => array('expand_file_upload_combo'),
     '#element_validate' => array('file_upload_combo_validate'),
     '#element_validate' => array('file_upload_combo_validate'),
   );
   );
+  
+  $type['sequence_combo'] = array(
+    '#input' => TRUE,
+    '#process' => array('expand_sequence_combo'),
+    '#element_validate' => array('sequence_combo_validate'),
+  );
 
 
   return $type;
   return $type;
 }
 }
@@ -25,6 +31,7 @@ function tripal_views_elements() {
  */
  */
 function expand_file_upload_combo($element, $edit, $form_state, $complete_form) {
 function expand_file_upload_combo($element, $edit, $form_state, $complete_form) {
 
 
+  // set the default values for each field
   if (empty($element['#value'])) {
   if (empty($element['#value'])) {
     $element['#value'] = array(
     $element['#value'] = array(
       'items' => '',
       'items' => '',
@@ -35,12 +42,15 @@ function expand_file_upload_combo($element, $edit, $form_state, $complete_form)
 
 
   $element['#tree'] = TRUE;
   $element['#tree'] = TRUE;
 
 
+  // add items text area element
   $parents = $element['#parents'];
   $parents = $element['#parents'];
   $parents[] = 'items';
   $parents[] = 'items';
   $element['items'] = array(
   $element['items'] = array(
     '#type' => 'textarea',
     '#type' => 'textarea',
     '#default_value' => $element['#value']['items'],
     '#default_value' => $element['#value']['items'],
   );
   );
+  
+  // add file upload element
   $parents = $element['#parents'];
   $parents = $element['#parents'];
   $parents[] = 'items_file';
   $parents[] = 'items_file';
   $element['items_file'] = array(
   $element['items_file'] = array(
@@ -49,6 +59,7 @@ function expand_file_upload_combo($element, $edit, $form_state, $complete_form)
     '#default_value' => $element['#value']['items_file'],
     '#default_value' => $element['#value']['items_file'],
   );
   );
 
 
+  // add hidden elelment
   $parents = $element['#parents'];
   $parents = $element['#parents'];
   $parents[] = 'file_path';
   $parents[] = 'file_path';
   $element['file_path'] = array(
   $element['file_path'] = array(
@@ -58,6 +69,42 @@ function expand_file_upload_combo($element, $edit, $form_state, $complete_form)
 
 
   return $element;
   return $element;
 }
 }
+/**
+ * Form element description
+ */
+function expand_sequence_combo($element, $edit, $form_state, $complete_form) {
+ 
+  // set the default values for each field
+  if (empty($element['#value'])) {
+    $element['#value'] = array(
+      'upstream' => '',
+      'downstream' => '',
+    );
+  }
+  
+  $element['#tree'] = TRUE;
+
+  // add the upstream box
+  $parents = $element['#parents'];
+  $parents[] = 'upstream';
+  $element['upstream'] = array(
+     '#type' => 'textfield',
+     '#title' => t('Get Upstream Bases'),
+     '#description' => t('Specify the number of upstream bases to include in the sequnce'),
+     '#default_value' => $element['#value']['upstream'],
+  );
+  // add the downstream box
+  $parents = $element['#parents'];
+  $parents[] = 'downstream';
+  $element['downstream'] = array(
+     '#type' => 'textfield',
+     '#prefix' => '<br>',
+     '#title' => t('Get Downstream Bases'),
+     '#description' => t('Specify the number of downstream bases to include in the sequnce'),
+     '#default_value' => $element['#value']['downstream'],     
+  );
+  return $element;
+}
 
 
 /**
 /**
  * Theme the file upload combo form element
  * Theme the file upload combo form element
@@ -66,6 +113,13 @@ function theme_file_upload_combo($element) {
   return theme('form_element', $element, '<div class="container-inline">' . $element['#children'] . '</div>');
   return theme('form_element', $element, '<div class="container-inline">' . $element['#children'] . '</div>');
 }
 }
 
 
+/**
+ * Theme the file sequence form element
+ */
+function theme_sequence_combo($element) {
+  return theme('form_element', $element, '<div class="container-inline">' . $element['#children'] . '</div>');
+}
+
 /**
 /**
  * Validate all content passed into the file upload combo form element
  * Validate all content passed into the file upload combo form element
  */
  */
@@ -78,3 +132,26 @@ function file_upload_combo_validate($element, &$form) {
     $_GET[$element['#name']]['file_path'] = $file->filepath;
     $_GET[$element['#name']]['file_path'] = $file->filepath;
   }
   }
 }
 }
+
+/**
+ * Validate all content passed into the sequence combo form element
+ */
+function sequence_combo_validate($element, &$form) {
+  $upstream = $form['values'][$element['#name']]['upstream'];
+  $downstream = $form['values'][$element['#name']]['downstream'];
+  
+
+  if ($upstream < 0) {
+    form_set_error($element['#name'], 'Please provide a positive number for upstream bases');
+  }
+  if ($upstream and !preg_match('/^\d+$/',$upstream)) {
+    form_set_error($element['#name'], 'Please provide a decimal number for upstream bases');
+  }
+
+  if ($downstream < 0) {
+    form_set_error($element['#name'], 'Please provide a positive number for downstream bases');
+  }
+  if ($downstream and !preg_match('/^\d+$/',$downstream)) {
+    form_set_error($element['#name'], 'Please provide a decimal number for downstream bases');
+  }
+}

+ 3 - 0
tripal_views/tripal_views.module

@@ -125,6 +125,9 @@ function tripal_views_theme() {
     'file_upload_combo' => array(
     'file_upload_combo' => array(
       'arguments' => array('element' => NULL)
       'arguments' => array('element' => NULL)
     ),
     ),
+    'sequence_combo' => array(
+      'arguments' => array('element' => NULL)
+    ),
   );
   );
 }
 }
 
 

+ 4 - 1
tripal_views/views/handlers/tripal_views_handler_field_sequence.inc

@@ -177,8 +177,11 @@ class tripal_views_handler_field_sequence extends chado_views_handler_field {
         'without intronic sequence'),
         'without intronic sequence'),
       '#default_value' => $this->options['display']['aggregate'],
       '#default_value' => $this->options['display']['aggregate'],
     );
     );
-  }
+  }  
 
 
+  /**
+  * We need to add a few fields to our query
+  */
   function query() {
   function query() {
     parent::query();
     parent::query();
     
     

+ 21 - 46
tripal_views/views/handlers/tripal_views_handler_filter_sequence.inc

@@ -8,8 +8,8 @@
  * @ingroup tripal_views_integration
  * @ingroup tripal_views_integration
  */
  */
 class tripal_views_handler_filter_sequence extends views_handler_filter {
 class tripal_views_handler_filter_sequence extends views_handler_filter {
-
-  /**
+ 
+ /**
    * Defines the value field in both the views filter options form
    * Defines the value field in both the views filter options form
    *   and the exposed form
    *   and the exposed form
    */
    */
@@ -17,15 +17,10 @@ class tripal_views_handler_filter_sequence extends views_handler_filter {
     parent::value_form($form, $form_state);
     parent::value_form($form, $form_state);
 
 
     $this->value_form = array(
     $this->value_form = array(
-       '#type' => 'checkbox',
-       '#title' => t('Provide fields for upstream and downstream'),
+       '#type' => 'sequence_combo',
+       '#title' => t('%label', array('%label' => $this->options['expose']['label'])),
        '#default_value' => $this->value,
        '#default_value' => $this->value,
-       '#multiple' => FALSE,
-       '#description' => 
-         t('Check here to provide form fields to allow the user to retrieve ' .
-           'sequences beyond the feature residues.  This requires that the ' .
-           'feature is aligned to a parent sequence and the optin to derive ' .
-           'the sequence from the parent is turned on in the field settings.'),
+       '#multiple' => FALSE,       
     );
     );
     $form['value'] = &$this->value_form;
     $form['value'] = &$this->value_form;
   }
   }
@@ -40,51 +35,31 @@ class tripal_views_handler_filter_sequence extends views_handler_filter {
     if (empty($this->options['exposed'])) {
     if (empty($this->options['exposed'])) {
       return;
       return;
     }
     }
+    // rebuild the form elements
+    $value = $this->options['expose']['identifier'];
+    $this->value_form($form, $form_state);
+
     $form[$value] = $form['value'];
     $form[$value] = $form['value'];
     unset($form[$value]['#title']);
     unset($form[$value]['#title']);
 
 
-    // add the upstream and downstream boxes
-    $form['upstream'] = array(
-       '#type' => 'textfield',
-       '#title' => t('Get Upstream Bases'),
-       '#description' => t('Specify the number of upstream bases to include in the sequnce'),
-    );
-    $form['downstream'] = array(
-       '#type' => 'textfield',
-       '#title' => t('Get Downstream Bases'),
-       '#description' => t('Specify the number of upstream bases to include in the sequnce'),
-    );
+    $this->exposed_translate($form[$value], 'value');
+
+    if ($value != 'value') {
+      unset($form['value']);
+    }
   }
   }
 
 
   /**
   /**
    *  Validates the input form
    *  Validates the input form
    */
    */
   function exposed_validate(&$form, &$form_state) {
   function exposed_validate(&$form, &$form_state) {
-     $upstream = $form_state['values']['upstream'];
-     $downstream = $form_state['values']['downstream'];
-     
-     if($upstream < 0){
-        form_set_error($form_state['values']['upstream'], 
-           'Please provide a positive number for upstream bases');
-     }
-     if($upstream and !preg_match('/^\d+$/',$upstream)){
-        form_set_error($form_state['values']['upstream'], 
-           'Please provide a decimal number for upstream bases');
-     }
-
-     if($downstream < 0){
-        form_set_error($form_state['values']['upstream'], 
-           'Please provide a positive number for downstream bases');
-     }
-     if($downstream and !preg_match('/^\d+$/',$downstream)){
-        form_set_error($form_state['values']['upstream'], 
-           'Please provide a decimal number for downstream bases');
-     }
+    $upstream = $form_state['values'][$this->field]['upstream'];
+    $downstream = $form_state['values'][$this->field]['downstream'];       
      
      
-     // we need the values provided by the user so that the field
-     // handler can generate the results properly.  These values
-     // will get stored in the view object.  This may not be the best place
-     $this->view->sequence_q['upstream'] = $upstream;
-     $this->view->sequence_q['downstream'] = $downstream;
+    // we need the values provided by the user so that the field
+    // handler can generate the results properly.  These values
+    // will get stored in the view object.  This may not be the best place
+    $this->view->sequence_q['upstream'] = $upstream;
+    $this->view->sequence_q['downstream'] = $downstream;
   }
   }
 }
 }