table.html.tmpl 6.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
[%# 1.0@bugzilla.org %]
[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Bug Tracking System.
  #
  # The Initial Developer of the Original Code is Netscape Communications
  # Corporation. Portions created by Netscape are
  # Copyright (C) 1998 Netscape Communications Corporation. All
  # Rights Reserved.
  #
  # Contributor(s): Jouni Heikniemi <jouni@heikniemi.net>
  #
  #%]

[%# INTERFACE:
  #
  # columns: 
  #   array of hashes representing the columns in the table. 
  #   Each hash contains data for a single column. Hash keys:
  #     name: Name of the field in the data param
  #     heading: The text to print at the header cell
  #     contentlink: URI to which the content of a data cell shall be linked to.
31
  #                  Expressions of format %%xxx%% are replaced with value
32 33 34
  #                  with the key xxx in data hash of the current row.
  #     content: If specified, the content of this variable is used
  #              instead of the data pulled from the current row. 
35
  #              NOTE: This value is only partially HTML filtered!
36 37 38 39 40 41
  #     content_use_field: If defined and true, then each value in the 
  #                        column corresponds with a key in the
  #                        field_descs field, and that value from the 
  #                        field_descs hash will be used instead of "content."
  #                        See fieldvalues/select-field for an example of use.
  #                        This content WILL be HTML-filtered in this case.
42 43
  #     align: left/center/right. Controls the horizontal alignment of the
  #            text in the column.
44 45
  #     allow_html_content: if defined, then this column allows some html content
  #                         and so it will be only partially filtered.
46
  #     yesno_field: Turn the data from 0/!0 into Yes/No
47 48 49 50 51 52
  #
  # data:
  #   array of hashes representing the data for the table.
  #   Each hash contains data for a single row of data. The
  #   keys are column names from columns subhashes name field.
  #
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  # overrides:
  #   Provides a method for overriding individual table cells. This is
  #   a hash, whose key is the column name, so the column must be
  #   named for one of it's cells to be overwritten. The hash value is
  #   an array. Each item in this array is a hash specifying
  #   row-matching criteria, and any overridden values. The
  #   row-matching criteria consist of keys:
  #     match_field: The name of the row value we want to match
  #     match_value: The value to match against
  #   Each column value mentioned in the 'columns' documentation above
  #   can be overwritten (apart from name and heading). To override a
  #   table-cell value 'xxx', specify a new 'xxx' value, and specify a
  #   'override_xxx' value as well. See
  #   admin/milestones/list.html.tmpl for example
  #
68 69
  #%]

70 71
[% PROCESS "global/field-descs.none.tmpl" %]

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
[%###################  TABLE HEADER   ######################%]

<table border="1" cellpadding="4" cellspacing="0">
  <tr bgcolor="#6666FF">
    [% FOREACH c = columns %]
      [%# Default to align left for headers %]
      <th align="[% (c.align || 'left') FILTER html %]">
        [% c.heading FILTER html %]
      </th>
    [% END %]
  </tr>


[%###################  TABLE CONTENT  ######################%]

[% FOREACH row = data %]
88

89 90
  <tr>
    [% FOREACH c = columns %]
91 92 93 94 95 96

      [%# Copy to local variables, as we may update these %]
      [% contentlink = c.contentlink
         content = c.content
         content_use_field = c.content_use_field
         align = c.align
97
         class = c.class
98 99 100 101 102 103 104 105 106 107
         allow_html_content = c.allow_html_content
         yesno_field = c.yesno_field
       %]

      [%# Are there any specific overrides for this column? %]
      [% FOREACH override = overrides.${c.name} %]

        [%# Is the override for this row? %]
        [% IF override.match_value == row.${override.match_field} %]

108
          [% SET contentlink = override.contentlink 
109
             IF override.override_contentlink %]
110
          [% SET content = override.content
111
             IF override.override_content %]
112
          [% SET content_use_field = override.content_use_field
113
             IF override.override_content_use_field %]
114
          [% SET align = override.align
115
             IF override.override_align %]
116 117
          [% SET class = override.class
             IF override.override_class %]
118
          [% SET allow_html_content = override.allow_html_content
119
             IF override.override_allow_html_content %]
120
          [% SET yesno_field = override.yesno_field
121 122 123 124 125 126 127
             IF override.override_yesno_field %]

          [% LAST %]

        [% END %]
      [% END %]

128 129
      <td [% IF align %] align="[% align FILTER html %]" [% END %]
          [% IF class %] class="[% class FILTER html %]" [% END %]>
130 131 132

        [% IF contentlink %]
          [% link_uri = contentlink %]
133 134 135 136 137 138 139
          [% WHILE link_uri.search('%%(.+?)%%')%]
            [% FOREACH m = link_uri.match('%%(.+?)%%') %]
              [% IF row.$m %]
                [% replacement_value = FILTER url_quote; row.$m; END %]
              [% ELSE %]
                [% replacement_value = "" %]
              [% END %]
140 141
              [% link_uri = link_uri.replace("%%$m%%", replacement_value) %]
            [% END %]
142 143 144 145
          [% END %]
          <a href="[% link_uri %]">
        [% END %]
        
146
        [% IF content_use_field %]
147 148
           [% colname = row.${c.name} %]
           [% field_descs.${colname} FILTER html %]
149
        [% ELSIF content %]
150
            [% content FILTER html_light %]
151
        [% ELSE %]
152
          [% IF yesno_field %]
153 154 155 156 157
            [% IF row.${c.name} %]
              Yes
            [% ELSE %]
              No
            [% END %]
158
          [% ELSE %]
159
            [% IF allow_html_content %]
160
              [% row.${c.name} FILTER html_light %]
161 162 163
            [% ELSE %]
              [% row.${c.name} FILTER html %]
            [% END %]
164
          [% END %]
165 166
        [% END %]
        
167
        [% IF contentlink %]
168 169 170 171 172 173 174 175
          </a>
        [% END %]
         
      </td>
    [% END %]
  </tr>
[% END %]

176 177 178 179 180
[% IF data.size == 0 %]
  <tr><td colspan="[% columns.size %]" align="center"><i>&lt;none&gt;</i></td></tr>
[% END %]


181 182 183
[%###################  TABLE FOOTER   ######################%]

</table>