Browse Source

Added the CV and CVTerm admin pages by moving them from legacy. Creation of content types now supports record association using prop tables. Fixed a few other bugs along the way

Stephen Ficklin 7 years ago
parent
commit
b2a1444857
35 changed files with 1581 additions and 1219 deletions
  1. 1 1
      legacy/tripal_analysis/includes/tripal_analysis.chado_node.inc
  2. 9 9
      legacy/tripal_core/api/tripal_core.chado_nodes.properties.api.inc
  3. 2 2
      legacy/tripal_core/api/tripal_core.chado_nodes.relationships.api.inc
  4. 1 1
      legacy/tripal_cv/api/tripal_cv.api.inc
  5. 3 42
      legacy/tripal_cv/includes/tripal_cv.cv_defaults.inc
  6. 0 256
      legacy/tripal_cv/includes/tripal_cv.cv_form.inc
  7. 0 474
      legacy/tripal_cv/includes/tripal_cv.cvterm_form.inc
  8. 1 1
      legacy/tripal_feature/includes/tripal_feature.chado_node.inc
  9. 1 1
      legacy/tripal_feature/includes/tripal_feature.delete.inc
  10. 1 1
      legacy/tripal_library/includes/tripal_library.chado_node.inc
  11. 1 1
      legacy/tripal_stock/includes/tripal_stock.chado_node.inc
  12. 42 309
      tripal/includes/TripalBundleUIController.inc
  13. 0 16
      tripal/includes/TripalFields/TripalField.inc
  14. 1 1
      tripal/includes/tripal.fields.inc
  15. 2 13
      tripal/tripal.module
  16. 19 12
      tripal_chado/api/tripal_chado.api.inc
  17. 25 0
      tripal_chado/api/tripal_chado.property.api.inc
  18. 1 1
      tripal_chado/api/tripal_chado.query.api.inc
  19. 1 1
      tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc
  20. 1 1
      tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc
  21. 1 0
      tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc
  22. 3 0
      tripal_chado/includes/tripal_chado.bundle.inc
  23. 767 0
      tripal_chado/includes/tripal_chado.cv.inc
  24. 6 6
      tripal_chado/includes/tripal_chado.db.inc
  25. 1 0
      tripal_chado/includes/tripal_chado.entity.inc
  26. 522 0
      tripal_chado/includes/tripal_chado.field_storage.inc
  27. 54 19
      tripal_chado/includes/tripal_chado.fields.inc
  28. 69 5
      tripal_chado/tripal_chado.module
  29. 16 16
      tripal_chado/tripal_chado.views_default.inc
  30. 3 3
      tripal_chado_views/api/tripal_chado_views.api.inc
  31. 1 1
      tripal_chado_views/includes/tripal_chado_views_integration.inc
  32. 6 6
      tripal_chado_views/includes/tripal_chado_views_integration_UI.inc
  33. 3 3
      tripal_chado_views/tripal_chado_views.module
  34. 3 3
      tripal_chado_views/tripal_chado_views.views.inc
  35. 14 14
      tripal_chado_views/tripal_chado_views.views_default.inc

+ 1 - 1
legacy/tripal_analysis/includes/tripal_analysis.chado_node.inc

@@ -267,7 +267,7 @@ function chado_analysis_form($node, &$form_state) {
 
   // Properties Form
   // ----------------------------------
-  $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the analysis_property vocabulary", "admin/tripal/vocab/cvterm/add") . ".");
+  $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the analysis_property vocabulary", "admin/tripal/loaders/chado_cv/cvterm/add") . ".");
   $prop_cv = tripal_get_default_cv('analysisprop', 'type_id');
   $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
   $details = array(

+ 9 - 9
legacy/tripal_core/api/tripal_core.chado_nodes.properties.api.inc

@@ -293,7 +293,7 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
         to the %cv_name controlled vocabulary.',
         array(
           '%cv_name' => $details['cv_name'],
-          '@cvtermlink' => url('admin/tripal/vocab/cv/' . $details['cv_id'] . '/cvterm/add')
+          '@cvtermlink' => url('admin/tripal/loaders/chado_cv/' . $details['cv_id'] . '/cvterm/add')
         )
       ),
       TRIPAL_NOTICE,
@@ -306,7 +306,7 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
         a controlled vocabulary term</a> to the %cv_name controlled vocabulary.',
         array(
           '%cv_name' => $details['cv_name'],
-          '@cvtermlink' => url('admin/tripal/vocab/cv/' . $details['cv_id'] . '/cvterm/add')
+          '@cvtermlink' => url('admin/tripal/loaders/chado_cv/' . $details['cv_id'] . '/cvterm/add')
         )
       ),
       TRIPAL_INFO,
@@ -325,15 +325,15 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
   );
 
   // the fieldset of the property elements
