Browse Source

Periodic check-in

Stephen Ficklin 6 years ago
parent
commit
73d9e662ac

+ 42 - 70
tripal/api/tripal.terms.api.inc

@@ -61,43 +61,6 @@ function hook_vocab_storage_info() {
   );
   );
 }
 }
 
 
-
-/**
- * Creates a form for specifying a term for TripalEntity creation.
- *
- * This hook allows the module that implements a vocabulary storage backend
- * to provide the form necessary to select a term that will then be used for
- * creating a new TripalEntity type.  Tripal will expect that a 'vocabulary' and
- * 'accession' are in the $form_state['storage'] array. The 'vocabulary' and
- * must be the abbreviated uppercase vocabulary for the vocabulary (e.g. 'RO',
- * 'SO', 'PATO', etc.).  The 'accession' must be the unique term ID (or
- * accession) for the term in the vocabulary.
- *
- * @param $form
- * @param $form_state
- *
- * @return
- *   A form object.
- *
- * @ingroup tripal_terms_api
- */
-function hook_vocab_select_term_form(&$form, &$form_state) {
-
-  return $form;
-}
-
-/**
- * Validates the hook_vocab_select_term_form().
- *
- * @param $form
- * @param $form_state
- *
- * @ingroup tripal_terms_api
- */
-function hook_vocab_select_term_form_validate($form, &$form_state) {
-
-}
-
 /**
 /**
  * Provides a form for importing vocabularies and their terms.
  * Provides a form for importing vocabularies and their terms.
  *
  *
@@ -618,17 +581,24 @@ function tripal_get_vocabularies() {
  */
  */
 function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
 function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
     $title = 'Vocabulary Term', $description = '', $is_required,
     $title = 'Vocabulary Term', $description = '', $is_required,
