summaryrefslogtreecommitdiffstats
path: root/template/en/default/admin/table.html.tmpl
blob: 77a15a9fc20b5a19530e52dc9e3d44440df36770 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
[%# This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  #
  # This Source Code Form is "Incompatible With Secondary Licenses", as
  # defined by the Mozilla Public License, v. 2.0.
  #%]

[%# 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.
  #                  Expressions of format %%xxx%% are replaced with value
  #                  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. 
  #              NOTE: This value is only partially HTML filtered!
  #     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.
  #     align: left/center/right. Controls the horizontal alignment of the
  #            text in the column.
  #     allow_html_content: if defined, then this column allows some html content
  #                         and so it will be only partially filtered.
  #     yesno_field: Turn the data from 0/!0 into Yes/No
  #
  # 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.
  #
  # overrides:
  # Example:
  #     overrides {                           # first hash
  #       column_name_to_be_overwriten => {   # second hash
  #         name_of_row_to_match_against => { # third hash
  #           value_to_match_against => {     # fourth hash
  #             content => "some contents"
  #             override_content => 1
  #           }
  #         }
  #       }
  #     }
  #
  #   Provides a method for overriding individual table cells. This is a hash
  #   (1), 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 another hash
  #   (2). The keys of that second hash are the name of the row to match
  #   against. The second hash then again points to another hash. Within this
  #   third hash (3), the keys represent values to match against. The item
  #   contains a fourth hash (4) specifying overridden values.
  #   
  #   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
  #
  #%]

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

[%###################  TABLE HEADER   ######################%]

<table id="admin_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 %]

  <tr>
    [% FOREACH c = columns %]

      [%# 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
         class = c.class
         allow_html_content = c.allow_html_content
         yesno_field = c.yesno_field
       %]

      [%# Get any specific "important" overrides for this c.name and row.name ? %]
      [% SET important = overrides.${c.name}.name.${row.name} %]

      [% IF important %]

          [% FOREACH key IN important.keys %]
             [% SET ${key} = important.${key} %]
          [% END %]

      [% ELSE %]

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

              [% FOREACH key IN override.keys %]
                  [% SET ${key} = override.${key} %]
              [% END %]

              [% LAST %]

          [% END %]
      [% END %]

      <td [% IF align %] align="[% align FILTER html %]" [% END %]
          [% IF class %] class="[% class FILTER html %]" [% END %]>

        [% IF contentlink %]
          [% link_uri = contentlink %]
          [% WHILE link_uri.search('%%(.+?)%%')%]
            [% FOREACH m = link_uri.match('%%(.+?)%%') %]
              [% IF row.$m.defined %]
                [% replacement_value = FILTER uri; row.$m; END %]
              [% ELSE %]
                [% replacement_value = "" %]
              [% END %]
              [% link_uri = link_uri.replace("%%$m%%", replacement_value) %]
            [% END %]
          [% END %]
          <a href="[% link_uri %]">
        [% END %]
        
        [% IF content_use_field %]
           [% colname = row.${c.name} %]
           [% field_descs.${colname} FILTER html %]
        [% ELSIF content %]
            [% content FILTER html_light %]
        [% ELSE %]
          [% IF yesno_field %]
            [% IF row.${c.name} %]
              Yes
            [% ELSE %]
              No
            [% END %]
          [% ELSE %]
            [% IF allow_html_content %]
              [% row.${c.name} FILTER html_light %]
            [% ELSE %]
              [% row.${c.name} FILTER html %]
            [% END %]
          [% END %]
        [% END %]
        
        [% IF contentlink %]
          </a>
        [% END %]
         
      </td>
    [% END %]
  </tr>
[% END %]

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


[%###################  TABLE FOOTER   ######################%]

</table>