summaryrefslogtreecommitdiffstats
path: root/extensions/BugModal/template/en/default/bug_modal/field.html.tmpl
blob: 0fe1439192539dd37f5b8573458f28a67cfe4430 (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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
[%# 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)
  # name: (string) field name (default: field.name)
  # prefix: (string) string to prepend to 'name' and 'id' attributes (default: empty)
  # 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)
  # append_content: (boolean) when called as a WRAPPER, the content will be appended to the
  #                 edit html instead of replacing it.  forces edit_only (default: false);
  # default: (string) default value (eg. used as a placeholder in user fields)
  # help: (string) optional url that describes the field (requires a label to be defined and visible)
  # action: (hash) show a button to the right of the edit field (user fields only currently).  keys:
  #   id: (string) optional button id
  #   class: (string) optional button class
  #   caption: (string) button caption
  #   hidden: (boolean) don't show the button (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 append_content;
  edit_only = 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 prefix.defined;
  name = prefix _ name;
END;
# date picker fields should always be short
IF field_type == constants.FIELD_TYPE_DATE
    || field_type == constants.FIELD_TYPE_DATETIME;
  short_width = 1;
END;
# determine if a field is set
IF field_type == constants.FIELD_TYPE_BUG_URLS || field_type == constants.FIELD_TYPE_BUG_LIST;
  has_value = values.size > 0;
ELSIF field_type == constants.FIELD_TYPE_MULTI_SELECT || field_type == constants.FIELD_TYPE_USERS;
  has_value = value.size > 0;
ELSE;
  has_value = value != "";
END;
# switch to view mode if edit-only and the current user cannot edit
IF !editable && edit_only;
  edit_only = 0;
END;
IF hide_on_view && hide_on_edit;
  RETURN;
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">
      [%~ IF help.defined %]<a href="[% help FILTER none %]" class="help">[% END %]
      [%~ label _ ":" FILTER html IF label %]
      [%~ IF help.defined %]</a>[% END ~%]
    </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 %]
      [% ELSIF !editable && !has_value %]
        ---
      [% 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 %]
          <input type="hidden" id="[% name FILTER html %]-dirty">
          <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 %]
                [% NEXT IF NOT bug.check_can_change_field(name, bug.${name}, v.name) %]
                <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 %]
          <input type="hidden" id="[% name FILTER html %]-dirty">
          <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 %]
          [% IF action && !action.hidden %]
            <button class="field-button minor [%= action.class FILTER html IF action.class %]"
              data-field="[% name FILTER html %]"
              [% IF action.id %]id="[% action.id FILTER html %]"[% END %]>
              [% action.caption FILTER html %]
            </button>
            <div class="field-edit-container">
          [% END %]
          [%# single user %]
          [% INCLUDE global/userselect.html.tmpl
              id = name
              name = name
              value = value.login
              classes = [ "bz_userfield" ]
              placeholder = default
            %]
          [% IF action && !action.hidden %]
            </div>
          [% END %]

        [% CASE constants.FIELD_TYPE_USERS %]
          [%# multiple users %]
          <input type="hidden" name="defined_[% name FILTER html %]" value="[% value.join(", ") FILTER html %]">
          [% INCLUDE global/userselect.html.tmpl
              id = name
              name = name
              value = value.join(", ")
              classes = [ "bz_userfield" ]
              placeholder = default
              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>
            [% IF content.defined && !append_content %]
              <span id="[% name FILTER html %]-view">[% content FILTER none %]</span>
            [% ELSE %]
              <span class="multiline-value" id="[% name FILTER html %]-view">[% value FILTER html FILTER html_line_break %]</span>
            [% END %]
            <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 %]

      [% IF append_content && content.defined %]
        [% content FILTER none %]
      [% 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 %]"
           title="[% url.name FILTER truncate(256) FILTER html %]"
        >[% url.name FILTER truncate(40) 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 type="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 %]