tripal_fields_layout_generic.tpl.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. // Render fields in a table
  8. function render_table ($table_layout) {
  9. $table = '';
  10. if (count($table_layout) != 0) {
  11. $rows = array();
  12. foreach ($table_layout as $field) {
  13. $rows[] = array(
  14. array(
  15. 'data' => $field['#title'],
  16. 'header' => TRUE,
  17. 'width' => '20%',
  18. 'nowrap' => 'nowrap'
  19. ),
  20. $field[0]['#markup']
  21. );
  22. }
  23. $table = theme_table(array(
  24. 'header' => array(),
  25. 'rows' => $rows,
  26. 'attributes' => array(
  27. 'id' => '', // TODO: need to add an ID
  28. 'class' => 'tripal-data-horz-table'
  29. ),
  30. 'sticky' => FALSE,
  31. 'caption' => '',
  32. 'colgroups' => array(),
  33. 'empty' => '',
  34. ));
  35. }
  36. return $table;
  37. }
  38. // Render fields not in a group
  39. function render_fields($no_group) {
  40. $ungrouped = '';
  41. if (count($no_group) != 0) {
  42. foreach ($no_group as $field) {
  43. $ungrouped .= render($field);
  44. }
  45. }
  46. return $ungrouped;
  47. }
  48. // Process fields in panels
  49. $content = '';
  50. $toc = '';
  51. $has_base_panel_only = TRUE;
  52. foreach ($panels AS $panel_id => $panel) {
  53. if ($panel->name != 'te_base') {
  54. $has_base_panel_only = FALSE;
  55. }
  56. $panel_settings = unserialize($panel->settings);
  57. $table_layout_group = key_exists('table_layout', $panel_settings) ? $panel_settings['table_layout'] : array();
  58. // Rearrange fields into groups for each panel
  59. $panel_fields = $fields[$panel_id];
  60. // Keyed by field's '#weight' and '#field_name so we can ksort() by weight
  61. $weighed_fields = array();
  62. foreach ($panel_fields AS $field) {
  63. $weighed_fields [$field['#weight'] . $field['#field_name']] = $field;
  64. }
  65. ksort($weighed_fields, SORT_NUMERIC);
  66. // Render weighed fields
  67. $table_layout = array();
  68. $no_group = array();
  69. $output = '';
  70. $current_layout = '';
  71. $counter = 0;
  72. foreach ($weighed_fields AS $field) {
  73. // The field is in a table
  74. if (in_array($field['#field_name'], $table_layout_group)) {
  75. if ($counter != 0 && $current_layout != 'Table') {
  76. $output .= render_fields($no_group);
  77. $no_group = array();
  78. }
  79. $table_layout [$field['#weight'] . $field['#field_name']] = $field;
  80. $current_layout = 'Table';
  81. }
  82. // The field is not in a table
  83. else {
  84. if ($counter != 0 && $current_layout != 'Default') {
  85. $output .= render_table($table_layout);
  86. $table_layout = array();
  87. }
  88. $no_group [$field['#weight'] . $field['#field_name']] = $field;
  89. $current_layout = 'Default';
  90. }
  91. $counter ++;
  92. }
  93. if ($current_layout == 'Table') {
  94. $output .= render_table($table_layout);
  95. }
  96. else if ($current_layout == 'Default') {
  97. $output .= render_fields($no_group);
  98. }
  99. // If this is a base content, do not organize the content in a fieldset
  100. if ($panel->name == 'te_base') {
  101. $content .= '<div class="tripal_panel-base_panel">' . $output . '</div>';
  102. } else {
  103. $collapsible_item = array('element' => array());
  104. $collapsible_item['element']['#description'] = $output;
  105. $collapsible_item['element']['#title'] = $panel->label;
  106. $collapsible_item['element']['#children'] = '';
  107. $collapsible_item['element']['#attributes']['id'] = 'tripal_panel-fieldset-' . $panel->name;
  108. $collapsible_item['element']['#attributes']['class'][] = 'tripal_panel-fieldset';
  109. $collapsible_item['element']['#attributes']['class'][] = 'collapsible';
  110. $collapsible_item['element']['#attributes']['class'][] = 'collapsed';
  111. $toc_item_id = $panel_id;
  112. $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>";
  113. $content .= theme('fieldset', $collapsible_item);
  114. }
  115. }
  116. $bundle_type = ''; // TODO: need to add the bundle type
  117. if ($has_base_panel_only) { ?>
  118. <div id ="tripal-<?php print $bundle_type?>-contents-box"> <?php
  119. // print the rendered content
  120. print $content; ?>
  121. </div> <?php
  122. } else { ?>
  123. <table id ="tripal-<?php print $bundle_type?>-contents-table" class="tripal-contents-table">
  124. <tr class="tripal-contents-table-tr"> <?php
  125. ?>
  126. <td nowrap class="tripal-contents-table-td tripal-contents-table-td-toc" align="left"><?php
  127. print $toc; ?>
  128. </td>
  129. <td class="tripal-contents-table-td-data" align="left" width="100%"> <?php
  130. // print the rendered content
  131. print $content; ?>
  132. </td>
  133. </tr>
  134. </table> <?php
  135. } ?>