tripal_fields_layout_generic.tpl.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. drupal_add_js('misc/form.js');
  3. drupal_add_js('misc/collapse.js');
  4. drupal_add_js(drupal_get_path('module','tripal_fields_layout') . '/theme/js/tripal_fields_layout.js');
  5. $panels = $variables['element']['#panels'];
  6. $fields = $variables['element']['#fields'];
  7. // TODO, the horz_table variable needs to be set in a variable and checked here.
  8. $table = TRUE;
  9. // Group fields into panels
  10. $content = '';
  11. $toc = '';
  12. $has_base_panel_only = TRUE;
  13. foreach ($panels AS $panel_id => $panel) {
  14. if ($panel->name != 'te_base') {
  15. $has_base_panel_only = FALSE;
  16. }
  17. $panel_settings = unserialize($panel->settings);
  18. $table_layout_group = key_exists('table_layout', $panel_settings) ? $panel_settings['table_layout'] : array();
  19. $panel_fields = $fields[$panel_id];
  20. // Rearrange fields into groups for each panel
  21. $table_layout = array();
  22. $no_group = array();
  23. // Keyed by field's '#weight' and '#field_name so we can ksort() by weight
  24. foreach ($panel_fields AS $field) {
  25. if (in_array($field['#field_name'], $table_layout_group)) {
  26. $table_layout [$field['#weight'] . $field['#field_name']] = $field;
  27. }
  28. else {
  29. $no_group [$field['#weight'] . $field['#field_name']] = $field;
  30. }
  31. }
  32. // Render horizontal table
  33. $table = '';
  34. if (count($table_layout) != 0) {
  35. ksort($table_layout, SORT_NUMERIC);
  36. $rows = array();
  37. foreach ($table_layout as $field) {
  38. $rows[] = array(
  39. array(
  40. 'data' => $field['#title'],
  41. 'header' => TRUE,
  42. 'width' => '20%',
  43. 'nowrap' => 'nowrap'
  44. ),
  45. $field[0]['#markup']
  46. );
  47. }
  48. $table = theme_table(array(
  49. 'header' => array(),
  50. 'rows' => $rows,
  51. 'attributes' => array(
  52. 'id' => '', // TODO: need to add an ID
  53. 'class' => 'tripal-data-horz-table'
  54. ),
  55. 'sticky' => FALSE,
  56. 'caption' => '',
  57. 'colgroups' => array(),
  58. 'empty' => '',
  59. ));
  60. }
  61. // Render field not in a group
  62. $ungrouped = '';
  63. if (count($no_group) != 0) {
  64. ksort($no_group, SORT_NUMERIC);
  65. foreach ($no_group as $field) {
  66. $ungrouped .= render($field);
  67. }
  68. }
  69. $output = $table . $ungrouped ;
  70. // If this is a base content, do not organize the content in a fieldset
  71. if ($panel->name == 'te_base') {
  72. $content .= '<div class="tripal_panel-base_panel">' . $output . '</div>';
  73. } else {
  74. $collapsible_item = array('element' => array());
  75. $collapsible_item['element']['#description'] = $output;
  76. $collapsible_item['element']['#title'] = $panel->label;
  77. $collapsible_item['element']['#children'] = '';
  78. $collapsible_item['element']['#attributes']['id'] = 'tripal_panel-fieldset-' . $panel->name;
  79. $collapsible_item['element']['#attributes']['class'][] = 'tripal_panel-fieldset';
  80. $collapsible_item['element']['#attributes']['class'][] = 'collapsible';
  81. $collapsible_item['element']['#attributes']['class'][] = 'collapsed';
  82. $toc_item_id = $panel_id;
  83. $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>";
  84. $content .= theme('fieldset', $collapsible_item);
  85. }
  86. }
  87. $bundle_type = ''; // TODO: need to add the bundle type
  88. if ($has_base_panel_only) { ?>
  89. <div id ="tripal-<?php print $bundle_type?>-contents-box"> <?php
  90. // print the rendered content
  91. print $content; ?>
  92. </div> <?php
  93. } else { ?>
  94. <table id ="tripal-<?php print $bundle_type?>-contents-table" class="tripal-contents-table">
  95. <tr class="tripal-contents-table-tr"> <?php
  96. ?>
  97. <td nowrap class="tripal-contents-table-td tripal-contents-table-td-toc" align="left"><?php
  98. print $toc; ?>
  99. </td>
  100. <td class="tripal-contents-table-td-data" align="left" width="100%"> <?php
  101. // print the rendered content
  102. print $content; ?>
  103. </td>
  104. </tr>
  105. </table> <?php
  106. } ?>