-    $field_name = '', $delta = 0 ) {
+    $field_name = '', $delta = 0, $callback = '') {
   
   
   $ajax_wrapper_id = 'tripal-vocab-select-form-' . $delta;
   $ajax_wrapper_id = 'tripal-vocab-select-form-' . $delta;
   if ($field_name) {
   if ($field_name) {
     $ajax_wrapper_id = $field_name . '-' . $delta;
     $ajax_wrapper_id = $field_name . '-' . $delta;
   }
   }
+  
+  if (!$callback) {
+    $callback = 'tripal_get_term_lookup_form_ajax_callback';
+  }
 
 
   $term_name = $default_name;
   $term_name = $default_name;
   if (array_key_exists('values', $form_state) and array_key_exists('term_name', $form_state['values'])) {
   if (array_key_exists('values', $form_state) and array_key_exists('term_name', $form_state['values'])) {
     $term_name = $form_state['values']['term_name'];
     $term_name = $form_state['values']['term_name'];
   }
   }
+  if (array_key_exists('input', $form_state) and array_key_exists('term_name', $form_state['input'])) {
+    $term_name = $form_state['input']['term_name'];
+  }
   if ($field_name and array_key_exists('input', $form_state) and array_key_exists($field_name, $form_state['input'])) {
   if ($field_name and array_key_exists('input', $form_state) and array_key_exists($field_name, $form_state['input'])) {
     $term_name = $form_state['input'][$field_name]['und'][$delta]['term_match']['term_name'];
     $term_name = $form_state['input'][$field_name]['und'][$delta]['term_match']['term_name'];
   }
   }
@@ -642,7 +612,7 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
   $form_state['storage'][$ajax_wrapper_id]['term_match_field'] = $field_name;
   $form_state['storage'][$ajax_wrapper_id]['term_match_field'] = $field_name;
   $form_state['storage'][$ajax_wrapper_id]['term_match_delta'] = $delta;
   $form_state['storage'][$ajax_wrapper_id]['term_match_delta'] = $delta;
 
 
-  $form['term_match'] = array(
+  $form['term_match' . $delta] = array(
     '#type' => 'fieldset',
     '#type' => 'fieldset',
     '#collapsible' => FALSE,
     '#collapsible' => FALSE,
     '#collapsed' => FALSE,
     '#collapsed' => FALSE,
@@ -650,7 +620,7 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
     '#prefix' => '<div id = "' . $ajax_wrapper_id . '">',
     '#prefix' => '<div id = "' . $ajax_wrapper_id . '">',
     '#suffix' => '</div>',
     '#suffix' => '</div>',
   );
   );
-  $form['term_match']['term_name'] = array(
+  $form['term_match' . $delta]['term_name' . $delta] = array(
     '#title'  => t('Type'),
     '#title'  => t('Type'),
     '#type' => 'textfield',
     '#type' => 'textfield',
     '#description' => $description,
     '#description' => $description,
@@ -658,14 +628,14 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
     '#default_value' => $term_name,
     '#default_value' => $term_name,
     '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
     '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
   );
   );
-  $form['term_match']['select_button'] = array(
+  $form['term_match' . $delta]['select_button' . $delta] = array(
     '#type' => 'button',
     '#type' => 'button',
     '#value' => t('Lookup Term'),
     '#value' => t('Lookup Term'),
     '#name' => 'select_cvterm_' . $ajax_wrapper_id,
     '#name' => 'select_cvterm_' . $ajax_wrapper_id,
     '#validate' => array(),
     '#validate' => array(),
     '#limit_validation_errors' => array(),
     '#limit_validation_errors' => array(),
     '#ajax' => array(
     '#ajax' => array(
-      'callback' => "tripal_get_term_lookup_form_ajax_callback",
+      'callback' => $callback,
       'wrapper' => $ajax_wrapper_id,
       'wrapper' => $ajax_wrapper_id,
       'effect' => 'fade',
       'effect' => 'fade',
       'method' => 'replace'
       'method' => 'replace'
@@ -676,12 +646,12 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
   // matching terms in the database and let them select among any matches.
   // matching terms in the database and let them select among any matches.
   if ($term_name) {
   if ($term_name) {
     $submit_disabled = TRUE;
     $submit_disabled = TRUE;
-    $form['term_match']['terms_list'] = array(
+    $form['term_match' . $delta]['terms_list' . $delta] = array(
       '#type' => 'fieldset',
       '#type' => 'fieldset',
       '#title' => t('Matching Terms'),
       '#title' => t('Matching Terms'),
-      '#description' => t('Please select the term the best matches the
-          content type you want to create. If the same term exists in
-          multiple vocabularies you will see more than one option below.')
+      '#description' => t('Please select the best matching term. If the 
+        same term exists in multiple vocabularies you will see more than 
+        one option below.')
     );
     );
     $match = array(
     $match = array(
       'name' => $term_name,
       'name' => $term_name,
@@ -700,23 +670,24 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
     foreach ($terms as $term) {
     foreach ($terms as $term) {
       // Save the user a click by setting the default value as 1 if there's
       // Save the user a click by setting the default value as 1 if there's
       // only one matching term.
       // only one matching term.
-      $default = FALSE;
+      $checked = FALSE;
       $attrs = array();
       $attrs = array();
       if ($num_terms == 0 and count($terms) == 1) {
       if ($num_terms == 0 and count($terms) == 1) {
-        $default = TRUE;
+        $checked = TRUE;
         $attrs = array('checked' => 'checked');
         $attrs = array('checked' => 'checked');
       }
       }
-      $term_element_name = 'term-' . $term->cvterm_id;
-      $form['term_match']['terms_list'][$term_element_name] = array(
+      $term_element_name = 'term-' . $term->cvterm_id  . '-' . $delta;
+      $definition = property_exists($term, 'definition') ? $term->definition : '';
+      $form['term_match' . $delta]['terms_list' . $delta][$term_element_name] = array(
         '#type' => 'checkbox',
         '#type' => 'checkbox',
         '#title' =>  $term->name,
         '#title' =>  $term->name,
-        '#default_value' => $default,
+        '#default_value' => $checked,
         '#attributes' => $attrs,
         '#attributes' => $attrs,
         '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
         '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
-        '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
-        '<br><b>Definition:</b>  ' . property_exists($term, 'definition') ? $term->definition : '',
+          '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
+          '<br><b>Definition:</b>  ' . $definition,
         '#ajax' => array(
         '#ajax' => array(
-          'callback' => "tripal_get_term_lookup_form_ajax_callback",
+          'callback' => $callback,
           'wrapper' => $ajax_wrapper_id,
           'wrapper' => $ajax_wrapper_id,
           'effect' => 'fade',
           'effect' => 'fade',
           'method' => 'replace'
           'method' => 'replace'
@@ -741,24 +712,25 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
       $term = $synonym->cvterm_id;
       $term = $synonym->cvterm_id;
       // Save the user a click by setting the default value as 1 if there's
       // Save the user a click by setting the default value as 1 if there's
       // only one matching term.
       // only one matching term.
-      $default = FALSE;
+      $checked = FALSE;
       $attrs = array();
       $attrs = array();
       if ($num_terms == 0 and count($terms) == 1) {
       if ($num_terms == 0 and count($terms) == 1) {
-        $default = TRUE;
+        $checked = TRUE;
         $attrs = array('checked' => 'checked');
         $attrs = array('checked' => 'checked');
       }
       }
-      $term_element_name = 'term-' . $term->cvterm_id;
-      $form['term_match']['terms_list'][$term_element_name] = array(
+      $term_element_name = 'term-' . $term->cvterm_id . '-' . $delta;
+      $definition = property_exists($term, 'definition') ? $term->definition : '';
+      $form['term_match' . $delta]['terms_list' . $delta][$term_element_name] = array(
         '#type' => 'checkbox',
         '#type' => 'checkbox',
         '#title' =>  $term->name,
         '#title' =>  $term->name,
-        '#default_value' => $default,
+        '#default_value' => $checked,
         '#attributes' => $attrs,
         '#attributes' => $attrs,
         '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
         '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
         '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
         '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
-        '<br><b>Definition:</b>  ' . $term->definition . 
+        '<br><b>Definition:</b>  ' . $definition . 
         '<br><b>Synonym:</b> ' . $synonym->synonym,
         '<br><b>Synonym:</b> ' . $synonym->synonym,
         '#ajax' => array(
         '#ajax' => array(
-          'callback' => "tripal_get_term_lookup_form_ajax_callback",
+          'callback' => $callback,
           'wrapper' => $ajax_wrapper_id,
           'wrapper' => $ajax_wrapper_id,
           'effect' => 'fade',
           'effect' => 'fade',
           'method' => 'replace'
           'method' => 'replace'
@@ -767,14 +739,14 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
       
       
       if (array_key_exists('values', $form_state) and array_key_exists($term_element_name, $form_state['values']) and
       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) {
         $form_state['values'][$term_element_name] == 1) {
-          $selected_term = $term;
-        }
-        $num_terms++;
+        $selected_term = $term;
+      }
+      $num_terms++;
     }
     }
     
     
     
     
     if ($num_terms == 0) {
     if ($num_terms == 0) {
-      $form['term_match']['terms_list']['none'] = array(
+      $form['term_match'. $delta]['terms_list'. $delta]['none'. $delta] = array(
         '#type' => 'item',
         '#type' => 'item',
         '#markup' => '<i>' . t('There is no term that matches the entered text.') . '</i>'
         '#markup' => '<i>' . t('There is no term that matches the entered text.') . '</i>'
       );
       );
@@ -804,8 +776,8 @@ function tripal_get_term_lookup_form_result($form, $form_state, $field_name = ''
   $values = array();
   $values = array();
   $selected = array();
   $selected = array();
   if ($field_name) {
   if ($field_name) {
-    if (array_key_exists('term_match', $form_state['values'][$field_name]['und'][$delta]) and 
-      array_key_exists('terms_list', $form_state['values'][$field_name]['und'][$delta]['term_match'])) {
+    if (array_key_exists('term_match' . $delta, $form_state['values'][$field_name]['und'][$delta]) and 
+        array_key_exists('terms_list' . $delta, $form_state['values'][$field_name]['und'][$delta]['term_match'. $delta])) {
       $values = $form_state['values'][$field_name]['und'][$delta]['term_match']['terms_list'];
       $values = $form_state['values'][$field_name]['und'][$delta]['term_match']['terms_list'];
     }
     }
   }
   }
@@ -816,7 +788,7 @@ function tripal_get_term_lookup_form_result($form, $form_state, $field_name = ''
   if (is_array($values)) {
   if (is_array($values)) {
     foreach ($values as $key => $value) {
     foreach ($values as $key => $value) {
       $matches = array();
       $matches = array();
-      if (preg_match("/^term-(\d+)$/", $key, $matches) and $values['term-' . $matches[1]]) {
+      if (preg_match("/^term-(\d+)-$delta$/", $key, $matches) and $values['term-' . $matches[1] . '-' . $delta]) {
         $cvterm_id = $matches[1];
         $cvterm_id = $matches[1];
         $selected[] = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
         $selected[] = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
       }
       }
@@ -839,9 +811,9 @@ function tripal_get_term_lookup_form_ajax_callback($form, $form_state) {
   // If this form is in a field then we need to dig a bit deeper to return
   // If this form is in a field then we need to dig a bit deeper to return
   // the form elements.
   // the form elements.
   if ($field_name) {
   if ($field_name) {
-    return $form[$field_name]['und'][$delta]['term_match'];
+    return $form[$field_name]['und'][$delta]['term_match'. $delta];
   }
   }
   else {
   else {
-    return $form['term_match'];
+    return $form['term_match' . $delta];
   }
   }
 }
 }

+ 211 - 184
tripal/includes/TripalBundleUIController.inc

@@ -537,6 +537,7 @@ function tripal_bundle_access($op, $type = NULL, $account = NULL) {
  */
  */
 function tripal_admin_add_type_form($form, &$form_state) {
 function tripal_admin_add_type_form($form, &$form_state) {
 
 
+  // Make sure we have a storage backend for managing content types.
   $stores = module_invoke_all('vocab_storage_info');
   $stores = module_invoke_all('vocab_storage_info');
   if (!is_array($stores) or count($stores) == 0) {
   if (!is_array($stores) or count($stores) == 0) {
     tripal_set_message('A storage backend is not enabled for managing
     tripal_set_message('A storage backend is not enabled for managing
@@ -545,202 +546,209 @@ function tripal_admin_add_type_form($form, &$form_state) {
           and return to create new Tripal content types.', TRIPAL_NOTICE);
           and return to create new Tripal content types.', TRIPAL_NOTICE);
     return;
     return;
   }
   }
-  $keys = array_keys($stores);
-  $module = $stores[$keys[0]]['module'];
-  $function = $module . '_vocab_select_term_form';
-  if (function_exists($function)) {
-    $form = $function($form, $form_state);
+  
+  // Set the stage to step1 if it isn't already set.
+  if (!isset($form_state['stage'])) $form_state['stage'] = 'step1';
+  $stage = $form_state['stage'];
+  
+  
+  // Get the selected term.
+  if (array_key_exists('values', $form_state) and
+      array_key_exists('term', $form_state['values'])) {
+    $selected_term = $form_state['values']['term'];
+  }
+  else {
+    $selected = tripal_get_term_lookup_form_result($form, $form_state);
+    $selected_term = $selected[0];
+  }
+    
+  // Get the selected storage element.
+  $default_store = 'term_chado_storage';
+  if (array_key_exists('values', $form_state) and
+      array_key_exists('store_select', $form_state['values'])) {
+    $default_store = $form_state['values']['store_select'];
   }
   }
+  
 
 
-  $term_name = array_key_exists('values', $form_state) ? $form_state['values']['term_name'] : '';
+  // Handle the different stages:
+  if ($stage == 'step1') {
+    tripal_admin_add_type_form_step1($form, $form_state);
+  }
+  if ($form_state['stage'] == 'step2') {
+    tripal_admin_add_type_form_step1_summary($form, $form_state, $selected_term);
+    tripal_admin_add_type_form_step2($form, $form_state, $stores, $selected_term, $default_store);
+  }
+  if ($form_state['stage'] == 'step3') {
+    tripal_admin_add_type_form_step1_summary($form, $form_state, $selected_term);
+    tripal_admin_add_type_form_step2_summary($form, $form_state, $stores, $selected_term, $default_store);
+    tripal_admin_add_type_form_step3($form, $form_state, $stores, $selected_term, $default_store);
+  }
+  
+  $form['#prefix'] = '<div id = "tripal-add-type-form">';
+  $form['#suffix'] = '</div>';
+  
+  return $form;
+}
 
 
-  // If no term has been selected yet then provide the auto complete field.
-  $form['term_name'] = array(
-    '#title'       => t('Content Type'),
-    '#type'        => 'textfield',
-    '#description' => t("The content type must be the name of a term in
+/**
+ * Builds step1 of the tripal_admin_add_type_form()
+ */
+function tripal_admin_add_type_form_step1(&$form, &$form_state) {
+  
+  // Get the term name from the form_state.
+  $term_name = '';
+  if (array_key_exists('values', $form_state) and array_key_exists('term_name0', $form_state['values'])) {
+    $term_name = $form_state['values']['term_name0'];
+  }
+  if (array_key_exists('input', $form_state) and array_key_exists('term_name0', $form_state['input'])) {
+    $term_name = $form_state['input']['term_name0'];
+  }
+  
+  // Get the term lookup form.
+  $description = t("The content type must be the name of a term in
         a controlled vocabulary and the controlled vocabulary should
         a controlled vocabulary and the controlled vocabulary should
         already be loaded into Tripal.  For example, to create a content
         already be loaded into Tripal.  For example, to create a content
         type for storing 'genes', use the 'gene' term from the
         type for storing 'genes', use the 'gene' term from the
-        Sequence Ontology (SO)."),
-    '#required'    => TRUE,
-    '#default_value' => $term_name,
-    '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
-  );
-  $form['select_button'] = array(
+        Sequence Ontology (SO).");
+  tripal_get_term_lookup_form($form, $form_state, $term_name,
+    'Step 1: Content Type', $description, TRUE, '', 0,
+    'tripal_admin_add_type_form_ajax_callback');
+  
+  if ($term_name) {
+    $form['term_match']['step1-continue'] = array(
+      '#type' => 'submit',
+      '#value' => t('Continue'),
+      '#name' => 'step1-continue',
+    );
+  }
+}
+
+/**
+ * Provides a summary of values selected in Step 1. 
+ */
+function tripal_admin_add_type_form_step1_summary(&$form, &$form_state, $selected_term) {
+     
+  $form['term'] = [
+    '#type' => 'value',
+    '#value' => $selected_term,
+  ];
+  
+  $form['term_summary'] = [
+    '#type' => 'fieldset',
+    '#title' => t('Step 1: Content Type'),
+    '#description' => '',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  ];
+  $definition = property_exists($selected_term, 'definition') ? $selected_term->definition : '';
+  $form['term_summary']['details'] = [
+    '#type' => 'item',
+    '#title' => t('Term'),
+    '#markup' => '<b>Vocabulary:</b> ' . $selected_term->cv_id->name . ' (' . $selected_term->dbxref_id->db_id->name . ') ' . $selected_term->cv_id->definition .
+    '<br><b>Term: </b> ' . $selected_term->dbxref_id->db_id->name . ':' . $selected_term->dbxref_id->accession . '.  ' .
+    '<br><b>Definition:</b>  ' . $definition
+  ];
+  $form['term_summary']['step1-return'] = array(
     '#type' => 'submit',
     '#type' => 'submit',
-    '#value' => t('Lookup Term'),
-    '#name' => 'select_cvterm',
+    '#value' => t('Pick a different term'),
+    '#name' => 'step1-return',
+  );  
+}
+  
+/**
+ * Builds step1 of the tripal_admin_add_type_form()
+ */
+function tripal_admin_add_type_form_step2(&$form, &$form_state, $stores) {
+  
+  // Now let the user select where the data type will be stored.
+  $form['storage'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Step 2: Storage'),
+    '#description' => t('The primary record for each content of this type
+          must be stored in a single storage backend. Please select the
+          storage method and settings for this content type.')
+  );
+    
+  $store_options = array(0 => '-- Select --');
+  foreach ($stores as $store_type => $store) {
+    $store_options[$store_type] = $store['label'];
+  }
+
+  $form['storage']['store_select'] = array(
+    '#type' => 'select',
+    '#title' => 'Storage backend',
+    '#options' => $store_options,
+    '#default_value' => $default_store,
     '#ajax' => array(
     '#ajax' => array(
       'callback' => "tripal_admin_add_type_form_ajax_callback",
       'callback' => "tripal_admin_add_type_form_ajax_callback",
-      'wrapper' => "tripal-vocab-select-form",
+      'wrapper' => "tripal-add-type-form",
       'effect' => 'fade',
       'effect' => 'fade',
       'method' => 'replace'
       'method' => 'replace'
     ),
     ),
+    '#description' => 'Select a storage background for this content type.'
   );
   );
-  $form['#prefix'] = '<div id = "tripal-vocab-select-form">';
-  $form['#suffix'] = '</div>';
-
-  // 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(
-      '#type' => 'fieldset',
-      '#title' => t('Matching Terms'),
-      '#description' => t('Please select the term the best matches the
-          content type you want to create. If the same term exists in
-          multiple vocabularies you will see more than one option below.')
-    );
-    $match = array(
-      'name' => $term_name,
-    );
-    $terms = chado_generate_var('cvterm', $match, array('return_array' => TRUE));
-    $terms = chado_expand_var($terms, 'field', 'cvterm.definition');
-    $num_terms = 0;
-    $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. 
-      $default = FALSE;
-      $attrs = array();
-      if ($num_terms == 0 and count($terms) == 1) {
-        $default = TRUE;
-        $attrs = array('checked' => 'checked');
-      }
-      $term_element_name = 'term-' . $term->cvterm_id;
-      $form['terms_list'][$term_element_name] = array(
-        '#type' => 'checkbox',
-        '#title' =>  $term->name,
-        '#default_value' => $default,
-        '#attributes' => $attrs,
-        '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
-        '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
-        '<br><b>Definition:</b>  ' . $term->definition,
-        '#ajax' => array(
-          'callback' => "tripal_admin_add_type_form_ajax_callback",
-          'wrapper' => "tripal-vocab-select-form",
-          'effect' => 'fade',
-          'method' => 'replace'
-        ),
-      );
-
-      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 = $term;
-      }
-      $num_terms++;
-    }
-    
-    
-    // Next find terms that are synonyms
-    $match = array(
-      'synonym' => $term_name,
-    );
-    $termsyn = chado_generate_var('cvtermsynonym', $match, array('return_array' => TRUE));
-    // Let the user select from any matching terms. Sometimes there may be
-    // more than one that match.
-    foreach ($termsyn as $synonym) {
-      $term = $synonym->cvterm_id;
-      // 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($terms) == 1) {
-        $default = TRUE;
-        $attrs = array('checked' => 'checked');
-      }
-      $term_element_name = 'term-' . $term->cvterm_id;
-      $form['term_match']['terms_list'][$term_element_name] = array(
-        '#type' => 'checkbox',
-        '#title' =>  $term->name,
-        '#default_value' => $default,
-        '#attributes' => $attrs,
-        '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
-        '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
-        '<br><b>Definition:</b>  ' . $term->definition .
-        '<br><b>Synonym:</b> ' . $synonym->synonym,
-        '#ajax' => array(
-          'callback' => "tripal_admin_add_type_form_ajax_callback",
-          'wrapper' => "tripal-vocab-select-form",
-          'effect' => 'fade',
-          'method' => 'replace'
-        ),
-      );
-      
-      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 = $term;
-        }
-        $num_terms++;
-    }
-    if ($num_terms == 0) {
-      $form['terms_list']['none'] = array(
-        '#type' => 'item',
-        '#markup' => '<i>' . t('There is no term that matches the entered text.') . '</i>'
-      );
-      return $form;
-    }
-
-    // Now let the user select where the data type will be stored.
-    $form['storage'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Storage Settings'),
-      '#description' => t('The primary record for each content of this type
-          must be stored in a single storage backend. Please select the
-          storage method and settings for this content type.')
-    );
-
-    // 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 storage backend.
-    $default_store = 'term_chado_storage';
-    $store_options = array(0 => '-- Select --');
-    foreach ($stores as $store_type => $store) {
-      $store_options[$store_type] = $store['label'];
-    }
-    if (array_key_exists('values', $form_state) and
-        array_key_exists('store_select', $form_state['values'])) {
-      $default_store = $form_state['values']['store_select'];
-    }
-    $form['storage']['store_select'] = array(
-      '#type' => 'select',
-      '#title' => 'Storage backend',
-      '#options' => $store_options,
-      '#default_value' => $default_store,
-      '#ajax' => array(
-        'callback' => "tripal_admin_add_type_form_ajax_callback",
-        'wrapper' => "tripal-vocab-select-form",
-        'effect' => 'fade',
-        'method' => 'replace'
-      ),
-      '#description' => 'Select a storage background for this content type.'
+  
+  if ($default_store) {
+    $form['term_match']['step2-continue'] = array(
+      '#type' => 'submit',
+      '#value' => t('Continue'),
+      '#name' => 'step2-continue',
     );
     );
-
-    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',
-        '#value' => t('Create content type'),
-        '#name' => 'use_cvterm',
-        '#disabled' => $submit_disabled,
-      );
-    }
   }
   }
+}
 
 
+/**
+ * Provides a summary of values selected in Step 1.
+ */
+function tripal_admin_add_type_form_step2_summary(&$form, &$form_state, $stores) {
+  $default_store = $form_state['values']['store_select'];
+  $selected_store_module = $stores[$default_store]['module'];
+  
+  $form['store_select'] = [
+    '#type' => 'value',
+    '#value' => $default_store,
+  ];
+  
+  $form['store_summary'] = [
+    '#type' => 'fieldset',
+    '#title' => t('Step 2: Storage'),
+    '#description' => '',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  ];
+  $form['store_summary']['details'] = [
+    '#type' => 'item',
+    '#title' => t('Storage backend'),
+    '#markup' => $stores[$default_store]['label']
+  ];
+  $form['term_summary']['step1-return'] = array(
+    '#type' => 'submit',
+    '#value' => t('Pick a different term'),
+    '#name' => 'step1-return',
+  );  
+}
 
 
-  return $form;
+/**
+ * Builds step1 of the tripal_admin_add_type_form()
+ */
+function tripal_admin_add_type_form_step3(&$form, &$form_state, $stores) {
+  $default_store = $form_state['values']['store_select'];
+  
+  $selected_store_module = $stores[$default_store]['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',
+    '#value' => t('Create content type'),
+    '#name' => 'use_cvterm',
+    '#disabled' => $submit_disabled,
+  );
 }
 }
 /**
 /**
  * Implements an AJAX callback for the tripal_chado_vocab_select_term_form.
  * Implements an AJAX callback for the tripal_chado_vocab_select_term_form.
@@ -755,10 +763,31 @@ function tripal_admin_add_type_form_ajax_callback($form, $form_state) {
 function tripal_admin_add_type_form_validate($form, &$form_state) {
 function tripal_admin_add_type_form_validate($form, &$form_state) {
   $stores = module_invoke_all('vocab_storage_info');
   $stores = module_invoke_all('vocab_storage_info');
   $store_select = (isset($form_state['values']['store_select'])) ? $form_state['values']['store_select'] : NULL;
   $store_select = (isset($form_state['values']['store_select'])) ? $form_state['values']['store_select'] : NULL;
+  $clicked_button = $form_state['clicked_button']['#name'];
 
 
-  if (array_key_exists('clicked_button', $form_state) and
-      $form_state['clicked_button']['#name'] =='use_cvterm') {
-
+  if ($clicked_button =='step1-continue') {
+    $form_state['rebuild'] = TRUE;
+    $form_state['stage'] = 'step2';   
+    
+    $selected = tripal_get_term_lookup_form_result($form, $form_state);
+    if (count($selected) == 0) {
+      form_set_error('term_match][term_name', 'Please select a vocabulary term.');
+    }
+    if (count($selected) > 1) {
+      form_set_error('term_match][term_name', 'Please select only one vocabulary term.');
+    }
+    
+  }
+  if ($clicked_button =='step1-return') {
+    $form_state['rebuild'] = TRUE;
+    $form_state['stage'] = 'step1';
+  }
+  if ($clicked_button =='step2-continue') {
+    $form_state['rebuild'] = TRUE;
+    $form_state['stage'] = 'step3';
+  }
+  
+  if ($clicked_button =='use_cvterm') {       
     $cvterm_id = NULL;
     $cvterm_id = NULL;
 
 
     // Make sure we have a cvterm selected
     // Make sure we have a cvterm selected
@@ -797,8 +826,6 @@ function tripal_admin_add_type_form_validate($form, &$form_state) {
       }
       }
     }
     }
   }
   }
-  // For any other button click it's an AJAX call and we just want to reubild
-  // the form.
   else {
   else {
     $form_state['rebuild'] = TRUE;
     $form_state['rebuild'] = TRUE;
   }
   }

+ 51 - 99
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -845,10 +845,6 @@ function tripal_chado_field_storage_bundle_mapping_form($form, &$form_state,
       and $form_state['values']['type_column']) {
       and $form_state['values']['type_column']) {
     $default['type_column'] = $form_state['values']['type_column'];
     $default['type_column'] = $form_state['values']['type_column'];
   }
   }
-  if (array_key_exists('type_column_ignore', $form_state['values'])
-    and $form_state['values']['type_column_ignore']) {
-      $default['type_column_ignore'] = $form_state['values']['type_column_ignore'];
-  } 
   if (array_key_exists('prop_term_name', $form_state['values'])
   if (array_key_exists('prop_term_name', $form_state['values'])
       and $form_state['values']['prop_term_name']) {
       and $form_state['values']['prop_term_name']) {
     $default['prop_term_name'] = $form_state['values']['prop_term_name'];
     $default['prop_term_name'] = $form_state['values']['prop_term_name'];
@@ -865,6 +861,8 @@ function tripal_chado_field_storage_bundle_mapping_form($form, &$form_state,
       and $form_state['values']['chado_type_cv_id']) {
       and $form_state['values']['chado_type_cv_id']) {
     $default['cv_id'] = $form_state['values']['chado_type_cv_id'];
     $default['cv_id'] = $form_state['values']['chado_type_cv_id'];
   }
   }
+  
+  dpm($default);
 
 
   $form['selected_cvterm_id'] = array(
   $form['selected_cvterm_id'] = array(
     '#type' => 'value',
     '#type' => 'value',
@@ -929,17 +927,11 @@ function tripal_chado_field_storage_bundle_mapping_form($form, &$form_state,
 
 
   // If the type_column is set then we're done!  We know the deafult table
   // If the type_column is set then we're done!  We know the deafult table
   // and column to map this data type.
   // and column to map this data type.
-  if (!empty($default['type_column'])) {
+  if (!empty($default['type_column']) and $default['type_column'] != 'none') {
     $submit_disabled = FALSE;
     $submit_disabled = FALSE;
     return $form;
     return $form;
   }
   }
-  
-  // If the type column is not disabled and the user has not selected
-  // a type then return.
-  if (!$default['type_column_ignore'] and empty($default['type_column'])) {
-    return $form;
-  }
-    
+     
   // Let's set the names of the linker and prop table for use below.
   // Let's set the names of the linker and prop table for use below.
   $linker_table = $default['table'] . '_cvterm';
   $linker_table = $default['table'] . '_cvterm';
   $prop_table = $default['table']. 'prop';
   $prop_table = $default['table']. 'prop';
@@ -1025,7 +1017,7 @@ function tripal_chado_field_storage_bundle_mapping_form_add_type(&$form,
     '#description' => 'Please select the column in the "' .
     '#description' => 'Please select the column in the "' .
       $default['table'] . '" table that will identify a record as being of type "' .
       $default['table'] . '" table that will identify a record as being of type "' .
       $term_name . '". If you select "--None--" then you will be asked
       $term_name . '". If you select "--None--" then you will be asked
-      if you the type can be identified using a property or linker table.
+      if 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.',
       Only fields that have a foreign key to the cvterm table will be listed.',
     '#default_value' => $default_column,
     '#default_value' => $default_column,
     '#ajax' => array(
     '#ajax' => array(
@@ -1036,17 +1028,6 @@ function tripal_chado_field_storage_bundle_mapping_form_add_type(&$form,
     ),
     ),
     '#disabled' => $default_column_ignore,
     '#disabled' => $default_column_ignore,
   );
   );
-  $form['type_column_ignore'] = array(
-    '#type' => 'checkbox',
-    '#title' => 'The type column does not distinguish the type',
-    '#default_value' => $default_column_ignore,
-    '#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.
   // Set the default value so we can short circuit the form.
   $default['type_column'] = $default_column;
   $default['type_column'] = $default_column;
@@ -1140,90 +1121,61 @@ function tripal_chado_field_storage_bundle_mapping_form_add_prop(&$form,
   );
   );
 
 
   if ($default['use_prop'] == 'Yes') {
   if ($default['use_prop'] == 'Yes') {
+    
     $prop_term_name = $default['prop_term_name'];
     $prop_term_name = $default['prop_term_name'];
     $prop_term_value = $default['prop_term_value'];
     $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
+    
+    // We need a term lookup form for the property type.
+    $description = t('The content type "' . $term->name . '" must be
           associated with a property type.  The property type must be the
           associated with a property type.  The property type must be the
           name of a term in a controlled vocabulary and the controlled
           name of a term in a controlled vocabulary and the controlled
           vocabulary should already be loaded into Tripal. Please select
           vocabulary should already be loaded into Tripal. Please select
           the property type that will be used to identify records of this
           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');
+          type');
+    tripal_get_term_lookup_form($form, $form_state, $prop_term_name,
+      'Property Type', $description, TRUE, '', 1,
+      'tripal_admin_add_type_form_ajax_callback');
+    
+    // If a base table has a 'type_id' field then we must have the user
+    // specify the base table type as well.
+    $base_type_column = FALSE;
+    $schema = chado_get_schema($default['table']);
+    foreach ($schema['foreign keys'] as $fk_id => $details) { 
+      if ($details['table'] == 'cvterm') {
+        foreach ($details['columns'] as $fk_left => $fk_right) {
+          if ($fk_left == 'type_id') {
+            $base_type_column = 'type_id';
+          }
         }
         }
-        $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,
-      );
     }
     }
+    
+    if ($base_type_column) {
+      $description = t('The ' . $default['table'] . ' table of Chado requires 
+        that each record have a type.  You have indicated that this
+        content type is not distinguished by a column in the base tabe but
+        instead by a property.  However, the ' . $default['table'] . ' requires 
+        that a value be given for the ' . $base_type_column . '. Please indicate 
+        what this type should be.  For example.  If you are storing genetic 
+        markers in the feature table and you want to refer to all markers as
+        genetic markers but you specify the type of marker in the featureprop table
+        then here you would enter the term for the genetic marker and in the
+        Property Type you would indicate the term for the marker type.');
+      tripal_get_term_lookup_form($form, $form_state, $prop_term_name,
+        'Base Type', $description, TRUE, '', 1,
+        'tripal_admin_add_type_form_ajax_callback');
+    }
+
+    $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,
+    );
   }
   }
 }
 }
 
 

+ 1 - 1
tripal_chado/includes/tripal_chado.vocab_storage.inc

@@ -368,4 +368,4 @@ function tripal_chado_vocab_import_form_validate($form, &$form_state) {
 function tripal_chado_vocab_import_form_submit($form, &$form_state) {
 function tripal_chado_vocab_import_form_submit($form, &$form_state) {
   module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.obo_loader');
   module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.obo_loader');
   return tripal_cv_obo_form_submit($form, $form_state);
   return tripal_cv_obo_form_submit($form, $form_state);
-}
+}