Browse Source

Added ability to order links to TOC

Stephen Ficklin 10 years ago
parent
commit
bebdbb2a85

+ 2 - 4
tripal_core/api/tripal_core.chado_nodes.properties.api.inc

@@ -236,14 +236,12 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
 
   // Get property types for the select list. If the user has provided a set
   // then use those, otherwise get them from the cvterm table for specified cv.
-  if (isset($details['select_options']) and
-      is_array($details['select_options']) and
-      count($details['select_options']) > 0) {
+  if (array_key_exists('select_options', $details) and
+      is_array($details['select_options'])) {
     $property_options = $details['select_options'];
   }
   // if the select options are not provided then try to get them on our own
   else {
-
     // if the vocabulary name is provided in the details then use that to
     // get the terms
     if (isset($details['cv_name'])) {

+ 51 - 11
tripal_core/includes/tripal_core.toc.inc

@@ -59,10 +59,23 @@ function tripal_core_node_toc_form($form, &$form_state, $node) {
       $toc_title = $element['#tripal_toc_title'];
       $toc_weight = $element['#weight'];
       $toc_hide = $element['#hide'];
-      $form['toc_items'][$toc_id]['title'] = array(
-        '#type' => 'textfield',
-        '#default_value' => $toc_title,
-      );
+
+      // If this element is a link then we don't want to allow the user
+      // to change the title as the link title is changed by using the
+      // interface that created the link.
+      $is_link = array_key_exists('#is_link', $element) ? $element['#is_link'] : FALSE;
+      if (!$is_link) {
+        $form['toc_items'][$toc_id]['title'] = array(
+          '#type' => 'textfield',
+          '#default_value' => $toc_title,
+        );
+      }
+      else {
+        $form['toc_items'][$toc_id]['title'] = array(
+          '#markup' => '<i>link title:</i> ' . $toc_title,
+          '#value' => $toc_title,
+        );
+      }
       $form['toc_items'][$toc_id]['hide'] = array(
         '#type' => 'checkbox',
         '#default_value' => $toc_hide,
@@ -158,7 +171,7 @@ function theme_tripal_node_toc_items_table($variables) {
  * @param $b
  */
 function theme_tripal_node_sort_toc_items($a, $b) {
-  
+
   if ($a['weight']['#value'] < $b['weight']['#value']) {
     return -1;
   }
@@ -178,7 +191,7 @@ function tripal_core_node_toc_form_validate($form, &$form_state) {
 
   // Iterate through the TOC items and validate.
   foreach ($toc_items as $toc_id => $item) {
-    if (!$item['title']) {
+    if (array_key_exists('title', $item) and !$item['title']) {
       form_set_error('toc_items][' . $toc_id, "Please provide a valid title.");
     }
   }
@@ -204,7 +217,7 @@ function tripal_core_node_toc_form_submit($form, &$form_state) {
           ->fields(array(
             'node_type' => $node->type,
             'key' => $toc_id,
-            'title' => $item['title'],
+            'title' => array_key_exists('title', $item) ? $item['title'] : '',
             'weight' => $item['weight'],
             'nid' => $node->nid,
             'hide' => $item['hide'],
@@ -309,8 +322,21 @@ function tripal_core_node_view_build_toc(&$build) {
         foreach (element_children($build[$key]) as $index) {
           $element = $build[$key][$index];
           $weight = 0;
-          $toc_item_id = "resource-$index";
-          
+          $hide = 0;
+          $toc_item_id = "resource-link-$index";
+
+          // Get any overrides for this key.
+          $overrides = tripal_core_get_toc_overrides($nid, $toc_item_id, $node_type);
+          $weight = $overrides['weight'] ? $overrides['weight'] : $weight;
+          $hide = $overrides['hide'] ? $overrides['hide'] : $hide;
+
+          // If the element should be hidden then unset this key the build
+          // array continue to the next one
+          if ($mode == "display" and $overrides['hide'] == 1) {
+            continue;
+          }
+
+          // Add the link to the TOC
           $parts = explode("|", $element['#markup']);
           if (count($parts) == 2) {
             $toc[$weight][$parts[0]] = "<div id=\"$toc_item_id\" class=\"tripal_toc_list_item\">" . l($parts[0], $parts[1], array('attributes' => array('target' => '_blank'))) . "</div>";
@@ -318,9 +344,21 @@ function tripal_core_node_view_build_toc(&$build) {
           else {
             $toc[$weight][$parts[0]] = "<div id=\"$toc_item_id\" class=\"tripal_toc_list_item\">" . $element['#markup'] . "</div>";
           }
-          // remove this link from the build array as we've moved it to appear in the TOC
-          unset($build[$key]);
+
+          // Add to the build array but do not add markup. This way 
+          // when the TOC is managed by the node 'TOC' menu these links can
+          // be ordered as well.
+          $build[$toc_item_id]['#toc_handled'] = TRUE;
+          $build[$toc_item_id]['#tripal_toc_id'] = $toc_item_id;
+          $build[$toc_item_id]['#tripal_toc_title'] = $parts[0];
+          $build[$toc_item_id]['#weight'] = $weight;
+          $build[$toc_item_id]['#hide'] = $hide;
+          $build[$toc_item_id]['#is_link'] = TRUE;
+
         }
+        // Remove the orilink from the build array as we've moved it to
+        // appear in the TOC
+        unset($build[$key]);
         continue;
       }
       if ($key == "field_resource_titles") {
@@ -710,6 +748,7 @@ function tripal_core_content_type_toc_form_submit($form, &$form_state) {
       // First delete any settings for this content type
       db_delete('tripal_toc')
         ->condition('node_type', $content_type)
+        ->isNull('nid')
         ->execute();
 
       // Second add in any new settings for this node
@@ -737,6 +776,7 @@ function tripal_core_content_type_toc_form_submit($form, &$form_state) {
       // First delete any settings for this node
       db_delete('tripal_toc')
         ->condition('node_type', $content_type)
+        ->isNull('nid')
         ->execute();
 
       drupal_set_message("The TOC is reset to defaults for this content type.");

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

@@ -1044,7 +1044,7 @@ function tripal_set_default_cv($table, $field, $cv_name, $cv_id = FALSE) {
  *   cvterm table for which the default vocabulary will be set
  *
  * @return
- *   The cv array of the default vocabulary or an empty array if not
+ *   The cv object of the default vocabulary or an empty array if not
  *   available.
  */
 function tripal_get_default_cv($table, $field) {

+ 16 - 6
tripal_library/includes/tripal_library.chado_node.inc

@@ -124,16 +124,26 @@ function chado_library_form($node, &$form_state) {
   );
 
   // get the list of library types
+  $lt_cv = tripal_get_default_cv("library", "type_id");
   $types = tripal_get_cvterm_default_select_options('library', 'type_id', 'library types');
   $types[0] = 'Select a Type';
+  $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/chado/tripal_cv/cv/" . $lt_cv->cv_id . "/cvterm/add",
+       array('attributes' => array('target' => '_blank'))
+      ),
+     TRIPAL_INFO, array('return_html' => TRUE)
+  );
 
   $form['library_type'] = array(
-    '#title'       => t('Library Type'),
-    '#type'        => t('select'),
-    '#description' => t("Choose the library type."),
-    '#required'    => TRUE,
+    '#title'         => t('Library Type'),
+    '#type'          => t('select'),
+    '#description'   => t("Choose the library type."),
+    '#required'      => TRUE,
     '#default_value' => $library_type,
-    '#options'     => $types,
+    '#options'       => $types,
+    '#suffix'        => $lt_message,
   );
 
   // get the list of organisms
@@ -173,7 +183,7 @@ function chado_library_form($node, &$form_state) {
   // to exclude the 'Library Description' term since it has it's own form element above
   if ($prop_cv->name == 'library_property') {
     // Generate our own select list so we can exclude the description element
-    $cv_result = chado_select_record('cv',array('cv_id'),array('name' => 'library_property'));
+    $cv_result = chado_select_record('cv', array('cv_id'), array('name' => 'library_property'));
     $cv_id = $cv_result[0]->cv_id;
     $select_options = tripal_get_cvterm_select_options($cv_id);
     $descrip_id = array_search('Library Description', $select_options);