-  $instructions = 'To add properties of the current %nodetype, select the type of 
-      information from the drop-down below and enter the information in the text box before 
-      clicking "Add". To remove incorrect information, click the "Remove" button. 
-      Note: you cannot edit previously added information but instead need to 
+  $instructions = 'To add properties of the current %nodetype, select the type of
+      information from the drop-down below and enter the information in the text box before
+      clicking "Add". To remove incorrect information, click the "Remove" button.
+      Note: you cannot edit previously added information but instead need to
       remove and re-add it.';
   $form['properties'] = array(
     '#type' => 'fieldset',
     '#title' => t($details['fieldset_title']),
-    '#description' => t('<p><strong>Additional information about a 
+    '#description' => t('<p><strong>Additional information about a
       %nodetype.</strong></p><p>'. $instructions . $details['additional_instructions'] . '</p>', array('%nodetype' => $details['nodetype'])) ,
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
@@ -363,7 +363,7 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
     '#type' => 'markup',
     '#prefix' => '<div id="property-save-warning" class="messages warning" style="display:none;">',
     '#suffix' => '</div>',
-    '#markup' => '* The changes to these properties will not be saved until the 
+    '#markup' => '* The changes to these properties will not be saved until the
       "Save" button at the bottom of this form is clicked. <span class="specific-changes"></span>',
     '#attached' => array(
       'js' => array(
@@ -649,7 +649,7 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
  * @ingroup tripal_core
  */
 function chado_add_node_form_properties_add_button_validate($form, &$form_state) {
-  
+
   // Ensure the type_id is supplied & Valid
   $cvterm = chado_select_record(
     'cvterm',

+ 2 - 2
legacy/tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -254,7 +254,7 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
         to the %cv_name controlled vocabulary.',
         array(
           '%cv_name' => $details['cv_name'],
-          '@cvtermlink' => url('admin/tripal/vocab/cv/'.$details['cv_id'].'/cvterm/add')
+          '@cvtermlink' => url('admin/tripal/loaders/chado_cv/'.$details['cv_id'].'/cvterm/add')
         )
       ),
       TRIPAL_WARNING,
@@ -267,7 +267,7 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
         a controlled vocabulary term</a> to the %cv_name controlled vocabulary.',
         array(
           '%cv_name' => $details['cv_name'],
-          '@cvtermlink' => url('admin/tripal/vocab/cv/' . $details['cv_id'] . '/cvterm/add')
+          '@cvtermlink' => url('admin/tripal/loaders/chado_cv/' . $details['cv_id'] . '/cvterm/add')
         )
       ),
       TRIPAL_INFO,

+ 1 - 1
legacy/tripal_cv/api/tripal_cv.api.inc

@@ -97,7 +97,7 @@ function tripal_get_cvterm_default_select_options($table, $field, $field_desc) {
     if (count($options) == 0) {
       tripal_set_message('There are no ' . $field_desc . '. Please ' .
           l('add terms',
-              'admin/tripal/vocab/cv/' .$default_cv->cv_id. '/cvterm/add',
+              'admin/tripal/loaders/chado_cv/' .$default_cv->cv_id. '/cvterm/add',
               array('attributes' => array('target' => '_blank'))) . ' to the ' .
           $default_cv->name .' vocabulary.',
           TRIPAL_WARNING);

+ 3 - 42
legacy/tripal_cv/includes/tripal_cv.cv_defaults.inc

@@ -1,44 +1,5 @@
 <?php
-/**
- * Provide landing page to the new admin pages
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_admin_cv_listing() {
-  $output = '';
-
-  // set the breadcrumb
-  $breadcrumb = array();
-  $breadcrumb[] = l('Home', '<front>');
-  $breadcrumb[] = l('Administration', 'admin');
-  $breadcrumb[] = l('Tripal', 'admin/tripal');
-  $breadcrumb[] = l('Chado Modules', 'admin/tripal/legacy');
-  $breadcrumb[] = l('Vocabularies', 'admin/tripal/legacy/vocab');
-  drupal_set_breadcrumb($breadcrumb);
-
-  // Add the view
-  $cvs_view = views_embed_view('tripal_cv_admin_cvs','default');
-  $cvterms_view = views_embed_view('tripal_cv_admin_cvterms','default');
-  if (isset($cvs_view) && isset($cvterms_view)) {
-    $output .= $cvs_view;
-  }
-  else {
-    $output .= '<p>The Tripal Controlled Vocabulary module uses primarily views to provide an '
-        . 'administrative interface. Currently one or more views needed for this '
-            . 'administrative interface are disabled. <strong>Click each of the following links to '
-                . 'enable the pertinent views</strong>:</p>';
-    $output .= '<ul>';
-    if (!isset($cvs_view)) {
-      $output .= '<li>'.l('Tripal Vocabularies', 'admin/tripal/vocab/views/cvs/enable').'</li>';
-    }
-    if (!isset($cvterm_view)) {
-      $output .= '<li>'.l('Tripal Vocabulary Terms', 'admin/tripal/vocab/views/cvterms/enable').'</li>';
-    }
-    $output .= '</ul>';
-  }
 
-  return $output;
-}
 
 /**
  *
@@ -118,18 +79,18 @@ function tripal_cv_admin_set_defaults_form($form, &$form_state) {
     );
 
     // Actions
-    $view_terms = l('New Vocabulary', 'admin/tripal/vocab/cv/add');
+    $view_terms = l('New Vocabulary', 'admin/tripal/loaders/chado_cv/add');
     $add_term = '';
     if (!empty($cv)) {
       $view_terms = l(
           'View Terms',
-          'admin/tripal/vocab/cvterms',
+          'admin/tripal/loaders/chado_cvterms',
           array('query' => array('cv' => $cv->name))
       );
 
       $add_term = l(
           'Add Term',
-          'admin/tripal/vocab/cv/' . $cv->cv_id . '/cvterm/add'
+          'admin/tripal/loaders/chado_cv/' . $cv->cv_id . '/cvterm/add'
       );
     }
     $form['settings']['existing'][$cv_default_id]["view-terms"] = array(

+ 0 - 256
legacy/tripal_cv/includes/tripal_cv.cv_form.inc

@@ -4,260 +4,4 @@
  * Provides a form for creating & editing chado controlled vocabularies
  */
 
-/**
- * Provides the actual "Select CV" form on the Update/Delete Controlled
- *   Vocabulary page. This form also triggers the edit javascript
- * @todo Modify this form to use Drupal AJAX
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cv_edit_form($form, &$form_state) {
-
-  // get the cv_d if form was submitted via AJAX
-  $cv_id = 0;
-  if (array_key_exists('values', $form_state)) {
-    $cv_id = $form_state['values']['cv_id'];
-  }
-  elseif (isset($form_state['build_info']['args'][0])) {
-    $cv_id = $form_state['build_info']['args'][0];
-  }
-
-  // get a list of db from chado for user to choose
-  $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
-  $results = chado_query($sql);
-
-  $cvs = array();
-  $cvs[] = 'Select a vocabulary';
-  foreach ($results as $cv) {
-    $cvs[$cv->cv_id] = $cv->name;
-  }
-
-  $form['cv_id'] = array(
-    '#title' => t('Controlled Vocabulary Name'),
-    '#type' => 'select',
-    '#options' => $cvs,
-    '#ajax' => array(
-      'callback' => 'tripal_cv_edit_form_ajax',
-      'wrapper'  => 'cv-edit-div',
-      'effect'   => 'fade',
-      'event'    => 'change',
-      'method'   => 'replace',
-    ),
-    '#default_value' => $cv_id,
-  );
-
-
-  // if we don't have a db_id then we can  return the form, otherwise
-  // add in the other fields
-  if ($cv_id) {
-    tripal_cv_add_cv_form_fields($form, $form_state, $cv_id);
-
-    $form['update'] = array(
-      '#type'         => 'submit',
-      '#value'        => t('Update'),
-    );
-    $form['delete'] = array(
-      '#type'         => 'submit',
-      '#value'        => t('Delete'),
-      '#attributes'   => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),
-    );
-  }
-  else {
-    // if we don't have a dbid then this is the first time the form has
-    // benn loaded and we need to create the div where ajax replacement elements get stored
-    $form['div_replace'] = array(
-      '#type' => 'item',
-      '#prefix' => '<div id="cv-edit-div">',
-      '#suffix' => '</div>',
-    );
-  }
-  return $form;
-}
-
-/**
- * Form to add contolled vocabularies
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cv_add_form($form, &$form_state) {
-
-  // add in the form fields to this form
-  tripal_cv_add_cv_form_fields($form, $form_state);
-
-  $form['add'] = array(
-    '#type'         => 'submit',
-    '#value'        => t('Add'),
-    '#weight'       => 5,
-  );
-  return $form;
-}
-
-/**
- * Form fields in common between the cv add & edit form.
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_add_cv_form_fields(&$form, $form_state, $cv_id = NULL) {
-
-  $default_name = '';
-  $default_desc = '';
-
-  if ($cv_id) {
-    $values = array('cv_id' => $cv_id);
-    $result = chado_select_record('cv', array('*'), $values);
-    $cv = $result[0];
-    $default_name = $cv->name;
-    $default_desc = $cv->definition;
-  }
-
-  // add a fieldset for the Drupal Schema API
-  $form['fields'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Controlled Vocabulary Details',
-    '#collapsible' => 0,
-  );
-
-  $form['fields']['name']= array(
-    '#type'          => 'textfield',
-    '#title'         => t("Controlled Vocabulary name"),
-    '#description'   => t('Please enter the name for this vocabulary.'),
-    '#required'      => TRUE,
-    '#default_value' => $default_name,
-    '#maxlength'     => 255,
-  );
-
-  $form['fields']['definition']= array(
-    '#type'          => 'textarea',
-    '#title'         => t('Description'),
-    '#description'   => t('Please enter a definition for this vocabulary'),
-    '#default_value' => $default_desc,
-  );
-
-  return $form;
-}
-
-/**
- * Validation fucntion for tripal_cv_cv_add_form
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cv_add_form_validate($form, &$form_state) {
-  tripal_cv_form_fields_validate($form, $form_state);
-}
-
-/**
- * Validation fucntion for tripal_cv_cv_edit_form
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cv_edit_form_validate($form, &$form_state) {
-  tripal_cv_form_fields_validate($form, $form_state);
-}
-
-/**
- * Generic validation form for shared fields of both the edit and add forms
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_form_fields_validate($form, &$form_state) {
-  $name =  array_key_exists('name', $form_state['values'])       ? trim($form_state['values']['name']) : '';
-  $desc =  array_key_exists('definition', $form_state['values']) ? trim($form_state['values']['definition']) : '';
-  $cv_id = array_key_exists('cv_id', $form_state['values'])      ? trim($form_state['values']['cv_id']) : '';
-
-
-  // make sure the cv name is unique
-  $values = array('name' => $name);
-  $results = chado_select_record('cv', array('cv_id'), $values);
-  if (count($results) > 0 and $results[0]->cv_id != $cv_id) {
-    form_set_error('name', 'The vocabulary name must be unique');
-  }
-}
-
-/**
- * Submit cv add form
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cv_add_form_submit($form, &$form_state) {
-
-  $name =  array_key_exists('name', $form_state['values'])       ? trim($form_state['values']['name']) : '';
-  $desc =  array_key_exists('definition', $form_state['values']) ? trim($form_state['values']['definition']) : '';
-
-  $values = array(
-    'name' => $name,
-    'definition' => $desc,
-  );
-  $success = chado_insert_record('cv', $values);
-  if ($success) {
-    drupal_set_message(t("Controlled vocabulary added"));
-  }
-  else {
-    drupal_set_message(t("Failed to add controlled vocabulary."));
-  }
-}
-
-/**
- * Submit cv edit form
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cv_edit_form_submit($form, &$form_state) {
-  $name  = array_key_exists('name', $form_state['values'])       ? trim($form_state['values']['name']) : '';
-  $desc  = array_key_exists('definition', $form_state['values']) ? trim($form_state['values']['definition']) : '';
-  $cv_id = array_key_exists('cv_id', $form_state['values'])      ? trim($form_state['values']['cv_id']) : '';
-  $op    = array_key_exists('op', $form_state['values'])         ? trim($form_state['values']['op']) : '';
-
-  $values = array(
-    'name' => $name,
-    'definition' => $desc,
-  );
-  if (strcmp($op, 'Update')==0) {
-    $match = array('cv_id' => $cv_id);
-    $success = chado_update_record('cv', $match, $values);
-    if ($success) {
-      drupal_set_message(t("Controlled vocabulary updated"));
-    }
-    else {
-      drupal_set_message(t("Failed to update controlled vocabulary."));
-    }
-  }
-  if (strcmp($op, 'Delete')==0) {
-    $match = array('cv_id' => $cv_id);
-    $success = chado_delete_record('cv', $match);
-    if ($success) {
-      drupal_set_message(t("Controlled vocabulary deleted"));
-    }
-    else {
-      drupal_set_message(t("Failed to delete controlled vocabulary."));
-    }
-  }
-}
-
-/**
- * Ajax callback for the tripal_cv_form
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_edit_form_ajax($form, $form_state) {
-
-  $elements = array();
-
-  // add in the form fields and the buttons
-  if (array_key_exists('cv_id', $form_state['values'])) {
-    $elements['fields'] = $form['fields'];
-    $elements['update'] = $form['update'];
-    $elements['delete'] = $form['delete'];
-  }
-
-   // add back in the cv-edit-div that is used for the next round of AJAX
-  $elements['fields']['#prefix'] =  '<div id="cv-edit-div">';
-  $elements['fields']['#suffix'] =  '</div">';
-
-  // reset the values for the fields to the defaults
-  $elements['fields']['name']['#value']        = $elements['fields']['name']['#default_value'];
-  $elements['fields']['definition']['#value']  = $elements['fields']['definition']['#default_value'];
-
-  //drupal_set_message('<pre>' . print_r($elements, TRUE) . '</pre>', "status");
 
-  return $elements;
-}

+ 0 - 474
legacy/tripal_cv/includes/tripal_cv.cvterm_form.inc

@@ -3,477 +3,3 @@
  * @file
  * Provides a form for creating & editing chado controlled vocabularies
  */
-
-/**
- * Form for editing cvterms
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cvterm_edit_form($form, &$form_state) {
-
-  $step = 0;
-  if (empty($form_state['storage']['step'])) {
-    $form_state['storage']['step'] = 0;
-  }
-  else {
-    $step = $form_state['storage']['step'];
-  }
-
-  $cv_id = 0;
-  if ($step == 1) {
-    $cv_id = $form_state['storage']['cv_id'];
-    $cvterm_name = $form_state['storage']['name'];
-    $cvterm_id = $form_state['storage']['cvterm_id'];
-  }
-  // get the cv if form was submitted via AJAX
-  $cvterm = '';
-  if (array_key_exists('values', $form_state)) {
-    $cv_id = $form_state['values']['cv_id'];
-    if (array_key_exists('cvterm', $form_state['values'])) {
-      $cvterm = $form_state['values']['cvterm'];
-    }
-  }
-  elseif (isset($form_state['build_info']['args'][0])) {
-    $cv_id = $form_state['build_info']['args'][0];
-    $cvterm_id = $form_state['build_info']['args'][1];
-    if ($form_state['build_info']['args'][1]) {
-      $result = db_select('chado.cvterm','c')
-        ->fields('c', array('name'))
-        ->condition('c.cvterm_id',$cvterm_id)
-        ->execute();
-      $cvterm_name = $result->fetchObject()->name;
-      $step = 1;
-    }
-  }
-
-  // get a list of CVs
-  $cvs = array();
-  $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
-  $results = chado_query($sql);
-  $cvs[] = 'Select a vocabulary';
-  foreach ($results as $cv) {
-    $cvs[$cv->cv_id] = $cv->name;
-  }
-  $form['cv_id'] = array(
-    '#title' => t('Controlled Vocabulary (Ontology) Name'),
-    '#type' => 'select',
-    '#options' => $cvs,
-    '#required' => TRUE,
-    '#default_value' => $cv_id,
-    '#ajax' => array(
-       'callback'    => 'tripal_cv_cvterm_edit_form_ajax',
-       'wrapper' => 'cvterm-edit-div',
-       'event'   => 'change',
-       'method'  => 'replace',
-       'event'    => 'change',
-    ),
-  );
-
-  if ($cv_id and $step == 0) {
-
-    $form['name']= array(
-      '#type'          => 'textfield',
-      '#title'         => t("Term Name"),
-      '#default_value' => $cvterm,
-      '#required'      => TRUE,
-      '#autocomplete_path' => "admin/tripal/tripal_cv/cvterm/auto_name/$cv_id",
-      '#description'   => t('Enter the term to edit.')
-    );
-    $form['continue']= array(
-      '#type'          => 'submit',
-      '#value'         => 'continue',
-    );
-  }
-  elseif ($step == 1) {
-
-    tripal_cv_add_cvterm_form_fields($form, $form_state, $cv_id, $cvterm_name);
-
-    // when editing there are certain fields the user should not change for a term
-    // let's mark those as disabled
-    $form['cv_id']['#disabled'] = TRUE;
-    $form['fields']['db_id']['#disabled'] = TRUE;
-    $form['fields']['accession']['#disabled'] = TRUE;
-
-    // add in the div for replacing the fields if needed
-    $form['fields']['#prefix'] = '<div id="cvterm-edit-div">';
-    $form['fields']['#suffix'] = '</div>';
-
-    // add in the cvterm id
-    $form['fields']['cvterm_id'] = array(
-      '#type' => 'hidden',
-      '#value' =>  $cvterm_id,
-    );
-
-    $form['update'] = array(
-      '#type'         => 'submit',
-      '#value'        => t('Update'),
-    );
-    $form['delete'] = array(
-      '#type'         => 'submit',
-      '#value'        => t('Delete'),
-      '#attributes'   => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),
-    );
-  }
-
-  if ($step == 0) {
-    // if we don't have a cv_id then this is the first time the form has
-    // benn loaded and we need to create the div where ajax replacement elements get stored
-    $form['div_replace'] = array(
-      '#type' => 'item',
-      '#prefix' => '<div id="cvterm-edit-div">',
-      '#suffix' => '</div>',
-    );
-  }
-  return $form;
-}
-
-/**
- * Form for adding cvterms
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cvterm_add_form($form, &$form_state) {
-  $cv_id = 0;
-  if (array_key_exists('values', $form_state)) {
-    $cv_id = $form_state['values']['cv_id'];
-  }
-  elseif (isset($form_state['build_info']['args'][0])) {
-    $cv_id = $form_state['build_info']['args'][0];
-  }
-
-  // get a list of CVs
-  $cvs = array();
-  $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
-  $results = chado_query($sql);
-  $cvs[] = 'Select a vocabulary';
-  foreach ($results as $cv) {
-    $cvs[$cv->cv_id] = $cv->name;
-  }
-  $form['cv_id'] = array(
-    '#title' => t('Controlled Vocabulary (Ontology) Name'),
-    '#type' => 'select',
-    '#options' => $cvs,
-    '#required' => TRUE,
-    '#default_value' => $cv_id,
-  );
-  tripal_cv_add_cvterm_form_fields($form, $form_state);
-
-  $form['add'] = array(
-    '#type'         => 'submit',
-    '#value'        => t('Add Term'),
-  );
-
-  return $form;
-}
-
-/**
- * Form fields in common between add/edit forms
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_add_cvterm_form_fields(&$form, $form_state, $cv_id = 0, $cvterm_name = '') {
-
-  $name = '';
-  $definition = '';
-  $is_relationship = '';
-  $is_obsolete = '';
-  $db_id = '';
-  $accession = '';
-
-  // get default values
-  if ($cvterm_name) {
-    $values = array('cv_id' => $cv_id, 'name' => $cvterm_name);
-    $cvterm = chado_generate_var('cvterm', $values);
-    $name = $cvterm->name;
-    $definition = $cvterm->definition;
-    $is_relationship = $cvterm->is_relationshiptype;
-    $is_obsolete = $cvterm->is_obsolete;
-    $db_id = $cvterm->dbxref_id->db_id->db_id;
-    $accession = $cvterm->dbxref_id->accession;
-  }
-
-  // add a fieldset for the Drupal Schema API
-  $form['fields'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Term Details',
-    '#collapsible' => 0,
-  );
-
-  $form['fields']['name']= array(
-    '#type'          => 'textfield',
-    '#title'         => t("Term Name"),
-    '#default_value' => $name,
-    '#description'   => t('The term must be unique within the database selected below.'),
-    '#required'      => TRUE,
-  );
-
-  $form['fields']['internal_id']= array(
-    '#type'          => 'item',
-    '#title'         => t("Internal ID"),
-    '#markup'        => $cvterm->cvterm_id,
-  );
-
-  $form['fields']['definition']= array(
-    '#type'          => 'textarea',
-    '#title'         => t('Description'),
-    '#description'   => t('Please enter a description for this term'),
-    '#default_value' => $definition,
-  );
-
-  $form['fields']['is_relationship'] = array(
-    '#type'          => 'checkbox',
-    '#title'         => t('This term describes a relationship?'),
-    '#default_value' => $is_relationship,
-  );
-
-  $form['fields']['is_obsolete'] = array(
-    '#type'          => 'checkbox',
-    '#title'         => t('This term is obsolete?'),
-    '#default_value' => $is_obsolete,
-  );
-
-  $values = array();
-  $columns = array('db_id', 'name');
-  $options = array('order_by' => array('name' => 'ASC'));
-  $results = chado_select_record('db', $columns, $values, $options);
-  $dbs = array();
-  $dbs[] = '';
-  foreach ($results as $db) {
-    $dbs[$db->db_id] = $db->name;
-  }
-  $form['fields']['db_id'] = array(
-    '#type'         => 'select',
-    '#title'         => t('Database'),
-    '#description'   => t('All terms must be assocated with a database. If there is no database for this term (e.g. it is a custom term specific to this site) then select the database \'null\' or consider creating a database specific for your site and use that anytime you would like to add terms.'),
-    '#options'      => $dbs,
-    '#default_value' => $db_id,
-    '#required' => TRUE,
-  );
-
-  $form['fields']['accession']= array(
-    '#type'          => 'textfield',
-    '#title'         => t("Accession"),
-    '#description'   => t('If this term has an existing accession (unique identifier) in the database
-       please enter that here.  If the accession is numeric with a database prefix (e.g. GO:003023), please
-       enter just the numeric value.  The database prefix will be appended whenever the term is displayed.
-       If you do not have a numeric value consider entering the term name as the accession.'),
-    '#required'      => TRUE,
-    '#default_value' => $accession,
-  );
-}
-
-/**
- * Validate cvterm edit form
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cvterm_edit_form_validate($form, &$form_state) {
-  $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
-  $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
-  $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
-  $cvterm_id = array_key_exists('cvterm_id', $form_state['values']) ? $form_state['values']['cvterm_id'] : '';
-  $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';
-
-  $step = $form_state['storage']['step'];
-
-  // make sure the cv term name is unique for this vocabulary
-  if ($step == 1) {
-    $values = array('name' => $name, 'cv_id' => $cv_id);
-    $results = chado_select_record('cvterm', array('cvterm_id'), $values);
-    foreach ($results as $r) {
-      if ($r->cvterm_id != $cvterm_id) {
-        form_set_error('name', 'The term name must be unique for this vocabulary. Another term with this name already exists.');
-      }
-    }
-  }
-}
-
-/**
- * Validate cv add form
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cvterm_add_form_validate($form, &$form_state) {
-  $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
-  $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
-  $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
-  $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';
-
-  $values = array('cv_id' => $cv_id);
-  $results = chado_select_record('cv', array('name'), $values);
-  if (!$results or count($results) == 0) {
-    form_set_error('cv_id', 'The controlled vocabulary does not exist');
-  }
-
-  // make sure the DB exists
-  $values = array('db_id' => $db_id);
-  $results = chado_select_record('db', array('name'), $values);
-  if (!$results or count($results) == 0) {
-    form_set_error('db_id', 'The database name does not exist');
-  }
-
-  // make sure the cv term name is unique for this vocabulary
-  $values = array('name' => $name, 'cv_id' => $cv_id);
-  $results = chado_select_record('cvterm', array('cvterm_id'), $values);
-  if (count($results) > 0) {
-    form_set_error('name', 'The term name must be unique for this vocabulary. Another term with this name already exists.');
-  }
-
-  // make sure this accession is unique for the database
-  $values = array('accession' => $accession, 'db_id' => $db_id);
-  $results = chado_select_record('dbxref', array('dbxref_id'), $values);
-  if (count($results) > 0 ) {
-    form_set_error('accession', 'The accession is not uniuqe for this vocabulary\'s database.');
-  }
-
-}
-
-/**
- * Edits existing controlled vocabulary terms
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cvterm_edit_form_submit($form, &$form_state) {
-
-  $cv_id           = array_key_exists('cv_id', $form_state['values'])           ? trim($form_state['values']['cv_id']) : '';
-  $name            = array_key_exists('name', $form_state['values'])            ? trim($form_state['values']['name']) : '';
-  $definition      = array_key_exists('definition', $form_state['values'])      ? trim($form_state['values']['definition']) : '';
-  $is_relationship = array_key_exists('is_relationship', $form_state['values']) ? trim($form_state['values']['is_relationship']) : '';
-  $is_obsolete     = array_key_exists('is_obsolete', $form_state['values'])     ? trim($form_state['values']['is_obsolete']) : '';
-  $cvterm_id       = array_key_exists('cvterm_id', $form_state['values'])       ? trim($form_state['values']['cvterm_id']) : '';
-  $db_id           = array_key_exists('db_id', $form_state['values'])           ? trim($form_state['values']['db_id']) : '';
-  $accession       = array_key_exists('accession', $form_state['values'])       ? trim($form_state['values']['accession']) : '';
-  $op              = array_key_exists('op', $form_state['values'])              ? trim($form_state['values']['op']) : '';
-
-
-  $step = $form_state['storage']['step'];
-
-  switch ($step) {
-    case 0:  // a cvterm name has been selected
-      $cv_id = array_key_exists('cv_id', $form_state['values']) ? trim($form_state['values']['cv_id']) : '';
-      $name  = array_key_exists('name', $form_state['values'])  ? trim($form_state['values']['name'])  : '';
-
-      // get the original cvterm_id
-      $values = array('name' => $name, 'cv_id' => $cv_id);
-      $results = chado_select_record('cvterm', array('cvterm_id'), $values);
-      $cvterm = $results[0];
-
-      $form_state['storage']['cv_id'] = $cv_id;
-      $form_state['storage']['name'] = $name;
-      $form_state['storage']['step'] = 1;
-      $form_state['storage']['cvterm_id'] = $cvterm->cvterm_id;
-      $form_state['rebuild'] = TRUE;
-      break;
-
-    case 1:  // update/delete button has been clicked
-
-      if ($op == 'Update') {
-        // get the cv
-        $values = array('cv_id' => $cv_id);
-        $results = chado_select_record('cv', array('name'), $values);
-        $cv = $results[0];
-
-        // get the db
-        $values = array('db_id' => $db_id);
-        $results = chado_select_record('db', array('name'), $values);
-        $db = $results[0];
-
-        // now add the term
-        $term = array(
-          'name' => $name,
-          'namespace' => $cv->name,
-          'id' => $accession,
-          'definition' => $definition,
-          'is_obsolete' => $is_obsolete,
-          'cv_name' => $cv->name,
-          'is_relationship' => $is_relationship,
-          'db_name' => $db_name
-        );
-
-        $cvterm = tripal_insert_cvterm($term, array('update_existing' => TRUE));
-        if ($cvterm) {
-          drupal_set_message('Term updated successfully.');
-        }
-        else {
-          drupal_set_message('Could not add term. Check Drupal recent logs for error messages.', 'error');
-        }
-      }
-      if ($op == 'Delete') {
-        $values = array('cvterm_id' => $cvterm_id);
-        $success = chado_delete_record('cvterm', $values);
-        if ($success) {
-          drupal_set_message('Term deleted successfully.');
-        }
-        else {
-          drupal_set_message('Could not delete term term. Check Drupal recent logs for error messages.', 'error');
-        }
-      }
-      break;
-  }
-}
-
-/**
- * Adds new terms to an existing cv
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cvterm_add_form_submit($form, &$form_state) {
-  $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
-  $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
-  $definition = array_key_exists('definition', $form_state['values']) ? $form_state['values']['definition'] : '';
-  $is_relationship = array_key_exists('is_relationship', $form_state['values']) ? $form_state['values']['is_relationship'] : '';
-  $is_obsolete = array_key_exists('is_obsolete', $form_state['values']) ? $form_state['values']['is_obsolete'] : '';
-
-  $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
-  $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';
-
-  // get the database
-  $values = array('db_id' => $db_id);
-  $results = chado_select_record('db', array('name'), $values);
-  $db = $results[0];
-
-  // get the cv
-  $values = array('cv_id' => $cv_id);
-  $results = chado_select_record('cv', array('name'), $values);
-  $cv = $results[0];
-
-  // now add the term
-  $term = array(
-    'name' => $name,
-    'namespace' => $cv->name,
-    'id' => $accession,
-    'definition' => $definition,
-    'is_obsolete' => $is_obsolete,
-    'cv_name' => $cv->name,
-    'is_relationship' => $is_relationship,
-    'db_name' => $db->name
-  );
-
-  $cvterm = tripal_insert_cvterm($term, array('update_existing' => TRUE));
-  if ($cvterm) {
-    drupal_set_message('Term added successfully.');
-  }
-  else {
-    drupal_set_message('Could not add term. Check Drupal recent logs for error messages.', 'error');
-  }
-}
-
-/**
- * Ajax callback for the tripal_cv_form
- *
- * @ingroup tripal_cv
- */
-function tripal_cv_cvterm_edit_form_ajax($form, $form_state) {
-
-  $elements = array();
-
-  $elements['name'] = $form['name'];
-  $elements['continue'] = $form['continue'];
-
-  // add back in the cv-edit-div that is used for the next round of AJAX
-  $elements['name']['#prefix'] =  '<div id="cvterm-edit-div">';
-  $elements['name']['#suffix'] =  '</div">';
-
-
-  return $elements;
-}

+ 1 - 1
legacy/tripal_feature/includes/tripal_feature.chado_node.inc

@@ -151,7 +151,7 @@ function chado_feature_form($node, &$form_state) {
    '#description' => t("Choose the feature type."),
    '#required'    => TRUE,
    '#default_value' => $feature_type,
-   '#autocomplete_path' => "admin/tripal/vocab/cvterm/auto_name/$cv_id",
+   '#autocomplete_path' => "aadmin/tripal/storage/chado/auto_name/cvterm/$cv_id",
   );
 
   // get the list of organisms

+ 1 - 1
legacy/tripal_feature/includes/tripal_feature.delete.inc

@@ -32,7 +32,7 @@ function tripal_feature_delete_form() {
    '#title'       => t('Feature Type'),
    '#type'        => 'textfield',
    '#description' => t("Choose the feature type."),
-   '#autocomplete_path' => "admin/tripal/vocab/cvterm/auto_name/$cv->cv_id",
+   '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/$cv->cv_id",
   );
 
   $organisms = tripal_get_organism_select_options(FALSE);

+ 1 - 1
legacy/tripal_library/includes/tripal_library.chado_node.inc

@@ -128,7 +128,7 @@ function chado_library_form($node, &$form_state) {
   $lt_message = tripal_set_message("To add additional items to the library type drop down list,
      add a term to the " .
      l($lt_cv->name . " controlled vocabulary",
-       "admin/tripal/vocab/cv/" . $lt_cv->cv_id . "/cvterm/add",
+       "admin/tripal/loaders/chado_cv/" . $lt_cv->cv_id . "/cvterm/add",
        array('attributes' => array('target' => '_blank'))
       ),
      TRIPAL_INFO, array('return_html' => TRUE)

+ 1 - 1
legacy/tripal_stock/includes/tripal_stock.chado_node.inc

@@ -202,7 +202,7 @@ function chado_stock_form($node, $form_state) {
   $st_message = tripal_set_message("To add additional items to the stock type drop down list,
      add a term to the " .
     l($st_cv->name . " controlled vocabulary",
-      "admin/tripal/vocab/cv/" . $st_cv->cv_id . "/cvterm/add",
+      "admin/tripal/loaders/chado_cv/" . $st_cv->cv_id . "/cvterm/add",
       array('attributes' => array('target' => '_blank'))
     ),
     TRIPAL_INFO, array('return_html' => TRUE)

+ 42 - 309
tripal/includes/TripalBundleUIController.inc

@@ -412,8 +412,7 @@ function tripal_bundle_access($op, $type = NULL, $account = NULL) {
  */
 function tripal_admin_add_type_form($form, &$form_state) {
 
-  // TODO: the Chado specific function calls should not be here.  They need
-  // to be genericized.
+
   $stores = module_invoke_all('vocab_storage_info');
   if (!is_array($stores) or count($stores) == 0) {
     tripal_set_message('A storage backend is not enabled for managing
@@ -456,6 +455,8 @@ function tripal_admin_add_type_form($form, &$form_state) {
     ),
   );
 
+  // If the term has been provided by the user then we want to search for
+  // matching terms in the database and let them select among any matches.
   if ($term_name) {
     $submit_disabled = TRUE;
     $form['terms_list'] = array(
@@ -471,7 +472,10 @@ function tripal_admin_add_type_form($form, &$form_state) {
     $terms = chado_generate_var('cvterm', $match, array('return_array' => TRUE));
     $terms = chado_expand_var($terms, 'field', 'cvterm.definition');
     $num_terms = 0;
-    $selected_term_id = '';
+    $selected_term = '';
+
+    // Let the user select from any matching terms. Sometimes there may be
+    // more than one that match.
     foreach ($terms as $term) {
       // Save the user a click by setting the default value as 1 if there's
       // only one matching term.
@@ -500,7 +504,7 @@ function tripal_admin_add_type_form($form, &$form_state) {
 
       if (array_key_exists('values', $form_state) and array_key_exists($term_element_name, $form_state['values']) and
           $form_state['values'][$term_element_name] == 1) {
-        $selected_term_id = $term->cvterm_id;
+        $selected_term = $term;
       }
       $num_terms++;
     }
@@ -510,6 +514,8 @@ function tripal_admin_add_type_form($form, &$form_state) {
         '#markup' => '<i>' . t('There is no term that matches the entered text.') . '</i>'
       );
     }
+
+    // Now let the user select where the data type will be stored.
     $form['storage'] = array(
       '#type' => 'fieldset',
       '#title' => t('Storage Settings'),
@@ -518,12 +524,9 @@ function tripal_admin_add_type_form($form, &$form_state) {
           storage method and settings for this content type.')
     );
 
-    // TODO: we should have a default store setting so that user's have
-    // fewer clicks.
-
     // TODO: there should be a way for each storage backend to determine if
     // it can handle the content type.  Maybe certain content types aren't
-    // yet supported by every sotrage backend.
+    // yet supported by every storage backend.
     $default_store = 'term_chado_storage';
     $store_options = array(0 => '-- Select --');
     foreach ($stores as $store_type => $store) {
@@ -548,273 +551,14 @@ function tripal_admin_add_type_form($form, &$form_state) {
     );
 
     if ($default_store) {
-      if ($store_type == 'term_chado_storage') {
-        // TODO: Move this Chado-specific code out of there.
-        $default_table = '';
-        if (array_key_exists('base_chado_table', $form_state['values'])
-            and $form_state['values']['base_chado_table']) {
-          $default_table = $form_state['values']['base_chado_table'];
-        }
-        else {
-          $mapped_table = chado_get_cvterm_mapping(array('cvterm_id' => $selected_term_id));
-          if ($mapped_table) {
-            $default_table = $mapped_table->chado_table;
-          }
-        }
-
-        $form['storage'][$store_type]['selected_cvterm_id'] = array(
-          '#type' => 'value',
-          '#value' => $selected_term_id,
-        );
-
-        $base_tables = chado_get_base_tables();
-        $options = array(0 => '-- Select table --');
-        foreach ($base_tables AS $tablename) {
-          $options[$tablename] = $tablename;
-        }
-        $form['storage'][$store_type]['base_chado_table'] = array(
-          '#type' => 'select',
-          '#title' => 'Chado table',
-          '#options' => $options,
-          '#description' => 'Select the Chado table into which the primary records for this content type will be stored.',
-          '#default_value' => $default_table,
-          '#ajax' => array(
-            'callback' => "tripal_admin_add_type_form_ajax_callback",
-            'wrapper' => "tripal-vocab-select-form",
-            'effect' => 'fade',
-            'method' => 'replace'
-          ),
-        );
-        $form_state['input']['base_chado_table'] = $default_table;
-
-        if ($default_table) {
-
-          // There are a few places in form below where the type columns
-          // can be used to identify a record. So, we'll create the
-          // select options here so it can be used multiple places.  We
-          // only want to include in our column options those fields that
-          // are foreign keys to the cvterm table
-          $schema = chado_get_schema($default_table);
-          $column_options = array('0' => '--Select column--');
-          $cvt_fkeys = array_keys($schema['foreign keys']['cvterm']['columns']);
-          foreach ($schema['fields'] as $column_name => $column_details) {
-            if (in_array($column_name, $cvt_fkeys)) {
-              $column_options[$column_name] = $column_name;
-            }
-          }
-
-          $default_has_all = 'No';
-          if (array_key_exists('chado_table_has_all', $form_state['values'])
-              and $form_state['values']['chado_table_has_all']) {
-            $default_has_all = $form_state['values']['chado_table_has_all'];
-          }
-          $form['storage'][$store_type]['chado_table_has_all'] = array(
-            '#type' => 'radios',
-            '#options' => array(
-              'Yes' => 'Yes',
-              'No' => 'No'
-            ),
-            '#title' => 'Are all records in the "' . $default_table .
-              '" table of type "'. $term_name . '"?',
-            '#description' => 'Select "Yes" if the "' .
-              $default_table . '" table houses more that just data of type "' .
-              $term_name . '".',
-            '#default_value' => $default_has_all,
-            '#ajax' => array(
-              'callback' => "tripal_admin_add_type_form_ajax_callback",
-              'wrapper' => "tripal-vocab-select-form",
-              'effect' => 'fade',
-              'method' => 'replace'
-            ),
-          );
-
-          // If the table does not contain just one single type of record.
-          if ($default_has_all == 'No') {
-
-            $default_type_column = '';
-            if (array_key_exists('type_id', $schema['fields'])) {
-              $default_type_column = 'type_id';
-            }
-
-            // If the table doesn't have an obvious type_id column then
-            // let the user specify how record types are identified.
-            if ($default_type_column) {
-
-              $default_has_type = 'Yes';
-              if (array_key_exists('chado_table_has_type', $form_state['values'])
-                  and $form_state['values']['chado_table_has_type']) {
-                $default_has_type = $form_state['values']['chado_table_has_type'];
-              }
-              $form['storage'][$store_type]['chado_table_has_type'] = array(
-                '#type' => 'radios',
-                '#title' => 'Do you want to use the "' . $default_table . '.' .
-                   $default_type_column . '" to distinguish between content types?',
-                '#options' => array(
-                  'Yes' => 'Yes',
-                  'No' => 'No'
-                ),
-                '#description' => t('Many tables in Chado use a "type_id" column
-                    to identify specific data types. For example, the "feature.type_id"
-                    column is used to distinguish between different types of
-                    genomic features that are all housed in the feature table.
-                    But there is sometimes a cvterm linker table where additional
-                    attributes for the record can be set.  Here you can specify if you
-                    want to use the type_id column or select another way
-                    to identify records in the "' . $default_table . '" table that
-                    are of this type'),
-                '#default_value' => $default_has_type,
-                '#ajax' => array(
-                  'callback' => "tripal_admin_add_type_form_ajax_callback",
-                  'wrapper' => "tripal-vocab-select-form",
-                  'effect' => 'fade',
-                  'method' => 'replace'
-                ),
-              );
-
-              // If the type_id column is not wanted to differentiate between
-              // different records of this type then find out if the user wants
-              // to use a linker cvterm table, but only if one exists
-              $linker_table = $default_table . '_cvterm';
-              if ($default_has_type == "Yes") {
-                $submit_disabled = FALSE;
-              }
-              else if ($default_has_type == 'No' and chado_table_exists($linker_table)) {
-                $default_use_linker = 'Yes';
-                if (array_key_exists('chado_type_use_linker', $form_state['values'])
-                    and $form_state['values']['chado_type_use_linker']) {
-                  $default_use_linker = $form_state['values']['chado_type_use_linker'];
-                }
-                $form['storage'][$store_type]['chado_type_use_linker'] = array(
-                  '#type' => 'radios',
-                  '#title' => 'Do you want to use the "' . $linker_table . '" table
-                     to distinguish between content types?',
-                  '#options' => array(
-                    'Yes' => 'Yes',
-                    'No' => 'No'
-                  ),
-                  '#description' => t('Sometimes records can be distringuish
-                      using a linker table, especially if there is no column
-                      in the specified Chado table to identify the
-                      record types. In these cases the linker table is
-                      sometimes used.'),
-                  '#default_value' => $default_use_linker,
-                  '#ajax' => array(
-                    'callback' => "tripal_admin_add_type_form_ajax_callback",
-                    'wrapper' => "tripal-vocab-select-form",
-                    'effect' => 'fade',
-                    'method' => 'replace'
-                  ),
-                );
-
-                if($default_use_linker == 'No') {
-                  if (count(array_keys($column_options)) == 1) {
-                    $form['storage'][$store_type]['type_column'] = array(
-                      '#type' => 'item',
-                      '#title' => 'Type Column',
-                      '#description' => 'The  "' . $default_table .
-                        '" table does not have a column
-                        that stores data types. You cannot map the "' .
-                        $term_name . '" type to this table.',
-                    );
-                  }
-                  else {
-                    $form['storage'][$store_type]['type_column'] = array(
-                      '#type' => 'select',
-                      '#title' => 'Type Column',
-                      '#options' => $column_options,
-                      '#description' => 'Please select the column in the "' .
-                        $default_table . '" table that will identify a record
-                        as being of type "' . $term_name . '".',
-                      '#default_value' => $default_type_column,
-                      '#ajax' => array(
-                        'callback' => "tripal_admin_add_type_form_ajax_callback",
-                        'wrapper' => "tripal-vocab-select-form",
-                        'effect' => 'fade',
-                        'method' => 'replace'
-                      ),
-                    );
-                    $submit_disabled = FALSE;
-                  }
-                } // end if(!$default_use_linker) {
-                else {
-                  $submit_disabled = FALSE;
-                }
-              } // end if ($default_has_type == 'No' and ...
-            } // end else if ($default_type_column) {
-            else {
-              // If the type_id column is not wanted to differentiate between
-              // different records of this type then find out if the user wants
-              // to use a linker table, but only if one exists
-              $linker_table = $default_table . '_cvterm';
-              if (chado_table_exists($linker_table)) {
-                $default_use_linker = 'Yes';
-                if (array_key_exists('chado_type_use_linker', $form_state['values'])
-                    and $form_state['values']['chado_type_use_linker']) {
-                  $default_use_linker = $form_state['values']['chado_type_use_linker'];
-                }
-                $form['storage'][$store_type]['chado_type_use_linker'] = array(
-                  '#type' => 'radios',
-                  '#title' => 'Do you want to use the "' . $linker_table . '" table
-                     to distinguish between content types?',
-                  '#options' => array(
-                    'Yes' => 'Yes',
-                    'No' => 'No'
-                  ),
-                  '#description' => t('Sometimes records can be distringuish
-                      using a linker, especially if there is no column
-                      in the specified Chado table to identify the
-                      record types. In these cases the linker table is
-                      sometimes used.'),
-                  '#default_value' => $default_use_linker,
-                  '#ajax' => array(
-                    'callback' => "tripal_admin_add_type_form_ajax_callback",
-                    'wrapper' => "tripal-vocab-select-form",
-                    'effect' => 'fade',
-                    'method' => 'replace'
-                  ),
-                );
-
-                if($default_use_linker == 'No') {
-                  if (count(array_keys($column_options)) == 1) {
-                    $form['storage'][$store_type]['type_column'] = array(
-                      '#type' => 'item',
-                      '#title' => 'Type Column',
-                      '#description' => 'The  "' . $default_table .
-                        '" table does not have a column
-                        that stores data types. You cannot map the "' .
-                        $term_name . '" type to this table.',
-                    );
-                  }
-                  else {
-                    $form['storage'][$store_type]['type_column'] = array(
-                      '#type' => 'select',
-                      '#title' => 'Type Column',
-                      '#options' => $column_options,
-                      '#description' => 'Please select the column in the "' .
-                        $default_table . '" table that will identify a record
-                        as being of type "' . $term_name . '".',
-                      '#default_value' => $default_type_column,
-                      '#ajax' => array(
-                        'callback' => "tripal_admin_add_type_form_ajax_callback",
-                        'wrapper' => "tripal-vocab-select-form",
-                        'effect' => 'fade',
-                        'method' => 'replace'
-                      ),
-                    );
-                    $submit_disabled = FALSE;
-                  }
-                } // end if(!$default_use_linker) {
-                else {
-                  $submit_disabled = FALSE;
-                }
-              } // end if ($default_has_type == 'No' and ...
-            } // end else
-          } //  end if ($default_has_all == 'No') {
-          else {
-            $submit_disabled = FALSE;
-          }
-        } // end if ($default_table) {
-      } // end if ($default_store) {
+      $selected_store_module = $stores[$store_type]['module'];
+
+      $function = $selected_store_module . '_field_storage_bundle_mapping_form';
+      if (function_exists($function)) {
+        $store_form = $function($form, $form_state, $selected_term, $submit_disabled);
+        $form['storage'][$store_type] = $store_form;
+      }
+
       // Add in the button for the cases of no terms or too many.
       $form['submit_button'] = array(
         '#type' => 'submit',
@@ -843,12 +587,7 @@ function tripal_admin_add_type_form_ajax_callback($form, $form_state) {
  */
 function tripal_admin_add_type_form_validate($form, &$form_state) {
   $stores = module_invoke_all('vocab_storage_info');
-  $keys = array_keys($stores);
-  $module = $stores[$keys[0]]['module'];
-  $function = $module . '_vocab_select_term_form_validate';
-  if (function_exists($function)) {
-    $function($form, $form_state);
-  }
+  $store_select = $form_state['values']['store_select'];
 
   if (array_key_exists('clicked_button', $form_state) and
       $form_state['clicked_button']['#name'] =='use_cvterm') {
@@ -866,6 +605,7 @@ function tripal_admin_add_type_form_validate($form, &$form_state) {
         $num_selected++;
       }
     }
+
     if ($num_selected == 0) {
       form_set_error('', 'Please select at least one term.');
     }
@@ -873,15 +613,20 @@ function tripal_admin_add_type_form_validate($form, &$form_state) {
       form_set_error('term-' . $cvterm_id, 'Please select only one term from the list below.');
     }
     else {
+      // Add the term to the form state so we can access it later.
       $form_state['term']['vocabulary'] = $term->dbxref_id->db_id->name;
       $form_state['term']['accession'] = $term->dbxref_id->accession;
       $form_state['term']['term_name'] = $term->name;
 
-      // Make sure a default table is selected
-      // TODO: move this Chado specific code out.
-      $default_table = $form_state['values']['base_chado_table'];
-      if (!$default_table) {
-        form_set_error('base_chado_table', 'Please select a default table.');
+      // Call the submit hook for this form for the storage method that
+      // will be responsible for this cotent type.
+      $stores = module_invoke_all('vocab_storage_info');
+      $selected_store_module = $stores[$store_select]['module'];
+      $selected_term = $form_state['term'];
+
+      $function = $selected_store_module . '_field_storage_bundle_mapping_form_validate';
+      if (function_exists($function)) {
+        $function($form, $form_state, $selected_term);
       }
     }
   }
@@ -899,6 +644,7 @@ function tripal_admin_add_type_form_submit($form, &$form_state) {
   $accession = '';
   if (array_key_exists('term', $form_state)) {
     $selected_term = $form_state['term'];
+    $store_select = $form_state['values']['store_select'];
     $vocabulary = array_key_exists('vocabulary', $selected_term) ? $selected_term['vocabulary'] : '';
     $accession = array_key_exists('accession', $selected_term) ? $selected_term['accession'] : '';
     $term_name = array_key_exists('term_name', $selected_term) ? $selected_term['term_name'] : '';
@@ -907,34 +653,25 @@ function tripal_admin_add_type_form_submit($form, &$form_state) {
     // as a bundle.
     $term = tripal_load_term_entity(array('vocabulary' => $vocabulary, 'accession' => $accession));
     if (!$term) {
-      $error = '';
-      // TODO: the storage args are Chado specific. This should be made
-      // more generic to support other back-ends.
+
+      // Call the submit hook for this form for the storage method that
+      // will be responsible for this cotent type.
+      $stores = module_invoke_all('vocab_storage_info');
+      $selected_store_module = $stores[$store_select]['module'];
+
       $storage_args = array();
-      if (array_key_exists('base_chado_table', $form_state['values'])) {
-        $storage_args['data_table'] = $form_state['values']['base_chado_table'];
-      }
-      if (array_key_exists('chado_type_use_linker', $form_state['values']) and
-          $form_state['values']['chado_type_use_linker'] == 'Yes') {
-        $storage_args['type_linker_table'] = $form_state['values']['base_chado_table'] . '_cvterm';
-        $storage_args['type_column'] = 'cvterm_id';
-      }
-      if (array_key_exists('chado_table_has_type', $form_state['values']) and
-          $form_state['values']['chado_table_has_type'] == 'Yes') {
-        $storage_args['type_column'] = 'type_id';
-      }
-      if (array_key_exists('type_column', $form_state['values']) and
-          $form_state['values']['type_column']) {
-        $storage_args['type_column'] = $form_state['values']['type_column'];
+      $function = $selected_store_module . '_field_storage_bundle_mapping_form_submit';
+      if (function_exists($function)) {
+        $function($form, $form_state, $term, $storage_args);
       }
 
-      $storage_args['type_id'] = $form_state['values']['selected_cvterm_id'];
       $args = array(
         'vocabulary' => $vocabulary,
         'accession' => $accession,
         'term_name' => $term_name,
         'storage_args' => $storage_args,
       );
+
       $bundle = tripal_create_bundle($args, $error);
       if (!$bundle) {
         drupal_set_message($error, 'error');
@@ -945,10 +682,6 @@ function tripal_admin_add_type_form_submit($form, &$form_state) {
         tripal_admin_access($bundle);
         $form_state['redirect'] = "admin/structure/bio_data";
       }
-
-      // TODO: move these Chado specific settings out.
-
-
     }
     else {
       drupal_set_message("The term '$accession' already exists as a content type.", 'warning');

+ 0 - 16
tripal/includes/TripalFields/TripalField.inc

@@ -111,25 +111,9 @@ class TripalField {
 
     $class = get_called_class();
 
-    // Make sure the term exist.
     if (!$instance) {
       tripal_set_message(t('Missing instance of field "%field"', array('%field' => $field['field_name'])), TRIPAL_ERROR);
     }
-    else {
-      // If the vocabulary and accession are set then make sure that the
-      // term is a real term. It is possible that the vocabulary and accession
-      // may not be set initially. This occurs when a field is created
-      // dynamically be a priviledge site admin.
-      if (array_key_exists('term_vocabulary', $instance['settings'])) {
-        $vocabulary = $instance['settings']['term_vocabulary'];
-        $accession = $instance['settings']['term_accession'];
-        $term = tripal_get_term_details($vocabulary, $accession);
-        if (!$term) {
-          throw new Error(t('Cannot create TripalField of type "%term" as that
-              term does not exist.', array('%term' => "$vocabulary:$accession")));
-        }
-      }
-    }
   }
 
   // --------------------------------------------------------------------------

+ 1 - 1
tripal/includes/tripal.fields.inc

@@ -358,7 +358,7 @@ function tripal_form_field_ui_field_overview_form_submit($form, &$form_state) {
         // Unset the the _add_new_field entry so Drupal doesn't try to
         // Create the field.
         unset($form_state['values']['fields']['_add_new_field']);
-        drupal_set_message('Please set the controlled vocabulary that best describes the data of this field. See the "Controlled Vocabulary Term" section below.', 'notice');
+        drupal_set_message('Please set the controlled vocabulary that best describes the data of this field. See the "Controlled Vocabulary Term" section below.', 'warning');
       }
     }
     catch (Exception $e) {

+ 2 - 13
tripal/tripal.module

@@ -109,17 +109,6 @@ function tripal_menu() {
     'access arguments' => array('administer tripal'),
   );
 
-  $items['admin/tripal/terms'] = array(
-    'title' => 'Vocabularies',
-    'description' => t("Vocabulary terms are essential to creating content
-        in Tripal. This allows data to be shared more easily with others
-        using technologies such as the semantic web and web services.
-        Before creating content you must have loaded vocabularies and their
-        terms."),
-    'weight' => 8,
-    'access arguments' => array('administer tripal'),
-  );
-
   $items['admin/tripal/dashboard'] = array(
     'title' => 'Dashboard',
     'description' => t("A dashboard view of Tripal including new fields for entities."),
@@ -131,8 +120,8 @@ function tripal_menu() {
     'file path' => drupal_get_path('module', 'tripal'),
   );
 
-  $items['admin/tripal/terms/import'] = array(
-    'title' => 'Import Vocabulary',
+  $items['admin/tripal/loaders/obo_loader'] = array(
+    'title' => 'OBO Controlled Vocabulary Loader',
     'description' => t("Import vocabularies and terms in OBO format."),
     'access arguments' => array('administer tripal'),
     'page callback' => 'drupal_get_form',

+ 19 - 12
tripal_chado/api/tripal_chado.api.inc

@@ -59,6 +59,7 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   $type_column = $chado_bundle->type_column;
   $type_linker_table = $chado_bundle->type_linker_table;
   $cvterm_id  = $chado_bundle->type_id;
+  $type_value = $chado_bundle->type_value;
 
   // Get the table information for the Chado table.
   $table_schema = chado_get_schema($table);
@@ -66,7 +67,7 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
 
   // Construct the SQL for identifying which records should be published.
   $args = array();
-  $select = "SELECT $pkey_field as record_id ";
+  $select = "SELECT T.$pkey_field as record_id ";
   $from = "
     FROM {" . $table . "} T
       LEFT JOIN public.$chado_entity_table CE on CE.record_id = T.$pkey_field
@@ -80,9 +81,8 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   }
   $where = " WHERE CE.record_id IS NULL ";
 
-  // Handle bundles that use a linker property table for identifying the type
-  // of record to publish.
-  if ($type_linker_table and $type_column) {
+  // Handle records that are mapped to property tables.
+  if ($type_linker_table and $type_column and $type_value) {
     $propschema = chado_get_schema($type_linker_table);
     $fkeys = $propschema['foreign keys'][$table]['columns'];
     foreach ($fkeys as $leftkey => $rightkey) {
@@ -90,22 +90,29 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
         $from .= " INNER JOIN {" . $type_linker_table . "} LT ON T.$pkey_field = LT.$leftkey ";
       }
     }
+    $where .= "AND LT.$type_column = :cvterm_id and LT.value = :prop_value";
+    $args[':cvterm_id'] = $cvterm_id;
+    $args[':prop_value'] = $type_value;
+  }
+
+  // Handle records that are mapped to cvterm linking tables.
+  if ($type_linker_table and $type_column and !$type_value) {
+    $cvtschema = chado_get_schema($type_linker_table);
+    $fkeys = $cvtschema['foreign keys'][$table]['columns'];
+    foreach ($fkeys as $leftkey => $rightkey) {
+      if ($rightkey == $pkey_field) {
+        $from .= " INNER JOIN {" . $type_linker_table . "} LT ON T.$pkey_field = LT.$leftkey ";
+      }
+    }
     $where .= "AND LT.$type_column = :cvterm_id";
     $args[':cvterm_id'] = $cvterm_id;
   }
 
-  // If the type column is in the base table then add in the SQL for that.
+  // Handle records that are mapped via a type_id column in the base table.
   if (!$type_linker_table and $type_column) {
     $where .= "AND T.$type_column = :cvterm_id";
     $args[':cvterm_id'] = $cvterm_id;
   }
-  // If no type column is specified then we have a problem.
-  if ($type_linker_table and !$type_column) {
-    tripal_report_error('tripal_chado', TRIPAL_ERROR,
-        "Could not publish record: @error",
-        array('@error' => 'The bundle does not properly map to Chado.'));
-    return FALSE;
-  }
 
   // Now add in any additional filters
   $fields = field_info_field_map();

+ 25 - 0
tripal_chado/api/tripal_chado.property.api.inc

@@ -627,3 +627,28 @@ function chado_get_record_with_property($record, $property, $options = array())
 
   return $records;
 }
+
+
+/**
+ * Retrieves all of the property types currently availalbe in a prop table.
+ *
+ * @param $prop_table
+ *   The name of the property table.
+ * @throws Exception
+ * @return
+ *   An array of cvterm objects as created by chado_generate_var().
+ */
+function chado_get_table_property_types($prop_table) {
+
+  // Make sure this is a prop table.
+  if (!preg_match('/prop$/', $prop_table)) {
+    throw new Exception('Please provide a valid Chado property table');
+  }
+  $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
+  $results = chado_query($sql);
+  $types = array();
+  foreach ($results as $result) {
+    $types[] = chado_generate_var('cvterm', array('cvterm_id' => $result->type_id));
+  }
+  return $types;
+}

+ 1 - 1
tripal_chado/api/tripal_chado.query.api.inc

@@ -1608,7 +1608,7 @@ function chado_select_record_check_value_type(&$op, &$value, $type) {
  *          WHERE
  *            F.uniquename = :feature_uniquename";
  * $args = array( ':feature_uniquename' => $form_state['values']['uniquename'] );
- * $result = chado_query( $sql, $args );
+ * $result = chado_query($sql, $args);
  * foreach ($result as $r) { [Do something with the records here] }
  * @endcode
  *

+ 1 - 1
tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc

@@ -106,7 +106,7 @@ class data__accession_widget extends ChadoFieldWidget {
     );
     $widget['links'] = array(
       '#type' => 'item',
-      '#markup' => l('Add a new database', 'admin/tripal/storage/chado/db/add', array('attributes' => array('target' => '_blank')))
+      '#markup' => l('Add a new database', 'admin/tripal/loaders/chado_db/add', array('attributes' => array('target' => '_blank')))
     );
   }
 

+ 1 - 1
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc

@@ -136,7 +136,7 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
     if (!$db_id) {
       $widget['links'] = array(
         '#type' => 'item',
-        '#markup' => l('Add a database', 'admin/tripal/storage/chado/db/add', array('attributes' => array('target' => '_blank')))
+        '#markup' => l('Add a database', 'admin/tripal/loaders/chado_db/add', array('attributes' => array('target' => '_blank')))
       );
     }
   }

+ 1 - 0
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -1,6 +1,7 @@
 <?php
 
 class sbo__relationship_formatter extends ChadoFieldFormatter {
+
   // The default lable for this field.
   public static $default_label = 'Relationship';
 

+ 3 - 0
tripal_chado/includes/tripal_chado.bundle.inc

@@ -53,6 +53,9 @@ function tripal_chado_bundle_create($bundle, $storage_args) {
     if (array_key_exists('type_column', $storage_args)) {
       $record['type_column'] = $storage_args['type_column'];
     }
+    if (array_key_exists('type_value', $storage_args)) {
+      $record['type_value'] = $storage_args['type_value'];
+    }
     $success = drupal_write_record('chado_bundle', $record);
     if (!$success) {
       throw new Exception('Cannot create content type. Problem associating type with Chado.');

+ 767 - 0
tripal_chado/includes/tripal_chado.cv.inc

@@ -0,0 +1,767 @@
+<?php
+/**
+ * Provide landing page to the new admin pages
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_admin_cv_listing() {
+  $output = '';
+
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Chado Modules', 'admin/tripal/legacy');
+  $breadcrumb[] = l('Vocabularies', 'admin/tripal/legacy/vocab');
+  drupal_set_breadcrumb($breadcrumb);
+
+  // Add the view
+  $cvs_view = views_embed_view('tripal_cv_admin_cvs','default');
+  $cvterms_view = views_embed_view('tripal_cv_admin_cvterms','default');
+  if (isset($cvs_view) && isset($cvterms_view)) {
+    $output .= $cvs_view;
+  }
+  else {
+    $output .= '<p>The Tripal Controlled Vocabulary module uses primarily views to provide an '
+        . 'administrative interface. Currently one or more views needed for this '
+            . 'administrative interface are disabled. <strong>Click each of the following links to '
+                . 'enable the pertinent views</strong>:</p>';
+    $output .= '<ul>';
+    if (!isset($cvs_view)) {
+      $output .= '<li>'.l('Tripal Vocabularies', 'admin/tripal/vocab/views/cvs/enable').'</li>';
+    }
+    if (!isset($cvterm_view)) {
+      $output .= '<li>'.l('Tripal Vocabulary Terms', 'admin/tripal/vocab/views/cvterms/enable').'</li>';
+    }
+    $output .= '</ul>';
+  }
+
+  return $output;
+}
+
+/**
+ * Provides the actual "Select CV" form on the Update/Delete Controlled
+ *   Vocabulary page. This form also triggers the edit javascript
+ * @todo Modify this form to use Drupal AJAX
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cv_edit_form($form, &$form_state) {
+
+  // get the cv_d if form was submitted via AJAX
+  $cv_id = 0;
+  if (array_key_exists('values', $form_state)) {
+    $cv_id = $form_state['values']['cv_id'];
+  }
+  elseif (isset($form_state['build_info']['args'][0])) {
+    $cv_id = $form_state['build_info']['args'][0];
+  }
+
+  // get a list of db from chado for user to choose
+  $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
+  $results = chado_query($sql);
+
+  $cvs = array();
+  $cvs[] = 'Select a vocabulary';
+  foreach ($results as $cv) {
+    $cvs[$cv->cv_id] = $cv->name;
+  }
+
+  $form['cv_id'] = array(
+    '#title' => t('Controlled Vocabulary Name'),
+    '#type' => 'select',
+    '#options' => $cvs,
+    '#ajax' => array(
+      'callback' => 'tripal_cv_edit_form_ajax',
+      'wrapper'  => 'cv-edit-div',
+      'effect'   => 'fade',
+      'event'    => 'change',
+      'method'   => 'replace',
+    ),
+    '#default_value' => $cv_id,
+  );
+
+
+  // if we don't have a db_id then we can  return the form, otherwise
+  // add in the other fields
+  if ($cv_id) {
+    tripal_cv_add_cv_form_fields($form, $form_state, $cv_id);
+
+    $form['update'] = array(
+      '#type'         => 'submit',
+      '#value'        => t('Update'),
+    );
+    $form['delete'] = array(
+      '#type'         => 'submit',
+      '#value'        => t('Delete'),
+      '#attributes'   => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),
+    );
+  }
+  else {
+    // if we don't have a dbid then this is the first time the form has
+    // benn loaded and we need to create the div where ajax replacement elements get stored
+    $form['div_replace'] = array(
+      '#type' => 'item',
+      '#prefix' => '<div id="cv-edit-div">',
+      '#suffix' => '</div>',
+    );
+  }
+  return $form;
+}
+
+/**
+ * Form to add contolled vocabularies
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cv_add_form($form, &$form_state) {
+
+  // add in the form fields to this form
+  tripal_cv_add_cv_form_fields($form, $form_state);
+
+  $form['add'] = array(
+    '#type'         => 'submit',
+    '#value'        => t('Add'),
+    '#weight'       => 5,
+  );
+  return $form;
+}
+
+/**
+ * Form fields in common between the cv add & edit form.
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_add_cv_form_fields(&$form, $form_state, $cv_id = NULL) {
+
+  $default_name = '';
+  $default_desc = '';
+
+  if ($cv_id) {
+    $values = array('cv_id' => $cv_id);
+    $result = chado_select_record('cv', array('*'), $values);
+    $cv = $result[0];
+    $default_name = $cv->name;
+    $default_desc = $cv->definition;
+  }
+
+  // add a fieldset for the Drupal Schema API
+  $form = array(
+    '#type' => 'fieldset',
+    '#title' => 'Controlled Vocabulary Details',
+    '#collapsible' => 0,
+  );
+
+  $form['name']= array(
+    '#type'          => 'textfield',
+    '#title'         => t("Controlled Vocabulary name"),
+    '#description'   => t('Please enter the name for this vocabulary.'),
+    '#required'      => TRUE,
+    '#default_value' => $default_name,
+    '#maxlength'     => 255,
+  );
+
+  $form['definition']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Description'),
+    '#description'   => t('Please enter a definition for this vocabulary'),
+    '#default_value' => $default_desc,
+  );
+
+  return $form;
+}
+
+/**
+ * Validation fucntion for tripal_cv_cv_add_form
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cv_add_form_validate($form, &$form_state) {
+  tripal_cv_form_fields_validate($form, $form_state);
+}
+
+/**
+ * Validation fucntion for tripal_cv_cv_edit_form
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cv_edit_form_validate($form, &$form_state) {
+  tripal_cv_form_fields_validate($form, $form_state);
+}
+
+/**
+ * Generic validation form for shared fields of both the edit and add forms
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_form_fields_validate($form, &$form_state) {
+  $name =  array_key_exists('name', $form_state['values'])       ? trim($form_state['values']['name']) : '';
+  $desc =  array_key_exists('definition', $form_state['values']) ? trim($form_state['values']['definition']) : '';
+  $cv_id = array_key_exists('cv_id', $form_state['values'])      ? trim($form_state['values']['cv_id']) : '';
+
+
+  // make sure the cv name is unique
+  $values = array('name' => $name);
+  $results = chado_select_record('cv', array('cv_id'), $values);
+  if (count($results) > 0 and $results[0]->cv_id != $cv_id) {
+    form_set_error('name', 'The vocabulary name must be unique');
+  }
+}
+
+/**
+ * Submit cv add form
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cv_add_form_submit($form, &$form_state) {
+
+  $name =  array_key_exists('name', $form_state['values'])       ? trim($form_state['values']['name']) : '';
+  $desc =  array_key_exists('definition', $form_state['values']) ? trim($form_state['values']['definition']) : '';
+
+  $values = array(
+    'name' => $name,
+    'definition' => $desc,
+  );
+  $success = chado_insert_record('cv', $values);
+  if ($success) {
+    drupal_set_message(t("Controlled vocabulary added"));
+  }
+  else {
+    drupal_set_message(t("Failed to add controlled vocabulary."));
+  }
+}
+
+/**
+ * Submit cv edit form
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cv_edit_form_submit($form, &$form_state) {
+  $name  = array_key_exists('name', $form_state['values'])       ? trim($form_state['values']['name']) : '';
+  $desc  = array_key_exists('definition', $form_state['values']) ? trim($form_state['values']['definition']) : '';
+  $cv_id = array_key_exists('cv_id', $form_state['values'])      ? trim($form_state['values']['cv_id']) : '';
+  $op    = array_key_exists('op', $form_state['values'])         ? trim($form_state['values']['op']) : '';
+
+  $values = array(
+    'name' => $name,
+    'definition' => $desc,
+  );
+  if (strcmp($op, 'Update')==0) {
+    $match = array('cv_id' => $cv_id);
+    $success = chado_update_record('cv', $match, $values);
+    if ($success) {
+      drupal_set_message(t("Controlled vocabulary updated"));
+    }
+    else {
+      drupal_set_message(t("Failed to update controlled vocabulary."));
+    }
+  }
+  if (strcmp($op, 'Delete')==0) {
+    $match = array('cv_id' => $cv_id);
+    $success = chado_delete_record('cv', $match);
+    if ($success) {
+      drupal_set_message(t("Controlled vocabulary deleted"));
+    }
+    else {
+      drupal_set_message(t("Failed to delete controlled vocabulary."));
+    }
+  }
+}
+
+/**
+ * Ajax callback for the tripal_cv_form
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_edit_form_ajax($form, $form_state) {
+
+  $elements = array();
+
+  // add in the form fields and the buttons
+  if (array_key_exists('cv_id', $form_state['values'])) {
+    $elements['fields'] = $form;
+    $elements['update'] = $form['update'];
+    $elements['delete'] = $form['delete'];
+  }
+
+  // add back in the cv-edit-div that is used for the next round of AJAX
+  $elements['fields']['#prefix'] =  '<div id="cv-edit-div">';
+  $elements['fields']['#suffix'] =  '</div">';
+
+  // reset the values for the fields to the defaults
+  $elements['fields']['name']['#value']        = $elements['fields']['name']['#default_value'];
+  $elements['fields']['definition']['#value']  = $elements['fields']['definition']['#default_value'];
+
+  //drupal_set_message('<pre>' . print_r($elements, TRUE) . '</pre>', "status");
+
+  return $elements;
+}
+
+/**
+ * Form for editing cvterms
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cvterm_edit_form($form, &$form_state) {
+
+  $step = 0;
+  if (empty($form_state['storage']['step'])) {
+    $form_state['storage']['step'] = 0;
+  }
+  else {
+    $step = $form_state['storage']['step'];
+  }
+
+  $cv_id = 0;
+  if ($step == 1) {
+    $cv_id = $form_state['storage']['cv_id'];
+    $cvterm_name = $form_state['storage']['name'];
+    $cvterm_id = $form_state['storage']['cvterm_id'];
+  }
+  // get the cv if form was submitted via AJAX
+  $cvterm = '';
+  if (array_key_exists('values', $form_state)) {
+    $cv_id = $form_state['values']['cv_id'];
+    if (array_key_exists('cvterm', $form_state['values'])) {
+      $cvterm = $form_state['values']['cvterm'];
+    }
+  }
+  elseif (isset($form_state['build_info']['args'][0])) {
+    $cv_id = $form_state['build_info']['args'][0];
+    $cvterm_id = $form_state['build_info']['args'][1];
+    if ($form_state['build_info']['args'][1]) {
+      $result = db_select('chado.cvterm','c')
+      ->fields('c', array('name'))
+      ->condition('c.cvterm_id',$cvterm_id)
+      ->execute();
+      $cvterm_name = $result->fetchObject()->name;
+      $step = 1;
+    }
+  }
+
+  // get a list of CVs
+  $cvs = array();
+  $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
+  $results = chado_query($sql);
+  $cvs[] = 'Select a vocabulary';
+  foreach ($results as $cv) {
+    $cvs[$cv->cv_id] = $cv->name;
+  }
+  $form['cv_id'] = array(
+    '#title' => t('Controlled Vocabulary Name'),
+    '#type' => 'select',
+    '#options' => $cvs,
+    '#required' => TRUE,
+    '#default_value' => $cv_id,
+    '#ajax' => array(
+      'callback'    => 'tripal_cv_cvterm_edit_form_ajax',
+      'wrapper' => 'cvterm-edit-div',
+      'event'   => 'change',
+      'method'  => 'replace',
+      'event'    => 'change',
+    ),
+  );
+
+  if ($cv_id and $step == 0) {
+
+    $form['name']= array(
+      '#type'          => 'textfield',
+      '#title'         => t("Term Name"),
+      '#default_value' => $cvterm,
+      '#required'      => TRUE,
+      '#autocomplete_path' => "admin/tripal/tripal_cv/cvterm/auto_name/$cv_id",
+      '#description'   => t('Enter the term to edit.')
+    );
+    $form['continue']= array(
+      '#type'          => 'submit',
+      '#value'         => 'continue',
+    );
+  }
+  elseif ($step == 1) {
+
+    tripal_cv_add_cvterm_form_fields($form, $form_state, $cv_id, $cvterm_name);
+
+    // when editing there are certain fields the user should not change for a term
+    // let's mark those as disabled
+    $form['cv_id']['#disabled'] = TRUE;
+    $form['db_id']['#disabled'] = TRUE;
+    $form['accession']['#disabled'] = TRUE;
+
+    // add in the div for replacing the fields if needed
+    $form['#prefix'] = '<div id="cvterm-edit-div">';
+    $form['#suffix'] = '</div>';
+
+    // add in the cvterm id
+    $form['cvterm_id'] = array(
+      '#type' => 'hidden',
+      '#value' =>  $cvterm_id,
+    );
+
+    $form['update'] = array(
+      '#type'         => 'submit',
+      '#value'        => t('Update'),
+    );
+    $form['delete'] = array(
+      '#type'         => 'submit',
+      '#value'        => t('Delete'),
+      '#attributes'   => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),
+    );
+  }
+
+  if ($step == 0) {
+    // if we don't have a cv_id then this is the first time the form has
+    // benn loaded and we need to create the div where ajax replacement elements get stored
+    $form['div_replace'] = array(
+      '#type' => 'item',
+      '#prefix' => '<div id="cvterm-edit-div">',
+      '#suffix' => '</div>',
+    );
+  }
+  return $form;
+}
+
+/**
+ * Form for adding cvterms
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cvterm_add_form($form, &$form_state) {
+  $cv_id = 0;
+  if (array_key_exists('values', $form_state)) {
+    $cv_id = $form_state['values']['cv_id'];
+  }
+  elseif (isset($form_state['build_info']['args'][0])) {
+    $cv_id = $form_state['build_info']['args'][0];
+  }
+
+  // get a list of CVs
+  $cvs = array();
+  $sql = "SELECT * FROM {cv} WHERE NOT name = 'tripal' ORDER BY name ";
+  $results = chado_query($sql);
+  $cvs[] = 'Select a vocabulary';
+  foreach ($results as $cv) {
+    $cvs[$cv->cv_id] = $cv->name;
+  }
+  $form['cv_id'] = array(
+    '#title' => t('Controlled Vocabulary (Ontology) Name'),
+    '#type' => 'select',
+    '#options' => $cvs,
+    '#required' => TRUE,
+    '#default_value' => $cv_id,
+  );
+  tripal_cv_add_cvterm_form_fields($form, $form_state);
+
+  $form['add'] = array(
+    '#type'         => 'submit',
+    '#value'        => t('Add Term'),
+  );
+
+  return $form;
+}
+
+/**
+ * Form fields in common between add/edit forms
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_add_cvterm_form_fields(&$form, $form_state, $cv_id = 0, $cvterm_name = '') {
+
+  $name = '';
+  $definition = '';
+  $is_relationship = '';
+  $is_obsolete = '';
+  $db_id = '';
+  $accession = '';
+  $cvterm = NULL;
+
+  // get default values
+  if ($cvterm_name) {
+    $values = array('cv_id' => $cv_id, 'name' => $cvterm_name);
+    $cvterm = chado_generate_var('cvterm', $values);
+    $name = $cvterm->name;
+    $definition = $cvterm->definition;
+    $is_relationship = $cvterm->is_relationshiptype;
+    $is_obsolete = $cvterm->is_obsolete;
+    $db_id = $cvterm->dbxref_id->db_id->db_id;
+    $accession = $cvterm->dbxref_id->accession;
+  }
+
+  $form['name']= array(
+    '#type'          => 'textfield',
+    '#title'         => t("Term Name"),
+    '#default_value' => $name,
+    '#description'   => t('The term must be unique within the database selected below.'),
+    '#required'      => TRUE,
+  );
+
+  $form['internal_id']= array(
+    '#type'          => 'item',
+    '#title'         => t("Internal ID"),
+    '#markup'        => $cvterm ? $cvterm->cvterm_id : '',
+  );
+
+  $form['definition']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Description'),
+    '#description'   => t('Please enter a description for this term'),
+    '#default_value' => $definition,
+  );
+
+  $form['is_relationship'] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('This term describes a relationship?'),
+    '#default_value' => $is_relationship,
+  );
+
+  $form['is_obsolete'] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('This term is obsolete?'),
+    '#default_value' => $is_obsolete,
+  );
+
+  $values = array();
+  $columns = array('db_id', 'name');
+  $options = array('order_by' => array('name' => 'ASC'));
+  $results = chado_select_record('db', $columns, $values, $options);
+  $dbs = array();
+  $dbs[] = '';
+  foreach ($results as $db) {
+    $dbs[$db->db_id] = $db->name;
+  }
+  $form['db_id'] = array(
+    '#type'         => 'select',
+    '#title'         => t('Database'),
+    '#description'   => t('All terms must be assocated with a database. If there is no database for this term (e.g. it is a custom term specific to this site) then select the database \'null\' or consider creating a database specific for your site and use that anytime you would like to add terms.'),
+    '#options'      => $dbs,
+    '#default_value' => $db_id,
+    '#required' => TRUE,
+  );
+
+  $form['accession']= array(
+    '#type'          => 'textfield',
+    '#title'         => t("Accession"),
+    '#description'   => t('If this term has an existing accession (unique identifier) in the database
+       please enter that here.  If the accession is numeric with a database prefix (e.g. GO:003023), please
+       enter just the numeric value.  The database prefix will be appended whenever the term is displayed.
+       If you do not have a numeric value consider entering the term name as the accession.'),
+    '#required'      => TRUE,
+    '#default_value' => $accession,
+  );
+}
+
+/**
+ * Validate cvterm edit form
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cvterm_edit_form_validate($form, &$form_state) {
+  $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
+  $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
+  $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
+  $cvterm_id = array_key_exists('cvterm_id', $form_state['values']) ? $form_state['values']['cvterm_id'] : '';
+  $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';
+
+  $step = $form_state['storage']['step'];
+
+  // make sure the cv term name is unique for this vocabulary
+  if ($step == 1) {
+    $values = array('name' => $name, 'cv_id' => $cv_id);
+    $results = chado_select_record('cvterm', array('cvterm_id'), $values);
+    foreach ($results as $r) {
+      if ($r->cvterm_id != $cvterm_id) {
+        form_set_error('name', 'The term name must be unique for this vocabulary. Another term with this name already exists.');
+      }
+    }
+  }
+}
+
+/**
+ * Validate cv add form
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cvterm_add_form_validate($form, &$form_state) {
+  $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
+  $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
+  $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
+  $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';
+
+  $values = array('cv_id' => $cv_id);
+  $results = chado_select_record('cv', array('name'), $values);
+  if (!$results or count($results) == 0) {
+    form_set_error('cv_id', 'The controlled vocabulary does not exist');
+  }
+
+  // make sure the DB exists
+  $values = array('db_id' => $db_id);
+  $results = chado_select_record('db', array('name'), $values);
+  if (!$results or count($results) == 0) {
+    form_set_error('db_id', 'The database name does not exist');
+  }
+
+  // make sure the cv term name is unique for this vocabulary
+  $values = array('name' => $name, 'cv_id' => $cv_id);
+  $results = chado_select_record('cvterm', array('cvterm_id'), $values);
+  if (count($results) > 0) {
+    form_set_error('name', 'The term name must be unique for this vocabulary. Another term with this name already exists.');
+  }
+
+  // make sure this accession is unique for the database
+  $values = array('accession' => $accession, 'db_id' => $db_id);
+  $results = chado_select_record('dbxref', array('dbxref_id'), $values);
+  if (count($results) > 0 ) {
+    form_set_error('accession', 'The accession is not uniuqe for this vocabulary\'s database.');
+  }
+
+}
+
+/**
+ * Edits existing controlled vocabulary terms
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cvterm_edit_form_submit($form, &$form_state) {
+
+  $cv_id           = array_key_exists('cv_id', $form_state['values'])           ? trim($form_state['values']['cv_id']) : '';
+  $name            = array_key_exists('name', $form_state['values'])            ? trim($form_state['values']['name']) : '';
+  $definition      = array_key_exists('definition', $form_state['values'])      ? trim($form_state['values']['definition']) : '';
+  $is_relationship = array_key_exists('is_relationship', $form_state['values']) ? trim($form_state['values']['is_relationship']) : '';
+  $is_obsolete     = array_key_exists('is_obsolete', $form_state['values'])     ? trim($form_state['values']['is_obsolete']) : '';
+  $cvterm_id       = array_key_exists('cvterm_id', $form_state['values'])       ? trim($form_state['values']['cvterm_id']) : '';
+  $db_id           = array_key_exists('db_id', $form_state['values'])           ? trim($form_state['values']['db_id']) : '';
+  $accession       = array_key_exists('accession', $form_state['values'])       ? trim($form_state['values']['accession']) : '';
+  $op              = array_key_exists('op', $form_state['values'])              ? trim($form_state['values']['op']) : '';
+
+
+  $step = $form_state['storage']['step'];
+
+  switch ($step) {
+    case 0:  // a cvterm name has been selected
+      $cv_id = array_key_exists('cv_id', $form_state['values']) ? trim($form_state['values']['cv_id']) : '';
+      $name  = array_key_exists('name', $form_state['values'])  ? trim($form_state['values']['name'])  : '';
+
+      // get the original cvterm_id
+      $values = array('name' => $name, 'cv_id' => $cv_id);
+      $results = chado_select_record('cvterm', array('cvterm_id'), $values);
+      $cvterm = $results[0];
+
+      $form_state['storage']['cv_id'] = $cv_id;
+      $form_state['storage']['name'] = $name;
+      $form_state['storage']['step'] = 1;
+      $form_state['storage']['cvterm_id'] = $cvterm->cvterm_id;
+      $form_state['rebuild'] = TRUE;
+      break;
+
+    case 1:  // update/delete button has been clicked
+
+      if ($op == 'Update') {
+        // get the cv
+        $values = array('cv_id' => $cv_id);
+        $results = chado_select_record('cv', array('name'), $values);
+        $cv = $results[0];
+
+        // get the db
+        $values = array('db_id' => $db_id);
+        $results = chado_select_record('db', array('name'), $values);
+        $db = $results[0];
+
+        // now add the term
+        $term = array(
+          'name' => $name,
+          'namespace' => $cv->name,
+          'id' => $accession,
+          'definition' => $definition,
+          'is_obsolete' => $is_obsolete,
+          'cv_name' => $cv->name,
+          'is_relationship' => $is_relationship,
+          'db_name' => $db_name
+        );
+
+        $cvterm = tripal_insert_cvterm($term, array('update_existing' => TRUE));
+        if ($cvterm) {
+          drupal_set_message('Term updated successfully.');
+        }
+        else {
+          drupal_set_message('Could not add term. Check Drupal recent logs for error messages.', 'error');
+        }
+      }
+      if ($op == 'Delete') {
+        $values = array('cvterm_id' => $cvterm_id);
+        $success = chado_delete_record('cvterm', $values);
+        if ($success) {
+          drupal_set_message('Term deleted successfully.');
+        }
+        else {
+          drupal_set_message('Could not delete term term. Check Drupal recent logs for error messages.', 'error');
+        }
+      }
+      break;
+  }
+}
+
+/**
+ * Adds new terms to an existing cv
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cvterm_add_form_submit($form, &$form_state) {
+  $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : '';
+  $name = array_key_exists('name', $form_state['values']) ? $form_state['values']['name'] : '';
+  $definition = array_key_exists('definition', $form_state['values']) ? $form_state['values']['definition'] : '';
+  $is_relationship = array_key_exists('is_relationship', $form_state['values']) ? $form_state['values']['is_relationship'] : '';
+  $is_obsolete = array_key_exists('is_obsolete', $form_state['values']) ? $form_state['values']['is_obsolete'] : '';
+
+  $db_id = array_key_exists('db_id', $form_state['values']) ? $form_state['values']['db_id'] : '';
+  $accession = array_key_exists('accession', $form_state['values']) ? $form_state['values']['accession'] : '';
+
+  // get the database
+  $values = array('db_id' => $db_id);
+  $results = chado_select_record('db', array('name'), $values);
+  $db = $results[0];
+
+  // get the cv
+  $values = array('cv_id' => $cv_id);
+  $results = chado_select_record('cv', array('name'), $values);
+  $cv = $results[0];
+
+  // now add the term
+  $term = array(
+    'name' => $name,
+    'namespace' => $cv->name,
+    'id' => $accession,
+    'definition' => $definition,
+    'is_obsolete' => $is_obsolete,
+    'cv_name' => $cv->name,
+    'is_relationship' => $is_relationship,
+    'db_name' => $db->name
+  );
+
+  $cvterm = tripal_insert_cvterm($term, array('update_existing' => TRUE));
+  if ($cvterm) {
+    drupal_set_message('Term added successfully.');
+  }
+  else {
+    drupal_set_message('Could not add term. Check Drupal recent logs for error messages.', 'error');
+  }
+}
+
+/**
+ * Ajax callback for the tripal_cv_form
+ *
+ * @ingroup tripal_cv
+ */
+function tripal_cv_cvterm_edit_form_ajax($form, $form_state) {
+
+  $elements = array();
+
+  $elements['name'] = $form['name'];
+  $elements['continue'] = $form['continue'];
+
+  // add back in the cv-edit-div that is used for the next round of AJAX
+  $elements['name']['#prefix'] =  '<div id="cvterm-edit-div">';
+  $elements['name']['#suffix'] =  '</div">';
+
+
+  return $elements;
+}

+ 6 - 6
tripal_chado/includes/tripal_chado.db.inc

@@ -15,7 +15,7 @@ function tripal_chado_admin_db_listing() {
   $breadcrumb[] = l('Tripal', 'admin/tripal');
   $breadcrumb[] = l('Data Storage', 'admin/tripal/storage');
   $breadcrumb[] = l('Chado', 'admin/tripal/storage/chado');
-  $breadcrumb[] = l('Databases', 'admin/tripal/storage/chado/db');
+  $breadcrumb[] = l('Databases', 'admin/tripal/loaders/chado_db');
   drupal_set_breadcrumb($breadcrumb);
 
   // Add the view
@@ -31,10 +31,10 @@ function tripal_chado_admin_db_listing() {
                 . 'enable the pertinent views</strong>:</p>';
     $output .= '<ul>';
     if (!isset($dbs_view)) {
-      $output .= '<li>'.l('DB Admin', 'admin/tripal/storage/chado/db/views/dbs/enable').'</li>';
+      $output .= '<li>'.l('DB Admin', 'admin/tripal/loaders/chado_db/views/dbs/enable').'</li>';
     }
     if (!isset($dbxrefs_view)) {
-      $output .= '<li>'.l('DB Reference Admin', 'admin/tripal/storage/chado/db/views/dbxrefs/enable').'</li>';
+      $output .= '<li>'.l('DB Reference Admin', 'admin/tripal/loaders/chado_db/views/dbxrefs/enable').'</li>';
     }
     $output .= '</ul>';
   }
@@ -262,7 +262,7 @@ function tripal_chado_db_add_form_submit($form, &$form_state) {
   $success = chado_insert_record('db', $values);
   if ($success) {
     drupal_set_message(t("External database added"));
-    drupal_goto('admin/tripal/storage/chado/db');
+    drupal_goto('admin/tripal/loaders/chado_db');
   }
   else {
     drupal_set_message(t("Failed to add external database."));
@@ -294,7 +294,7 @@ function tripal_chado_db_edit_form_submit($form, &$form_state) {
     $success = chado_update_record('db', $match, $values);
     if ($success) {
       drupal_set_message(t("External database updated"));
-      drupal_goto('admin/tripal/storage/chado/db');
+      drupal_goto('admin/tripal/loaders/chado_db');
     }
     else {
       drupal_set_message(t("Failed to update external database."));
@@ -305,7 +305,7 @@ function tripal_chado_db_edit_form_submit($form, &$form_state) {
     $success = chado_delete_record('db', $match);
     if ($success) {
       drupal_set_message(t("External database deleted"));
-      drupal_goto('admin/tripal/storage/chado/db');
+      drupal_goto('admin/tripal/loaders/chado_db');
     }
     else {
       drupal_set_message(t("Failed to delete external database."));

+ 1 - 0
tripal_chado/includes/tripal_chado.entity.inc

@@ -62,6 +62,7 @@ function tripal_chado_entity_load($entities, $type) {
           $bundle->type_linker_table = $chado_bundle->type_linker_table;
           $bundle->type_column = $chado_bundle->type_column;
           $bundle->type_id = $chado_bundle->type_id;
+          $bundle->type_value = $chado_bundle->type_value;
         }
       }
     }

+ 522 - 0
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -621,3 +621,525 @@ function tripal_chado_field_storage_query($query) {
   }
   return $result;
 }
+
+
+/**
+ * Implements hook_field_storage_bundle_mapping_form().
+ *
+ * This is a Tripal added hook to the field storage API.
+ */
+function tripal_chado_field_storage_bundle_mapping_form($form, &$form_state,
+    $term, &$submit_disabled) {
+
+  $selected_term_id = $term->cvterm_id;
+
+  // Initialize the form.
+  $form = array();
+
+  // Get the form default values.
+  $default = array(
+    'table' => '',
+    'has_all' => 'No',
+    'use_linker' => 'Yes',
+    'use_prop' => 'Yes',
+    'type_column' => '',
+    'prop_term_name' => '',
+    'prop_term_value' => '',
+  );
+  if (array_key_exists('base_chado_table', $form_state['values'])
+      and $form_state['values']['base_chado_table']) {
+    $default['table'] = $form_state['values']['base_chado_table'];
+  }
+  else {
+    $mapped_table = chado_get_cvterm_mapping(array('cvterm_id' => $selected_term_id));
+    if ($mapped_table) {
+      $default['table'] = $mapped_table->chado_table;
+    }
+  }
+  if (array_key_exists('chado_table_has_all', $form_state['values'])
+      and $form_state['values']['chado_table_has_all']) {
+    $default['has_all'] = $form_state['values']['chado_table_has_all'];
+  }
+  if (array_key_exists('chado_type_use_linker', $form_state['values'])
+      and $form_state['values']['chado_type_use_linker']) {
+    $default['use_linker'] = $form_state['values']['chado_type_use_linker'];
+  }
+  if (array_key_exists('chado_type_use_prop', $form_state['values'])
+      and $form_state['values']['chado_type_use_prop']) {
+    $default['use_prop'] = $form_state['values']['chado_type_use_prop'];
+  }
+  if (array_key_exists('type_column', $form_state['values'])
+      and $form_state['values']['type_column']) {
+    $default['type_column'] = $form_state['values']['type_column'];
+  }
+  if (array_key_exists('prop_term_name', $form_state['values'])
+      and $form_state['values']['prop_term_name']) {
+    $default['prop_term_name'] = $form_state['values']['prop_term_name'];
+  }
+  if (array_key_exists('prop_term_value', $form_state['values'])
+      and $form_state['values']['prop_term_value']) {
+    $default['prop_term_value'] = $form_state['values']['prop_term_value'];
+  }
+
+  $form['selected_cvterm_id'] = array(
+    '#type' => 'value',
+    '#value' => $selected_term_id,
+  );
+
+  $base_tables = chado_get_base_tables();
+  $options = array(0 => '-- Select table --');
+  foreach ($base_tables AS $tablename) {
+    $options[$tablename] = $tablename;
+  }
+  $form['base_chado_table'] = array(
+    '#type' => 'select',
+    '#title' => 'Chado table',
+    '#options' => $options,
+    '#description' => 'Select the Chado table into which the primary records for this content type will be stored.',
+    '#default_value' => $default['table'],
+    '#ajax' => array(
+      'callback' => "tripal_admin_add_type_form_ajax_callback",
+      'wrapper' => "tripal-vocab-select-form",
+      'effect' => 'fade',
+      'method' => 'replace'
+    ),
+  );
+  $form_state['input']['base_chado_table'] = $default['table'];
+
+  // Return now if the user hasn't provided a table.
+  if (!$default['table']) {
+    return $form;
+  }
+
+  // Get the schema for this table.
+  $schema = chado_get_schema($default['table']);
+
+  // Ask the user if all of the records in the default table are of one type.
+  tripal_chado_field_storage_bundle_mapping_form_add_allrecs($form,
+      $form_state, $term, $default);
+
+  // If all the records in the table are of this type then we're done.
+  if ($default['has_all'] == 'Yes') {
+    $submit_disabled = FALSE;
+    return $form;
+  }
+
+  // If this table has a field that maps to a cvterm record then we want
+  // to ask if the user wants to use that field.
+  tripal_chado_field_storage_bundle_mapping_form_add_type($form,
+      $form_state, $term, $default);
+
+  // If the type_column is set then we're done!  We know the deafult table
+  // and column to map this data type.
+  if (!empty($default['type_column'])) {
+    $submit_disabled = FALSE;
+    return $form;
+  }
+
+  // Let's set the names of the linker and prop table for use below.
+  $linker_table = $default['table'] . '_cvterm';
+  $prop_table = $default['table']. 'prop';
+  $linker_exists = chado_table_exists($linker_table);
+  $prop_exists = chado_table_exists($prop_table);
+
+  // Ask the user if they want to use a linker table if it exists.
+  if($prop_exists) {
+
+    tripal_chado_field_storage_bundle_mapping_form_add_prop($form,
+        $form_state, $term, $prop_table, $default);
+
+    // If the user wants to use the property table then we're done!
+    if ($default['use_prop'] == 'Yes') {
+      $submit_disabled = FALSE;
+      return $form;
+    }
+
+    // Ask if the user wants to use the linker table if it exists.
+    if ($linker_exists) {
+      tripal_chado_field_storage_bundle_mapping_form_add_linker($form,
+          $form_state, $term, $linker_table, $default);
+
+      // If the user wants to use the linker table then we're done!
+      if ($default['use_linker'] == 'Yes') {
+        $submit_disabled = FALSE;
+        return $form;
+      }
+    }
+
+  }
+  // A prop table doesn't exist then ask the user if they want
+  // to use the linker table to associate records.
+  else if ($linker_exists) {
+    tripal_chado_field_storage_bundle_mapping_form_add_prop($form,
+        $form_state, $term, $prop_table, $default);
+
+    // If the user wants to use the linker table then we're done!
+    if ($default['use_linker'] == 'Yes') {
+      $submit_disabled = FALSE;
+      return $form;
+    }
+  }
+
+  $form['notice'] = array(
+    '#type' => 'item',
+    '#markup' => '<font color="red">Unfortunately, the options selected above do not allow for mapping of this content type to records in Chado.</font>'
+  );
+  return $form;
+}
+
+function tripal_chado_field_storage_bundle_mapping_form_add_type(&$form,
+    &$form_state, $term, &$default){
+
+  $term_name = $term->name;
+
+  // Get the list of columns in the default table.
+  $schema = chado_get_schema($default['table']);
+  $column_options = array('none' => '--None--');
+  $cvt_fkeys = array_keys($schema['foreign keys']['cvterm']['columns']);
+  foreach ($schema['fields'] as $column_name => $column_details) {
+    if (in_array($column_name, $cvt_fkeys)) {
+      $column_options[$column_name] = $column_name;
+    }
+  }
+
+  // If this table has no types then just return.
+  if (count($column_options) == 1) {
+    $default['type_column'] = '';
+    return;
+  }
+
+  $default_column = !empty($default['type_column']) ? $default['type_column'] : 'type_id';
+  $form['type_column'] = array(
+    '#type' => 'select',
+    '#title' => 'Type Column',
+    '#options' => $column_options,
+    '#description' => 'Please select the column in the "' .
+      $default['table'] . '" table that will identify a record as being of type "' .
+      $term_name . '". If you select "--None--" then you will be asked
+      if you the type can be identified using a property or linker table.
+      Only fields that have a foreign key to the cvterm table will be listed.',
+    '#default_value' => $default_column,
+    '#ajax' => array(
+      'callback' => "tripal_admin_add_type_form_ajax_callback",
+      'wrapper' => "tripal-vocab-select-form",
+      'effect' => 'fade',
+      'method' => 'replace'
+    ),
+  );
+
+  // Set the default value so we can short circuit the form.
+  $default['type_column'] = $default_column;
+  if ($default['type_column'] == 'none') {
+    $default['type_column'] = '';
+  }
+}
+
+function tripal_chado_field_storage_bundle_mapping_form_add_allrecs(&$form,
+    &$form_state, $term, $default) {
+
+  $term_name = $term->name;
+
+  // Form elements to determine if all records in base table are of this type.
+  $form['chado_table_has_all'] = array(
+    '#type' => 'radios',
+    '#options' => array(
+      'Yes' => 'Yes',
+      'No' => 'No'
+    ),
+    '#title' => 'Are all records in the "' . $default['table'] .
+      '" table of type "'. $term_name . '"?',
+    '#description' => 'Select "No" if the "' .
+      $default['table'] . '" table houses more that just data of type "' .
+      $term_name . '".',
+    '#default_value' => $default['has_all'],
+    '#ajax' => array(
+      'callback' => "tripal_admin_add_type_form_ajax_callback",
+      'wrapper' => "tripal-vocab-select-form",
+      'effect' => 'fade',
+      'method' => 'replace'
+    ),
+  );
+}
+
+function tripal_chado_field_storage_bundle_mapping_form_add_linker(&$form,
+    &$form_state, $term, $linker_table, $default){
+
+  $form['chado_type_use_linker'] = array(
+    '#type' => 'radios',
+    '#title' => 'Do you want to use the "' . $linker_table . '" table
+      to distinguish between content types?',
+    '#options' => array(
+      'Yes' => 'Yes',
+      'No' => 'No'
+    ),
+    '#description' => t('Sometimes records can be distringuished
+      using a linker table, especially if there is no column
+      in the specified Chado table to identify the
+      record type. In these cases the linker table can be used.'),
+    '#default_value' => $default['use_linker'],
+    '#ajax' => array(
+      'callback' => "tripal_admin_add_type_form_ajax_callback",
+      'wrapper' => "tripal-vocab-select-form",
+      'effect' => 'fade',
+      'method' => 'replace'
+    ),
+  );
+}
+
+function tripal_chado_field_storage_bundle_mapping_form_add_prop(&$form,
+    &$form_state, $term, $prop_table, $default){
+
+  $form['chado_type_use_prop'] = array(
+    '#type' => 'radios',
+    '#title' => 'Do you want to use the "' . $prop_table . '" table
+      to distinguish between content types?',
+    '#options' => array(
+      'Yes' => 'Yes',
+      'No' => 'No'
+    ),
+    '#description' => t('Sometimes records can be distringuished
+      using a value in property table, especially if there is no column
+      in the specified Chado table to identify the
+      record type. In these cases the property table can be used.'),
+    '#default_value' => $default['use_prop'],
+    '#ajax' => array(
+      'callback' => "tripal_admin_add_type_form_ajax_callback",
+      'wrapper' => "tripal-vocab-select-form",
+      'effect' => 'fade',
+      'method' => 'replace'
+    ),
+  );
+
+  if ($default['use_prop'] == 'Yes') {
+    $prop_term_name = $default['prop_term_name'];
+    $prop_term_value = $default['prop_term_value'];
+
+    $form['prop_term_name'] = array(
+      '#title'       => t('Property Type'),
+      '#type'        => 'textfield',
+      '#description' => t('The content type "' . $term->name . '" must be
+          associated with a property type.  The property type must be the
+          name of a term in a controlled vocabulary and the controlled
+          vocabulary should already be loaded into Tripal. Please select
+          the property type that will be used to identify records of this
+          type'),
+      '#required'    => TRUE,
+      '#default_value' => $prop_term_name,
+      '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
+    );
+    $form['prop_term_select_button'] = array(
+      '#type' => 'submit',
+      '#value' => t('Lookup Term'),
+      '#name' => 'select_prop_cvterm',
+      '#ajax' => array(
+        'callback' => "tripal_admin_add_type_form_ajax_callback",
+        'wrapper' => "tripal-vocab-select-form",
+        'effect' => 'fade',
+        'method' => 'replace'
+      ),
+    );
+    // If the term has been provided by the user then we want to search for
+    // matching terms in the database and let them select among any matches.
+    if ($prop_term_name) {
+      $form['prop_terms_list'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Matching Terms'),
+        '#description' => t('Please select the term the best matches the
+          property type.')
+      );
+      $match = array(
+        'name' => $prop_term_name,
+      );
+      $pterms = chado_generate_var('cvterm', $match, array('return_array' => TRUE));
+      $pterms = chado_expand_var($pterms, 'field', 'cvterm.definition');
+      $num_terms = 0;
+
+      // Let the user select from any matching terms. Sometimes there may be
+      // more than one that match.
+      foreach ($pterms as $pterm) {
+        // Save the user a click by setting the default value as 1 if there's
+        // only one matching term.
+        $default = FALSE;
+        $attrs = array();
+        if ($num_terms == 0 and count($pterms) == 1) {
+          $default = TRUE;
+          $attrs = array('checked' => 'checked');
+        }
+        $term_element_name = 'prop_term-' . $pterm->cvterm_id;
+        $form['prop_terms_list'][$term_element_name] = array(
+          '#type' => 'checkbox',
+          '#title' =>  $pterm->name,
+          '#default_value' => $default,
+          '#attributes' => $attrs,
+          '#description' => '<b>Vocabulary:</b> ' . $pterm->cv_id->name . ' (' . $pterm->dbxref_id->db_id->name . ') ' . $pterm->cv_id->definition .
+            '<br><b>Term: </b> ' . $pterm->dbxref_id->db_id->name . ':' . $pterm->dbxref_id->accession . '.  ' .
+            '<br><b>Definition:</b>  ' . $pterm->definition,
+          '#ajax' => array(
+            'callback' => "tripal_admin_add_type_form_ajax_callback",
+            'wrapper' => "tripal-vocab-select-form",
+            'effect' => 'fade',
+            'method' => 'replace'
+          ),
+        );
+        $num_terms++;
+      }
+
+      $form['prop_term_value'] = array(
+        '#type' => 'textfield',
+        '#title' => 'Property Value',
+        '#description' => t('All properties have a type and a value.  Above you
+            indicated the type of property. Now you must specify the value
+            that this properly must have in order to be considered of
+            type "' . $term->name . '".'),
+        '#default_value' => $prop_term_value,
+        '#required' => TRUE,
+      );
+    }
+  }
+}
+/**
+ * Implements hook_field_stoage_bundle_mapping_form_validate().
+ */
+function tripal_chado_field_storage_bundle_mapping_form_validate($form, &$form_state) {
+  // Get the form values
+  $default = array(
+    'table' => '',
+    'has_all' => 'No',
+    'use_linker' => 'Yes',
+    'use_prop' => 'Yes',
+    'type_column' => '',
+    'prop_term_name' => '',
+    'prop_term_value' => '',
+  );
+  if (array_key_exists('base_chado_table', $form_state['values'])
+      and $form_state['values']['base_chado_table']) {
+    $default['table'] = $form_state['values']['base_chado_table'];
+  }
+  if (array_key_exists('chado_table_has_all', $form_state['values'])
+      and $form_state['values']['chado_table_has_all']) {
+    $default['has_all'] = $form_state['values']['chado_table_has_all'];
+  }
+  if (array_key_exists('chado_type_use_linker', $form_state['values'])
+      and $form_state['values']['chado_type_use_linker']) {
+    $default['use_linker'] = $form_state['values']['chado_type_use_linker'];
+  }
+  if (array_key_exists('chado_type_use_prop', $form_state['values'])
+      and $form_state['values']['chado_type_use_prop']) {
+    $default['use_prop'] = $form_state['values']['chado_type_use_prop'];
+  }
+  if (array_key_exists('type_column', $form_state['values'])
+      and $form_state['values']['type_column']) {
+    $default['type_column'] = $form_state['values']['type_column'];
+  }
+  if (array_key_exists('prop_term_name', $form_state['values'])
+      and $form_state['values']['prop_term_name']) {
+    $default['prop_term_name'] = $form_state['values']['prop_term_name'];
+  }
+  if (array_key_exists('prop_term_value', $form_state['values'])
+      and $form_state['values']['prop_term_value']) {
+    $default['prop_term_value'] = $form_state['values']['prop_term_value'];
+  }
+
+  // Make sure a default table is selected
+  if (!$default['table']) {
+    form_set_error('base_chado_table', 'Please select a default table.');
+  }
+
+  // Make sure we have only one property cvterm selected
+  $num_selected = 0;
+  foreach ($form_state['values'] as $key => $value) {
+    $matches = array();
+    if (preg_match("/^prop_term-(\d+)$/", $key, $matches) and
+        $form_state['values']['prop_term-' . $matches[1]]) {
+      $cvterm_id = $matches[1];
+      $term = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
+      $num_selected++;
+    }
+  }
+  if ($num_selected == 0) {
+    form_set_error('', 'Please select at least one property term.');
+  }
+  else if ($num_selected > 1) {
+    form_set_error('prop_term-' . $cvterm_id, 'Please select only one property term from the list below.');
+  }
+  $form_state['prop_term'] = $term;
+
+}
+/**
+ * Implements hook_field_stoage_bundle_mapping_form_submit().
+ *
+ * Here we do no action on submit other than set the storage_args
+ * variable that is passed by reference.
+ */
+function tripal_chado_field_storage_bundle_mapping_form_submit($form,
+    &$form_state, $term, &$storage_args) {
+
+  // Get the form values
+  $default = array(
+    'table' => '',
+    'has_all' => 'No',
+    'use_linker' => 'Yes',
+    'use_prop' => 'Yes',
+    'type_column' => '',
+    'prop_term_name' => '',
+    'prop_term_value' => '',
+  );
+  if (array_key_exists('base_chado_table', $form_state['values'])
+      and $form_state['values']['base_chado_table']) {
+    $default['table'] = $form_state['values']['base_chado_table'];
+  }
+  if (array_key_exists('chado_table_has_all', $form_state['values'])
+      and $form_state['values']['chado_table_has_all']) {
+    $default['has_all'] = $form_state['values']['chado_table_has_all'];
+  }
+  if (array_key_exists('chado_type_use_linker', $form_state['values'])
+      and $form_state['values']['chado_type_use_linker']) {
+    $default['use_linker'] = $form_state['values']['chado_type_use_linker'];
+  }
+  if (array_key_exists('chado_type_use_prop', $form_state['values'])
+      and $form_state['values']['chado_type_use_prop']) {
+    $default['use_prop'] = $form_state['values']['chado_type_use_prop'];
+  }
+  if (array_key_exists('type_column', $form_state['values'])
+      and $form_state['values']['type_column']) {
+    $default['type_column'] = $form_state['values']['type_column'];
+  }
+  if (array_key_exists('prop_term_name', $form_state['values'])
+      and $form_state['values']['prop_term_name']) {
+    $default['prop_term_name'] = $form_state['values']['prop_term_name'];
+  }
+  if (array_key_exists('prop_term_value', $form_state['values'])
+      and $form_state['values']['prop_term_value']) {
+    $default['prop_term_value'] = $form_state['values']['prop_term_value'];
+  }
+
+  // If we have a type_column then we know this type uses a column in the
+  // base table, so we can set the storage args and return.
+  if ($default['type_column']) {
+    $storage_args['data_table'] = $default['table'];
+    $storage_args['type_id'] = $form_state['values']['selected_cvterm_id'];
+    $storage_args['type_column'] = $default['type_column'];
+    return;
+  }
+
+  // If the user indicated they wanted to use the prop table then we'll
+  // set the storage args and return.
+  if ($default['use_prop'] == 'Yes') {
+    $storage_args['data_table'] = $default['table'];
+    $storage_args['type_linker_table'] = $default['table'] . 'prop';
+    $storage_args['type_column'] = 'type_id';
+    $storage_args['type_id'] = $form_state['prop_term']->cvterm_id;
+    $storage_args['type_value'] = $default['prop_term_value'];
+    return;
+  }
+
+  // If the user indicated they wanted to use the linker tables then we'll
+  // set the storage args and return.
+  if ($default['use_linker'] == 'Yes') {
+    $storage_args['data_table'] = $default['table'];
+    $storage_args['type_id'] = $form_state['values']['selected_cvterm_id'];
+    $storage_args['type_linker_table'] = $default['table'] . '_cvterm';
+    $storage_args['type_column'] = 'cvterm_id';
+    return;
+  }
+}

+ 54 - 19
tripal_chado/includes/tripal_chado.fields.inc

@@ -1474,7 +1474,7 @@ function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle
        SELECT DISTINCT P.type_id
        FROM {" . $prop_table . "} P
      ";
-     if ($type_field) {
+     if (array_key_exists('type_id', $tschema['fields'])) {
        $sql .= "
            INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
          WHERE T.type_id = :cvterm_id
@@ -1695,10 +1695,11 @@ function tripal_chado_bundle_create_user_field($new_field, $bundle) {
     'vocabulary' => $vocab->vocabulary,
     'accession' => $term->accession,
   );
-  $mapped_table = chado_get_cvterm_mapping($params);
-  $chado_table = $mapped_table->chado_table;
-  $chado_type_table = $mapped_table->chado_table;
-  $chado_type_column = $mapped_table->chado_field;
+  $chado_table = $bundle->data_table;
+  $chado_type_table = $bundle->type_linker_table;
+  $chado_type_column = $bundle->type_column;
+  $chado_type_id = $bundle->type_id;
+  $chado_type_value = $bundle->type_value;
 
   // We allow site admins to add new chado_linker__prop fields to an entity.
   // This function will allow us to properly add them.  But at this point we
@@ -1737,9 +1738,9 @@ function tripal_chado_bundle_create_user_field($new_field, $bundle) {
           'base_table' => $chado_table,
           'chado_table' => $table_name,
           'chado_column' => $pkey,
-          'term_vocabulary' => $vocab->vocabulary,
-          'term_accession' => $term->accession,
-          'term_name' => $term->name
+          'term_vocabulary' => '',
+          'term_accession' => '',
+          'term_name' => ''
         ),
         'widget' => array(
           'type' => 'chado_linker__prop_widget',
@@ -1914,9 +1915,11 @@ function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
     'vocabulary' => $vocab->vocabulary,
     'accession' => $term->accession,
   );
-  $mapped_table = chado_get_cvterm_mapping($params);
-  $chado_table = $mapped_table->chado_table;
-  $chado_column = $mapped_table->chado_field;
+  $chado_table = $bundle->data_table;
+  $chado_column = $bundle->type_column;
+  $chado_type_table = $bundle->type_linker_table;
+  $chado_type_id = $bundle->type_id;
+  $chado_type_value = $bundle->type_value;
 
   // Construct a table for the vocabulary information.
   $headers = array();
@@ -1929,14 +1932,46 @@ function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
     ),
     $chado_table
   );
-  $rows[] = array(
-    array(
-      'data' => 'Type Column',
-      'header' => TRUE,
-      'width' => '20%',
-    ),
-    $chado_column
-  );
+  if ($chado_column) {
+    $rows[] = array(
+      array(
+        'data' => 'Type Column',
+        'header' => TRUE,
+        'width' => '20%',
+      ),
+      $chado_column
+    );
+  }
+  if ($chado_type_table) {
+    $rows[] = array(
+      array(
+        'data' => 'Association Table',
+        'header' => TRUE,
+        'width' => '20%',
+      ),
+      $chado_type_table
+    );
+  }
+  if ($chado_type_table and $chado_type_id) {
+    $rows[] = array(
+      array(
+        'data' => 'CVTerm Table ID',
+        'header' => TRUE,
+        'width' => '20%',
+      ),
+      $chado_type_id
+    );
+  }
+  if ($chado_type_value) {
+    $rows[] = array(
+      array(
+        'data' => 'Property Value',
+        'header' => TRUE,
+        'width' => '20%',
+      ),
+      $chado_type_value
+    );
+  }
   $table = array(
     'header' => $headers,
     'rows' => $rows,

+ 69 - 5
tripal_chado/tripal_chado.module

@@ -545,7 +545,7 @@ function tripal_chado_menu() {
     'page callback' => 'tripal_autocomplete_cvterm',
     'page arguments' => array(6, 7),
     'access arguments' => array('access content'),
-    'file' => 'api/modules/tripal_chado.db.api.inc',
+    'file' => 'api/modules/tripal_chado.cv.api.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
     'type' => MENU_CALLBACK,
   );
@@ -583,12 +583,76 @@ function tripal_chado_menu() {
     'type' => MENU_CALLBACK,
   );
 
+  //////////////////////////////////////////////////////////////////////////////
+  //                          Controlled Vocabularies
+  //////////////////////////////////////////////////////////////////////////////
+  $items['admin/tripal/loaders/chado_cv'] = array(
+    'title' => 'Chado Controlled Vocabularies',
+    'description' => 'Controlled Vocabularies control the terms available for various chado fields.',
+    'page callback' => 'tripal_cv_admin_cv_listing',
+    'access arguments' => array('administer controlled vocabularies'),
+    'file' => 'includes/tripal_chado.cv.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/tripal/loaders/chado_cv/edit/%'] = array(
+    'title' => 'Edit a Controlled Vocabulary',
+    'description' => 'Edit the details such as name and description for an existing controlled vocabulary.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_cv_cv_edit_form', 5),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer controlled vocabularies'),
+    'file' => 'includes/tripal_chado.cv.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/tripal/loaders/chado_cv/add'] = array(
+    'title' => 'Add a Controlled Vocabulary',
+    'description' => 'Manually a new controlled vocabulary.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_cv_cv_add_form'),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer controlled vocabularies'),
+    'file' => 'includes/tripal_chado.cv.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/tripal/loaders/chado_cv/%/cvterm/add'] = array(
+    'title' => 'Add a Controlled Vocabulary Term',
+    'description' => 'Add a new controlled vocabulary term.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_cv_cvterm_add_form', 4),
+    'access arguments' => array('administer controlled vocabularies'),
+    'file' => 'includes/tripal_chado.cv.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/tripal/loaders/chado_cv/cvterm/add'] = array(
+    'title' => 'Add a Controlled Vocabulary Term',
+    'description' => 'Add a new controlled vocabulary term.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_cv_cvterm_add_form'),
+    'access arguments' => array('administer controlled vocabularies'),
+    'file' => 'includes/tripal_chado.cv.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/tripal/loaders/chado_cv/%/cvterm/edit/%'] = array(
+    'title' => 'Edit a Controlled Vocabulary Term',
+    'description' => 'Edit an existing controlled vocabulary term.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_cv_cvterm_edit_form', 4, 7),
+    'access arguments' => array('administer controlled vocabularies'),
+    'file' => 'includes/tripal_chado.cv.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_CALLBACK,
+  );
 
   //////////////////////////////////////////////////////////////////////////////
   //                           Databases
   //////////////////////////////////////////////////////////////////////////////
-  $items['admin/tripal/storage/chado/db'] = array(
-    'title' => 'Databases',
+  $items['admin/tripal/loaders/chado_db'] = array(
+    'title' => 'Chado Databases',
     'description' => 'References to External Database sites such as NCBI',
     'page callback' => 'tripal_chado_admin_db_listing',
     'access arguments' => array('administer db cross-references'),
@@ -596,7 +660,7 @@ function tripal_chado_menu() {
     'file path' => drupal_get_path('module', 'tripal_chado'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items['admin/tripal/storage/chado/db/edit/%'] = array(
+  $items['admin/tripal/loaders/chado_db/edit/%'] = array(
     'title' => 'Edit a Database Reference',
     'description' => 'Edit existing Database References.',
     'page callback' => 'drupal_get_form',
@@ -608,7 +672,7 @@ function tripal_chado_menu() {
     'type' => MENU_CALLBACK,
   );
 
-  $items['admin/tripal/storage/chado/db/add'] = array(
+  $items['admin/tripal/loaders/chado_db/add'] = array(
     'title' => 'Create a Database Reference',
     'description' => 'Create a new reference to an External Database.',
     'page callback' => 'drupal_get_form',

+ 16 - 16
tripal_chado/tripal_chado.views_default.inc

@@ -504,7 +504,7 @@ function tripal_chado_defaultview_admin_cvs_listing() {
   $handler->display->display_options['header']['action_links_area']['empty'] = TRUE;
   $handler->display->display_options['header']['action_links_area']['link-1'] = array(
     'label-1' => 'Add Vocabulary',
-    'path-1' => 'admin/tripal/vocab/cv/add',
+    'path-1' => 'admin/tripal/loaders/chado_cv/add',
   );
   $handler->display->display_options['header']['action_links_area']['link-2'] = array(
     'label-2' => 'Load Ontology',
@@ -538,7 +538,7 @@ function tripal_chado_defaultview_admin_cvs_listing() {
   $handler->display->display_options['fields']['nothing_1']['exclude'] = TRUE;
   $handler->display->display_options['fields']['nothing_1']['alter']['text'] = 'edit';
   $handler->display->display_options['fields']['nothing_1']['alter']['make_link'] = TRUE;
-  $handler->display->display_options['fields']['nothing_1']['alter']['path'] = 'admin/tripal/vocab/cv/edit/[cv_id]';
+  $handler->display->display_options['fields']['nothing_1']['alter']['path'] = 'admin/tripal/loaders/chado_cv/edit/[cv_id]';
   /* Field: Global: Custom text */
   $handler->display->display_options['fields']['nothing']['id'] = 'nothing';
   $handler->display->display_options['fields']['nothing']['table'] = 'views';
@@ -547,7 +547,7 @@ function tripal_chado_defaultview_admin_cvs_listing() {
   $handler->display->display_options['fields']['nothing']['exclude'] = TRUE;
   $handler->display->display_options['fields']['nothing']['alter']['text'] = 'View Terms';
   $handler->display->display_options['fields']['nothing']['alter']['make_link'] = TRUE;
-  $handler->display->display_options['fields']['nothing']['alter']['path'] = 'admin/tripal/vocab/cvterms?cv=[name]';
+  $handler->display->display_options['fields']['nothing']['alter']['path'] = 'admin/tripal/loaders/chado_cvterms?cv=[name]';
   $handler->display->display_options['fields']['nothing']['hide_alter_empty'] = TRUE;
   /* Field: Global: Custom text */
   $handler->display->display_options['fields']['nothing_3']['id'] = 'nothing_3';
@@ -557,7 +557,7 @@ function tripal_chado_defaultview_admin_cvs_listing() {
   $handler->display->display_options['fields']['nothing_3']['exclude'] = TRUE;
   $handler->display->display_options['fields']['nothing_3']['alter']['text'] = 'Add Term';
   $handler->display->display_options['fields']['nothing_3']['alter']['make_link'] = TRUE;
-  $handler->display->display_options['fields']['nothing_3']['alter']['path'] = 'admin/tripal/vocab/cv/[cv_id]/cvterm/add';
+  $handler->display->display_options['fields']['nothing_3']['alter']['path'] = 'admin/tripal/loaders/chado_cv/[cv_id]/cvterm/add';
   /* Field: Global: Custom text */
   $handler->display->display_options['fields']['nothing_2']['id'] = 'nothing_2';
   $handler->display->display_options['fields']['nothing_2']['table'] = 'views';
@@ -613,9 +613,9 @@ function tripal_chado_defaultview_admin_cvs_listing() {
 
   /* Display: Page */
   $handler = $view->new_display('page', 'Page', 'page_1');
-  $handler->display->display_options['path'] = 'admin/tripal/vocab/cvs';
+  $handler->display->display_options['path'] = 'admin/tripal/loaders/chado_cvs';
   $handler->display->display_options['menu']['type'] = 'default tab';
-  $handler->display->display_options['menu']['title'] = 'Vocabularies';
+  $handler->display->display_options['menu']['title'] = 'Chado Controlled Vocabularies';
   $handler->display->display_options['menu']['description'] = 'A listing of all controlled vocabularies';
   $handler->display->display_options['menu']['weight'] = '-10';
   $handler->display->display_options['menu']['name'] = 'management';
@@ -708,7 +708,7 @@ $handler->display->display_options['header']['action_links_area']['label'] = 'Ac
 $handler->display->display_options['header']['action_links_area']['empty'] = TRUE;
 $handler->display->display_options['header']['action_links_area']['link-1'] = array(
   'label-1' => 'Add Term',
-  'path-1' => 'admin/tripal/vocab/cvterm/add',
+  'path-1' => 'admin/tripal/loaders/chado_cv/cvterm/add',
 );
 /* No results behavior: Global: Text area */
 $handler->display->display_options['empty']['text']['id'] = 'area';
@@ -728,7 +728,7 @@ $handler->display->display_options['fields']['name_1']['table'] = 'cv';
 $handler->display->display_options['fields']['name_1']['field'] = 'name';
 $handler->display->display_options['fields']['name_1']['label'] = 'Vocabulary';
 $handler->display->display_options['fields']['name_1']['alter']['make_link'] = TRUE;
-$handler->display->display_options['fields']['name_1']['alter']['path'] = 'admin/tripal/vocab/cvs?name=[name_1]';
+$handler->display->display_options['fields']['name_1']['alter']['path'] = 'admin/tripal/loaders/chado_cvs?name=[name_1]';
 /* Field: Chado Cvterm: Cvterm Id */
 $handler->display->display_options['fields']['cvterm_id']['id'] = 'cvterm_id';
 $handler->display->display_options['fields']['cvterm_id']['table'] = 'cvterm';
@@ -777,7 +777,7 @@ $handler->display->display_options['fields']['nothing']['label'] = 'Edit Link';
 $handler->display->display_options['fields']['nothing']['exclude'] = TRUE;
 $handler->display->display_options['fields']['nothing']['alter']['text'] = 'edit';
 $handler->display->display_options['fields']['nothing']['alter']['make_link'] = TRUE;
-$handler->display->display_options['fields']['nothing']['alter']['path'] = 'admin/tripal/vocab/cv/[cv_id]/cvterm/edit/[cvterm_id]';
+$handler->display->display_options['fields']['nothing']['alter']['path'] = 'admin/tripal/loaders/chado_cv/[cv_id]/cvterm/edit/[cvterm_id]';
 /* Field: Global: Custom text */
 $handler->display->display_options['fields']['nothing_1']['id'] = 'nothing_1';
 $handler->display->display_options['fields']['nothing_1']['table'] = 'views';
@@ -847,9 +847,9 @@ $handler->display->display_options['filters']['definition']['expose']['remember_
 
 /* Display: Page */
 $handler = $view->new_display('page', 'Page', 'page_1');
-$handler->display->display_options['path'] = 'admin/tripal/storage/chado/cvterms';
+$handler->display->display_options['path'] = 'admin/tripal/loaders/chado_cvterms';
 $handler->display->display_options['menu']['type'] = 'normal';
-$handler->display->display_options['menu']['title'] = 'Terms';
+$handler->display->display_options['menu']['title'] = 'Chado CV Terms';
 $handler->display->display_options['menu']['description'] = 'A listing of a controlled vocabulary terms for a given vocabulary';
 $handler->display->display_options['menu']['weight'] = '-8';
 $handler->display->display_options['menu']['name'] = 'management';
@@ -920,7 +920,7 @@ function tripal_chado_defaultview_admin_db_listing() {
   $handler->display->display_options['header']['action_links_area']['empty'] = TRUE;
   $handler->display->display_options['header']['action_links_area']['link-1'] = array(
     'label-1' => 'Add Database',
-    'path-1' => 'admin/tripal/storage/chado/db/add',
+    'path-1' => 'admin/tripal/loaders/chado_db/add',
   );
   /* No results behavior: Global: Text area */
   $handler->display->display_options['empty']['text']['id'] = 'area';
@@ -950,7 +950,7 @@ function tripal_chado_defaultview_admin_db_listing() {
   $handler->display->display_options['fields']['nothing']['exclude'] = TRUE;
   $handler->display->display_options['fields']['nothing']['alter']['text'] = 'edit';
   $handler->display->display_options['fields']['nothing']['alter']['make_link'] = TRUE;
-  $handler->display->display_options['fields']['nothing']['alter']['path'] = 'admin/tripal/storage/chado/db/edit/[db_id]';
+  $handler->display->display_options['fields']['nothing']['alter']['path'] = 'admin/tripal/loaders/chado_db/edit/[db_id]';
   /* Field: Global: Custom text */
   $handler->display->display_options['fields']['nothing_1']['id'] = 'nothing_1';
   $handler->display->display_options['fields']['nothing_1']['table'] = 'views';
@@ -959,7 +959,7 @@ function tripal_chado_defaultview_admin_db_listing() {
   $handler->display->display_options['fields']['nothing_1']['exclude'] = TRUE;
   $handler->display->display_options['fields']['nothing_1']['alter']['text'] = 'items';
   $handler->display->display_options['fields']['nothing_1']['alter']['make_link'] = TRUE;
-  $handler->display->display_options['fields']['nothing_1']['alter']['path'] = 'admin/tripal/storage/chado/db/dbxrefs?db_name=[name]';
+  $handler->display->display_options['fields']['nothing_1']['alter']['path'] = 'admin/tripal/loaders/chado_db/dbxrefs?db_name=[name]';
   /* Field: Global: Custom text */
   $handler->display->display_options['fields']['nothing_2']['id'] = 'nothing_2';
   $handler->display->display_options['fields']['nothing_2']['table'] = 'views';
@@ -1002,7 +1002,7 @@ function tripal_chado_defaultview_admin_db_listing() {
 
   /* Display: Page */
   $handler = $view->new_display('page', 'Page', 'page_1');
-  $handler->display->display_options['path'] = 'admin/tripal/storage/chado/db/dbs';
+  $handler->display->display_options['path'] = 'admin/tripal/loaders/chado_db/dbs';
   $handler->display->display_options['menu']['type'] = 'default tab';
   $handler->display->display_options['menu']['title'] = 'Databases';
   $handler->display->display_options['menu']['description'] = 'Lists all databases available to create database references for.';
@@ -1184,7 +1184,7 @@ function tripal_chado_defaultview_admin_dbxref_listing() {
 
   /* Display: Page */
   $handler = $view->new_display('page', 'Page', 'page');
-  $handler->display->display_options['path'] = 'admin/tripal/storage/chado/db/dbxrefs';
+  $handler->display->display_options['path'] = 'admin/tripal/loaders/chado_db/dbxrefs';
   $handler->display->display_options['menu']['type'] = 'tab';
   $handler->display->display_options['menu']['title'] = 'References';
   $handler->display->display_options['menu']['weight'] = '0';

+ 3 - 3
tripal_chado_views/api/tripal_chado_views.api.inc

@@ -1,7 +1,7 @@
 <?php
 /**
  * @file
- * API functions for Tripal Views Integration
+ * API functions for Chado Views Integration
  */
 
  /**
@@ -81,7 +81,7 @@ function mymodule_admin_landing_page() {
 
  * @endcode
  *
- * Adding your own Tripal Views Integrations:
+ * Adding your own Chado Views Integrations:
  *
  * One of the main ways the Tripal View API is likely to be used is if your module needs
  * to create it's own tripal views integration. You might need to do this for any number of
@@ -565,7 +565,7 @@ function tripal_rebuild_views_integrations($delete_first = FALSE) {
 
   // TODO: the function above should have a return value from which we can
   // determine if the message below is approprite.
-  drupal_set_message('Successfully rebuilt default Tripal Views Integrations');
+  drupal_set_message('Successfully rebuilt default Chado Views Integrations');
 }
 
 /**

+ 1 - 1
tripal_chado_views/includes/tripal_chado_views_integration.inc

@@ -5,7 +5,7 @@
  */
 
 /**
- * Purpose: Deletes ALL Tripal Views Integrations.
+ * Purpose: Deletes ALL Chado Views Integrations.
  *
  * @ingroup tripal_chado_views
  */

+ 6 - 6
tripal_chado_views/includes/tripal_chado_views_integration_UI.inc

@@ -138,7 +138,7 @@ function tripal_chado_views_integration_delete($setup_id) {
 }
 
 /**
- * Purpose: Deletes ALL Tripal Views Integrations.  This
+ * Purpose: Deletes ALL Chado Views Integrations.  This
  *   function is meant to be called from a menu item. After completion it
  *   redirects the user to the views intergation page.
  *
@@ -180,7 +180,7 @@ function tripal_chado_views_integration_delete_all_form($form, &$form_state) {
 }
 
 /**
- * Purpose: Deletes ALL Tripal Views Integrations.  This
+ * Purpose: Deletes ALL Chado Views Integrations.  This
  *   function is meant to be called from a menu item. After completion it
  *   redirects the user to the views intergation page.
  *
@@ -414,7 +414,7 @@ function tripal_chado_views_integration_form($form, &$form_state) {
   }
   $form['views_type']['new_integration'] = array(
     '#type' => 'checkbox',
-    '#title' => t('Create a New Tripal Views Integration Record'),
+    '#title' => t('Create a New Chado Views Integration Record'),
     '#description' => t('If this checkbox is checked then a new tripal views integration '
       .'will be created rather then overriding the current one with your changes. This '
       .'especially important if you are editing one of the default views integrations '
@@ -1417,7 +1417,7 @@ function tripal_chado_views_integration_discover_handlers() {
 }
 
 /*
- * Ajax Callback: Tripal Views Integration Form
+ * Ajax Callback: Chado Views Integration Form
  * Replaces the entire fields table when the table or materialized view is set/changed
  *
  * @ingroup tripal_chado_views
@@ -1428,7 +1428,7 @@ function tripal_chado_views_integration_ajax_view_setup_table($form, $form_state
 }
 
 /*
- * Ajax Callback: Tripal Views Integration Form
+ * Ajax Callback: Chado Views Integration Form
  * Replaces the join db field dropdown when the join table dropdown is changed
  *
  * @ingroup tripal_chado_views
@@ -1444,7 +1444,7 @@ function tripal_chado_views_integration_ajax_join_field($form, $form_state) {
   }
   else {
     tripal_report_error('tripal_views', TRIPAL_ERROR,
-      'Tripal Views Integration Ajax failed due to being unable to determine which row needs updating', array());
+      'Chado Views Integration Ajax failed due to being unable to determine which row needs updating', array());
     return $form;
   }
 }

+ 3 - 3
tripal_chado_views/tripal_chado_views.module

@@ -97,7 +97,7 @@ function tripal_chado_views_menu() {
 
   $items['admin/tripal/storage/chado/views-integration/import'] = array(
     'title' => 'Import Views Integration',
-    'description' => 'Import a Tripal Views Integration from another site.',
+    'description' => 'Import a Chado Views Integration from another site.',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_chado_views_integration_import_form'),
     'access arguments' => array('manage tripal_views_integration'),
@@ -107,7 +107,7 @@ function tripal_chado_views_menu() {
 
   $items['admin/tripal/storage/chado/views-integration/export'] = array(
     'title' => 'Export Views Integration',
-    'description' => 'Export a Tripal Views Integration for use in another Tripal site',
+    'description' => 'Export a Chado Views Integration for use in another Tripal site',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_chado_views_integration_export_form', 4),
     'access arguments' => array('manage tripal_views_integration'),
@@ -117,7 +117,7 @@ function tripal_chado_views_menu() {
 
   $items['admin/tripal/storage/chado/views-integration/export/%'] = array(
     'title' => 'Export Views Integration',
-    'description' => 'Export a Tripal Views Integration for use in another Tripal site',
+    'description' => 'Export a Chado Views Integration for use in another Tripal site',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tripal_chado_views_integration_export_form', 4),
     'access arguments' => array('manage tripal_views_integration'),

+ 3 - 3
tripal_chado_views/tripal_chado_views.views.inc

@@ -1,7 +1,7 @@
 <?php
 /**
  * @file
- * Tripal Views Integration
+ * Chado Views Integration
  */
 
 include 'views/handlers/tripal_views_handler_area_action_links.inc';
@@ -420,10 +420,10 @@ function tripal_chado_views_views_data() {
  */
 function tripal_chado_views_views_data_tripal_views_tables($data) {
 
-  $data['tripal_views']['table']['group'] = t('Tripal Views Integration');
+  $data['tripal_views']['table']['group'] = t('Chado Views Integration');
   $data['tripal_views']['table']['base'] = array(
     'field' => 'setup_id', // This is the identifier field for the view.
-    'title' => t('Tripal Views Integration'),
+    'title' => t('Chado Views Integration'),
     'help' => t('Specifications on how to integrate various tables with Drupal Views'),
     'weight' => -10,
   );

+ 14 - 14
tripal_chado_views/tripal_chado_views.views_default.inc

@@ -36,7 +36,7 @@ $view->disabled = FALSE; /* Edit this to true to make a default view disabled in
 
 /* Display: Master */
 $handler = $view->new_display('default', 'Master', 'default');
-$handler->display->display_options['title'] = 'Tripal Views Integrations';
+$handler->display->display_options['title'] = 'Chado Views Integrations';
 $handler->display->display_options['use_more_always'] = FALSE;
 $handler->display->display_options['access']['type'] = 'perm';
 $handler->display->display_options['access']['perm'] = 'manage tripal_views_integration';
@@ -152,17 +152,17 @@ $handler->display->display_options['header']['action_links_area_1']['link-4'] =
   'label-4' => '',
   'path-4' => '',
 );
-/* Field: Tripal Views Integration: Setup ID */
+/* Field: Chado Views Integration: Setup ID */
 $handler->display->display_options['fields']['setup_id']['id'] = 'setup_id';
 $handler->display->display_options['fields']['setup_id']['table'] = 'tripal_views';
 $handler->display->display_options['fields']['setup_id']['field'] = 'setup_id';
 $handler->display->display_options['fields']['setup_id']['exclude'] = TRUE;
 $handler->display->display_options['fields']['setup_id']['separator'] = '';
-/* Field: Tripal Views Integration: Name */
+/* Field: Chado Views Integration: Name */
 $handler->display->display_options['fields']['name']['id'] = 'name';
 $handler->display->display_options['fields']['name']['table'] = 'tripal_views';
 $handler->display->display_options['fields']['name']['field'] = 'name';
-/* Field: Tripal Views Integration: Chado Table Name */
+/* Field: Chado Views Integration: Chado Table Name */
 $handler->display->display_options['fields']['table_name']['id'] = 'table_name';
 $handler->display->display_options['fields']['table_name']['table'] = 'tripal_views';
 $handler->display->display_options['fields']['table_name']['field'] = 'table_name';
@@ -171,16 +171,16 @@ $handler->display->display_options['fields']['mv_table']['id'] = 'mv_table';
 $handler->display->display_options['fields']['mv_table']['table'] = 'tripal_mviews';
 $handler->display->display_options['fields']['mv_table']['field'] = 'mv_table';
 $handler->display->display_options['fields']['mv_table']['label'] = 'Materialized View';
-/* Field: Tripal Views Integration: Description */
+/* Field: Chado Views Integration: Description */
 $handler->display->display_options['fields']['comment']['id'] = 'comment';
 $handler->display->display_options['fields']['comment']['table'] = 'tripal_views';
 $handler->display->display_options['fields']['comment']['field'] = 'comment';
-/* Field: Tripal Views Integration: Base Table? */
+/* Field: Chado Views Integration: Base Table? */
 $handler->display->display_options['fields']['base_table']['id'] = 'base_table';
 $handler->display->display_options['fields']['base_table']['table'] = 'tripal_views';
 $handler->display->display_options['fields']['base_table']['field'] = 'base_table';
 $handler->display->display_options['fields']['base_table']['not'] = 0;
-/* Field: Tripal Views Integration: Priority */
+/* Field: Chado Views Integration: Priority */
 $handler->display->display_options['fields']['priority']['id'] = 'priority';
 $handler->display->display_options['fields']['priority']['table'] = 'tripal_views';
 $handler->display->display_options['fields']['priority']['field'] = 'priority';
@@ -222,15 +222,15 @@ $handler->display->display_options['fields']['nothing_3']['alter']['text'] = '[n
 $handler->display->display_options['fields']['nothing_3']['element_class'] = 'short-column';
 $handler->display->display_options['fields']['nothing_3']['element_label_class'] = 'short-column';
 $handler->display->display_options['fields']['nothing_3']['element_label_colon'] = FALSE;
-/* Sort criterion: Tripal Views Integration: Chado Table Name */
+/* Sort criterion: Chado Views Integration: Chado Table Name */
 $handler->display->display_options['sorts']['table_name']['id'] = 'table_name';
 $handler->display->display_options['sorts']['table_name']['table'] = 'tripal_views';
 $handler->display->display_options['sorts']['table_name']['field'] = 'table_name';
-/* Sort criterion: Tripal Views Integration: Priority */
+/* Sort criterion: Chado Views Integration: Priority */
 $handler->display->display_options['sorts']['priority']['id'] = 'priority';
 $handler->display->display_options['sorts']['priority']['table'] = 'tripal_views';
 $handler->display->display_options['sorts']['priority']['field'] = 'priority';
-/* Filter criterion: Tripal Views Integration: Name */
+/* Filter criterion: Chado Views Integration: Name */
 $handler->display->display_options['filters']['name']['id'] = 'name';
 $handler->display->display_options['filters']['name']['table'] = 'tripal_views';
 $handler->display->display_options['filters']['name']['field'] = 'name';
@@ -246,7 +246,7 @@ $handler->display->display_options['filters']['name']['expose']['remember_roles'
   1 => 0,
   3 => 0,
 );
-/* Filter criterion: Tripal Views Integration: Chado Table Name */
+/* Filter criterion: Chado Views Integration: Chado Table Name */
 $handler->display->display_options['filters']['table_name']['id'] = 'table_name';
 $handler->display->display_options['filters']['table_name']['table'] = 'tripal_views';
 $handler->display->display_options['filters']['table_name']['field'] = 'table_name';
@@ -276,7 +276,7 @@ $handler->display->display_options['filters']['mv_table']['expose']['remember_ro
   1 => 0,
   3 => 0,
 );
-/* Filter criterion: Tripal Views Integration: Priority */
+/* Filter criterion: Chado Views Integration: Priority */
 $handler->display->display_options['filters']['priority']['id'] = 'priority';
 $handler->display->display_options['filters']['priority']['table'] = 'tripal_views';
 $handler->display->display_options['filters']['priority']['field'] = 'priority';
@@ -291,7 +291,7 @@ $handler->display->display_options['filters']['priority']['expose']['remember_ro
   1 => 0,
   3 => 0,
 );
-/* Filter criterion: Tripal Views Integration: Base Table? */
+/* Filter criterion: Chado Views Integration: Base Table? */
 $handler->display->display_options['filters']['base_table']['id'] = 'base_table';
 $handler->display->display_options['filters']['base_table']['table'] = 'tripal_views';
 $handler->display->display_options['filters']['base_table']['field'] = 'base_table';
@@ -312,7 +312,7 @@ $handler->display->display_options['filters']['base_table']['expose']['remember_
 $handler = $view->new_display('page', 'Page', 'page');
 $handler->display->display_options['path'] = 'admin/tripal/storage/chado/views-integration';
 $handler->display->display_options['menu']['type'] = 'normal';
-$handler->display->display_options['menu']['title'] = 'Integrations';
+$handler->display->display_options['menu']['title'] = 'Chado Views Integrations';
 $handler->display->display_options['menu']['description'] = 'Integrates Chado tables with Drupal Views for direct access.';
 $handler->display->display_options['menu']['weight'] = '-10';
 $handler->display->display_options['menu']['name'] = 'management';