summaryrefslogtreecommitdiffstats
path: root/extensions/BugModal/template/en/default/bug_modal/field.html.tmpl
blob: cb2ce7a7a97a8574dfb8f79d8baeff6d5cf47240 (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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
[%# 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.
  #%]

[%#
  # field: (field object) bug_fields.$field_name object
  # field_type: (const) constants.FIELD_TYPE_*
  # no_label: (boolean) don't output label
  # label: (string) field label text (default: field_descs.${$field.name}
  # view_only: (boolean) don't allow editing (default: determined from bug.check_can_change_field)
  # edit_only: (boolean) always render the edit ui
  # container: (boolean) output just a label and the content (eg. for multiple fields next to one label)
  # value: (string) visible value (default: bug.$name)
  # values: (array of string) list of value objects (FIELD_TYPE_SINGLE_SELECT and _BUG_URLS only) (default: lazy-load on edit)
  # inline: (boolean) output field as a table-cell instead of as a stand-alone div (default: false)
  # no_indent: (boolean) don't indent the field (left-padding) (default: false)
  # full_width: (boolean) the field takes up the complete page width (default: false)
  # short_width: (boolean) the field shouldn't take up much space at all (default: false)
  # hide_on_view: (boolean) hide field from read-only view (default: false)
  # hide_on_edit: (boolean) hide content when in edit mode (default: false)
  #%]

[%
IF field_type.defined && !field;
  RETURN;
END;
IF !name.defined;
  name = field.name;
END;
IF !value.defined;
  value = bug.$name;
END;
IF hide_on_edit;
  view_only = 1;
END;
IF view_only || container;
  editable = 0;
END;
IF !editable.defined;
  editable = bug.check_can_change_field(name, 0, 1);
END;
IF inline && !label.defined;
  no_label = 1;
END;
IF !no_label && !label.defined;
  label = field_descs.${field.name};
END;
IF field_type == "";
  field_type = -1;
END;
IF field_type == constants.FIELD_TYPE_DATE
    || field_type == constants.FIELD_TYPE_DATETIME;
  short_width = 1;
END;
%]

<div class="field
            [%~ " indent" IF no_label && !no_indent %]
            [%~ " inline" IF inline %]
            [%~ " edit-hide" IF hide_on_edit %]
            [%~ " edit-show" IF hide_on_view && !hide_on_edit %]"
  [% IF name %] id="field-[% name FILTER html %]"[% END %]
  [% IF hide_on_view %] style="display:none"[% END %]
>
  [% IF label.defined && !no_label %]
    <div class="name">[% label _ ":" FILTER html IF label %]</div>
  [% END %]

  [%# read-only html %]
  [% UNLESS edit_only %]
    <div class="[% "value" IF !container %][% " edit-hide" IF editable %][% " container" IF container %]">
      [% IF name %]
        <span id="field-value-[% name FILTER html %]">
      [% END %]
      [% IF content.defined %]
        [% content FILTER none %]
      [% ELSE %]
        [% SWITCH field_type %]

          [% CASE constants.FIELD_TYPE_USER %]
            [%# users %]
            [% INCLUDE bug_modal/user.html.tmpl u=value %]

          [% CASE constants.FIELD_TYPE_BUG_URLS %]
            [%# see also %]
            [% INCLUDE bug_urls values=values edit=0 %]

          [% CASE constants.FIELD_TYPE_BUG_LIST %]
            [%# bug lists (generally dependancies) %]
            [% INCLUDE bug_list values=values edit=0 %]

          [% CASE constants.FIELD_TYPE_TEXTAREA %]
            [%# text areas %]
            <span class="multiline-value">[% value FILTER html FILTER html_line_break %]</span>

          [% CASE constants.FIELD_TYPE_MULTI_SELECT %]
            [%# multi-select %]
            [% value.join(", ") FILTER html %]

          [% CASE constants.FIELD_TYPE_DATETIME %]
            [%# datetime %]
            [% value FILTER time %]

          [% CASE constants.FIELD_TYPE_DATE %]
            [%# date %]
            [% value FILTER time("%Y-%m-%d") %]

          [% CASE constants.FIELD_TYPE_BUG_ID %]
            [%# bug id %]
            [% value FILTER bug_link(value, use_alias => 1) FILTER none %]

          [% CASE %]
            [%# every else %]
            [% value FILTER html %]

        [% END %]
      [% END %]
      [% IF name %]
        </span>
      [% END %]
    </div>
  [% END %]

  [%# edit html %]
  [% IF editable %]
    [% "MISSING NAME" UNLESS name %]
    <div class="value edit edit-show [% " wide" IF full_width %][% " short" IF short_width %]"
      [% UNLESS edit_only +%] style="display:none"[% END %]>
      [% SWITCH field_type %]

        [% CASE constants.FIELD_TYPE_SINGLE_SELECT %]
          [%# single value select %]
          <select name="[% name FILTER html %]" id="[% name FILTER html %]">
            [% IF values.defined %]
              [% FOREACH v IN values %]
                [% NEXT IF NOT v.is_active AND NOT value.contains(v.name).size %]
                <option value="[% v.name FILTER html %]"
                        id="v[% v.id FILTER html %]_[% name FILTER html %]"
                        [% " selected" IF value.contains(v.name).size %]
                >[% v.name FILTER html %]</option>
              [% END %]
            [% ELSE %]
              <option value="[% value FILTER html %]" selected>[% value FILTER html %]</option>
            [% END %]
          </select>

        [% CASE constants.FIELD_TYPE_MULTI_SELECT %]
          [%# multi value select %]
          <select name="[% name FILTER html %]" id="[% name FILTER html %]" multiple size="5">
            [% IF values.defined %]
              [%# not implemented %]
            [% ELSE %]
              [% FOREACH v IN value %]
                <option value="[% v FILTER html %]" selected>[% v FILTER html %]</option>
              [% END %]
            [% END %]
          </select>

        [% CASE constants.FIELD_TYPE_FREETEXT %]
          [%# normal input field %]
          <input name="[% name FILTER html %]" id="[% name FILTER html %]" value="[% value FILTER html %]">

        [% CASE constants.FIELD_TYPE_USER %]
          [%# single user %]
          [% INCLUDE global/userselect.html.tmpl
              id = name
              name = name
              value = value.login
              classes = [ "bz_userfield" ]
            %]

        [% CASE constants.FIELD_TYPE_USERS %]
          [%# multiple users %]
          [% INCLUDE global/userselect.html.tmpl
              id = name
              name = name
              value = value.join(", ")
              classes = [ "bz_userfield" ]
              multiple = 5
            %]

        [% CASE constants.FIELD_TYPE_KEYWORDS %]
          [%# keywords %]
          <input type="text" id="[% name FILTER html %]" name="[% name FILTER html %]"
            value="[% value FILTER html %]">

        [% CASE constants.FIELD_TYPE_BUG_URLS %]
          [%# see also %]
          [% INCLUDE bug_urls values=values edit=1 %]

        [% CASE constants.FIELD_TYPE_BUG_LIST %]
          [%# bug lists %]
          [% INCLUDE bug_list values=values edit=1 %]

        [% CASE constants.FIELD_TYPE_TEXTAREA %]
          [%# text area %]
            <button type="button" class="minor edit-textarea-btn [%= "edit-textarea-set-btn" IF value != "" %]"
              id="[% name FILTER html %]-edit">Edit</button>
            <span class="multiline-value" id="[% name FILTER html %]-view">[% value FILTER html FILTER html_line_break %]</span>
            <textarea id="[% name FILTER html %]" name="[% name FILTER html %]"
              rows="10" cols="10" style="display:none">[% value FILTER html %]</textarea>

        [% CASE constants.FIELD_TYPE_DATETIME %]
          [%# datetime %]
          <input class="cf_datetime" name="[% name FILTER html %]" id="[% name FILTER html %]"
            value="[% value FILTER html %]">
          <img class="cf_datetime-img" id="[% name FILTER html %]-img"
            src="extensions/BugModal/web/calendar.png" width="16" height="16">

        [% CASE constants.FIELD_TYPE_DATE %]
          [%# date %]
          <input class="cf_date" name="[% name FILTER html %]" id="[% name FILTER html %]"
            value="[% value FILTER html %]">
          <img class="cf_date-img" id="[% name FILTER html %]-img"
            src="extensions/BugModal/web/calendar.png" width="16" height="16">

        [% CASE constants.FIELD_TYPE_INTEGER %]
          [%# integer %]
          <input type="number" name="[% name FILTER html %]" id="[% name FILTER html %]"
            value="[% value FILTER html %]">

        [% CASE constants.FIELD_TYPE_BUG_ID %]
          [%# bug id %]
          <input type="text" name="[% name FILTER html %]" id="[% name FILTER html %]"
            value="[% value FILTER html %]">

        [% CASE %]
          [%# error %]
          ('[% name FILTER html %]' [[% field_type FILTER html %])] not supported)

      [% END %]
    </div>
  [% END %]
</div>

[%# bug-urls, currently just see-also %]
[% BLOCK bug_urls %]
  [% FOREACH url IN values %]
    <div>
      [% IF url.isa('Bugzilla::BugUrl::Bugzilla::Local') %]
        [% url.target_bug_id FILTER bug_link(url.target_bug_id, use_alias => 1) FILTER none %]
      [% ELSE %]
        <a href="[% url.name FILTER html %]">[% url.name FILTER html %]</a>
      [% END %]
      [% IF edit %]
          <label>
            <input type="checkbox" name="remove_see_also" value="[% url.name FILTER html %]">
            Remove
          </label>
      [% END %]
    </div>
  [% END %]

  [% IF edit %]
    <button id="[% name FILTER html %]-btn" class="bug-urls-btn minor">Add</button>
    <input id="[% name FILTER html %]" name="[% name FILTER html %]" style="display:none">
  [% END %]
[% END %]

[%# bug lists, depencancies, blockers %]
[% BLOCK bug_list %]
  [% IF NOT edit %]
    [% FOREACH b IN values %]
      [% INCLUDE bug/link.html.tmpl bug=b link_text=b.id use_alias=1  %]
      [% ", " UNLESS loop.last %]
    [% END %]
  [% ELSE %]
    <input type="text" id="[% name FILTER html %]" name="[% name FILTER html %]"
           value="[% values.pluck('id').join(", ") FILTER html %]">
  [% END %]
[% END %]