浏览代码

Added sidebar and collapsible fields to generic layout

Stephen Ficklin 9 年之前
父节点
当前提交
6324a60d64

+ 66 - 7
tripal_fields_layout/theme/templates/tripal_fields_layout_generic.tpl.php

@@ -1,16 +1,75 @@
 <?php
 
+drupal_add_js('misc/collapse.js');
 $panels = $variables['element']['#panels'];
 $fields = $variables['element']['#fields'];
 
+$horz_table = TRUE;
+
 // Group fields into panels
-foreach ($fields AS $panel_id => $field) { ?>
-  <div id="" class="tripal-biodata-panel"> <?php
-    if ($panels[$panel_id] != 'Base Content') {
-      print '<h2>' . $panels[$panel_id] . '</h2>';
+$content = '';
+$toc = '';
+foreach ($panels AS $panel_id => $panel) {
+  $panel_fields = $fields[$panel_id];
+  $collapsible_item = array('element' => array());
+
+  // If the format is horizontal table then format the fields in tabular format.
+  if ($horz_table) {
+    $rows = array();
+    foreach ($panel_fields as $field) {
+      $rows[] = array(
+        array(
+          'data' => $field['#title'],
+          'header' => TRUE,
+          'width' => '20%',
+        ),
+        $field[0]['#markup']
+      );
     }
-    print render($field); ?>
-  </div> <?php
+    $collapsible_item['element']['#description'] = theme_table(array(
+      'header' => array(),
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => '',  // TODO: need to add an ID
+        'class' => 'tripal-data-table'
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    ));
+  }
+  // If no format is provided then use the default Drupal render.
+  else {
+    $collapsible_item['element']['#description'] = render($panel_fields);
+  }
+
+  // If this is not the base content then the field should be collapsible.
+  if ($panel->name != 'te_base') {
+    $collapsible_item['element']['#title'] = $panel->label;
+    $collapsible_item['element']['#children'] = '';
+    $collapsible_item['element']['#attributes']['class'][] = 'collapsible';
+    $collapsible_item['element']['#attributes']['class'][] = 'collapsed';
+    $toc_item_id = $panel_id;
+    $toc .= "<div class=\"tripal_toc_list_item\"><a id=\"" . $panel->name . "\" class=\"tripal_toc_list_item_link\" href=\"?pane=" . $panel->name . "\">" . $panel->label . "</a></div>";
+    $content .= theme('fieldset', $collapsible_item);
+  }
+  // The base field should just be the fields
+  else {
+    $content .= render($panel_fields);
+  }
 }
 
-print render($content);
+$bundle_type = ''; // TODO: need to add the bundle type ?>
+<table id ="tripal-<?php print $bundle_type?>-contents-table" class="tripal-contents-table">
+  <tr class="tripal-contents-table-tr">
+    <td nowrap class="tripal-contents-table-td tripal-contents-table-td-toc" align="left"><?php
+      print $toc; ?>
+    </td>
+    <td class="tripal-contents-table-td-data" align="left" width="100%"> <?php
+
+      // print the rendered content
+      print $content; ?>
+    </td>
+  </tr>
+</table>

+ 2 - 1
tripal_fields_layout/tripal_fields_layout.module

@@ -523,6 +523,7 @@ function tripal_fields_layout_entity_view($entity, $type, $view_mode, $langcode)
         $results = db_select('tripal_panels', 'tp')
           ->fields('tp', array('panel_id','name', 'label'))
           ->condition('bundle_id', $bundle->id)
+          ->orderBy('tp.weight', 'ASC')
           ->execute();
 
         $panels = array();
@@ -533,7 +534,7 @@ function tripal_fields_layout_entity_view($entity, $type, $view_mode, $langcode)
             $disabled_panel_id = $row->panel_id;
           }
           else {
-            $panels[$row->panel_id] = $row->label;
+            $panels[$row->panel_id] = $row;
             $fields[$row->panel_id] = array();
           }
         }