blob: 9b0bc11e498039775e6019e1311294a2b0a599e9 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001[define title]Add a Field[end]
2[define category_css]css/ph_detail.css[end]
3[include "../framework/header.ezt" "showtabs"]
4
5<a href="/p/[projectname]/adminLabels">&lsaquo; Back to field list</a><br><br>
6
7
8<h4>Add a custom field</h4>
9
10<form action="create.do" method="POST">
11<input type="hidden" name="token" value="[form_token]">
12
13<table cellspacing="8" class="rowmajor vt">
14 <tr>
15 <th width="1%">Name:</th>
16 <td>
17 <input id="fieldname" name="name" size="30" value="[initial_field_name]" class="acob">
18 <span id="fieldnamefeedback" class="fielderror" style="margin-left:1em">
19 [if-any errors.field_name][errors.field_name][end]
20 </span>
21 </td>
22 </tr>
23
24 <tr>
25 <th>Description:</th>
26 <td>
27 <textarea name="docstring" rows="4" cols="75">[initial_field_docstring]</textarea>
28 </td>
29 </tr>
30
31 <tr>
32 <th>Type:</th>
33 <td>
34 <select id="field_type" name="field_type">
35 <option value="enum_type" [is initial_type "enum_type"]selected="selected"[end]>Enum</option>
36 <option value="int_type" [is initial_type "int_type"]selected="selected"[end]>Integer</option>
37 <option value="str_type" [is initial_type "str_type"]selected="selected"[end]>String</option>
38 <option value="user_type" [is initial_type "user_type"]selected="selected"[end]>User</option>
39 <option value="date_type" [is initial_type "date_type"]selected="selected"[end]>Date</option>
40 <option value="url_type" [is initial_type "url_type"]selected="selected"[end]>URL</option>
41 <option value="approval_type" [is initial_type "approval_type"]selected="selected"[end]>Approval</option>
42 </select>
43 </td>
44 </tr>
45
46 <tr class="js-make_phase_subfield">
47 <th>Issue Gate field:</th>
48 <td>
49 <input id="phase_input" type="checkbox" name="is_phase_field" class="acob"
50 [if-any initial_is_phase_field]checked="checked"[end]>
51 <label for="phase_input">This field can only belong to issue gates.</label>
52 </td>
53 </tr>
54
55 [if-any approval_names]
56 <tr class="js-make_approval_subfield">
57 <th>Parent Approval:</th>
58 <td>
59 <select id="parent_input" name="parent_approval_name">
60 <option value="" [is initial_parent_approval_name ""]selected[end]>Not an approval's subfield</option>
61 [for approval_names]
62 <option value="[approval_names]"
63 [is initial_parent_approval_name approval_names]selected[end]
64 >[approval_names]</option>
65 [end]
66 </select>
67 </td>
68 </tr>
69 [end]
70
71 [# TODO(jojwang): monorail:3241, evaluate how to use applicable/importance for approval subfields]
72 <tr id="applicable_row">
73 <th>Applicable:</th>
74 <td>When issue type is:
75 <select id="applicable_type" name="applicable_type">
76 <option value="" [is initial_applicable_type ""]selected="selected"[end]>Anything</option>
77 <option disabled="disabled">----</option>
78 [for well_known_issue_types]
79 <option value="[well_known_issue_types]" [is initial_applicable_type well_known_issue_types]selected="selected"[end]>[well_known_issue_types]</option>
80 [end]
81 </select>
82 [# TODO(jrobbins): AND with free-form applicability predicate.]
83 </td>
84 </tr>
85
86 <tr id="importance_row">
87 <th>Importance:</th>
88 <td>
89 <select id="importance" name="importance">
90 <option value="required" [is initial_importance "required"]selected[end]>Required when applicable</option>
91 <option value="normal" [is initial_importance "normal"]selected[end]>Offered when applicable</option>
92 <option value="niche" [is initial_importance "niche"]selected[end]>Under "Show all fields" when applicable</option>
93 </select>
94 </td>
95 </tr>
96
97 <tr id="multi_row">
98 <th>Multivalued:</th>
99 <td>
100 <input type="checkbox" name="is_multivalued" class="acob"
101 [if-any initial_is_multivalued]checked="checked"[end]>
102 </td>
103 </tr>
104
105 <tr id="choices_row" style="display:none">
106 <th>Choices:</th>
107 <td>
108 <textarea id="choices" name="choices" rows="10" cols="75" style="tab-size:12"
109 >[initial_choices]</textarea>
110 </td>
111 </tr>
112
113 <tr id="int_row" style="display:none">
114 <th>Validation:</th>
115 <td>
116 Min value: <input type="number" name="min_value" style="text-align:right; width: 4em">
117 Max value: <input type="number" name="max_value" style="text-align:right; width: 4em"><br>
118 <span class="fielderror" style="margin-left: 1em">
119 [if-any errors.min_value][errors.min_value][end]</span><br>
120 </td>
121 </tr>
122
123 <tr id="str_row" style="display:none">
124 <th>Validation:</th>
125 <td>
126 Regex: <input type="text" name="regex" size="30"><br>
127 </td>
128 </tr>
129
130 <tr id="user_row" style="display:none">
131 <th>Validation:</th>
132 <td>
133 <input type="checkbox" name="needs_member" id="needs_member" class="acob"
134 [if-any initial_needs_member]checked[end]>
135 <label for="needs_member">User must be a project member</label><br>
136 <span id="needs_perm_span" style="margin-left:1em">
137 Required permission:
138 <input type="text" name="needs_perm" id="needs_perm" size="20"
139 value="[initial_needs_perm]" class="acob">
140 </span><br>
141 </td>
142 </tr>
143 <tr id="user_row2" style="display:none">
144 <th>Permissions:</th>
145 <td>
146 The users named in this field is granted this permission on this issue:<br>
147 [# TODO(jrobbins): one-click way to specify View vs. EditIssue vs. any custom perm.]
148 <input type="text" name="grants_perm" id="grants_perm" class="acob"
149 size="20" value="[initial_grants_perm]" autocomplete="off">
150 </td>
151 </tr>
152 <tr id="user_row3" style="display:none">
153 <th>Notification:</th>
154 <td>
155 The users named in this field will be notified via email whenever:<br>
156 <select name="notify_on">
157 <option value="never" [is initial_notify_on "0"]selected="selected"[end]
158 >No notifications</option>
159 <option value="any_comment" [is initial_notify_on "1"]selected="selected"[end]
160 >Any change or comment is added</option>
161 </select>
162 </td>
163 </tr>
164
165 <tr id="date_row" style="display:none">
166 <th>Action:</th>
167 <td>
168 When this date arrives:
169 <select name="date_action">
170 <option value="no_action" [is initial_date_action "no_action"]selected="selected"[end]
171 >No action</option>
172 [# TODO(jrobbins): owner-only option.]
173 <option value="ping_participants" [is initial_date_action "ping_participants"]selected="selected"[end]
174 >Post a "ping" comment and notify all issue participants</option>
175 </select>
176 </td>
177 </tr>
178
179 <tr id="approval_row" style="display:none">
180 <th>Approvers:</th>
181 <td>
182 <input id="member_approvers" name="approver_names" size="75" value="[initial_approvers]"
183 autocomplete="off">
184 <span class="fielderror" style="margin-left:1em">
185 [if-any errors.approvers][errors.approvers][end]
186 </span>
187 </td>
188 </tr>
189
190 <tr id="approval_row2" style="display:none">
191 <th>Survey:</th>
192 <td>
193 Any information feature owners need to provide for the approval team should be requested here.
194 <textarea name="survey" rows="4" cols="75">[initial_survey]</textarea>
195 </td>
196 </tr>
197
198 <tr>
199 <th>Admins:</th>
200 <td>
201 <input id="member_admins" name="admin_names" size="75" value="[initial_admins]"
202 autocomplete="off" class="acob">
203 <span class="fielderror" style="margin-left:1em">
204 [if-any errors.field_admins][errors.field_admins][end]
205 </span>
206 </td>
207 </tr>
208
209 <tr id="field_restriction">
210 <th>Restriction
211 <i id="editors_tooltip" class="material-icons inline-icon" style="font-size:14px; vertical-align: text-bottom"
212 title="Project owners and field admins can always edit the values of a custom field.">
213 info_outline</i> :
214 </th>
215 <td style="display:flex; align-items:center">
216 <input id="editors_checkbox" type="checkbox" name="is_restricted_field" class="acob"
217 [if-any initial_is_restricted_field]checked="checked"[end]>
218 Restrict users that can edit values of this custom field.
219 </td>
220 </tr>
221 <tr id="editors_input" style="display:none">
222 <th>Editors:</th>
223 <td>
224 <input id="member_editors" name="editor_names" size="75" value="[initial_editors]"
225 autocomplete="off" class="acob" disabled>
226 <span class="fielderror" style="margin-left:1em">
227 [if-any errors.field_editors][errors.field_editors][end]
228 </span>
229 </td>
230 </tr>
231
232 <tr>
233 <td></td>
234 <td>
235 <input id="submit_btn" type="submit" name="submit" value="Create field">
236 </td>
237 </tr>
238
239</table>
240</form>
241
242<script type="text/javascript" nonce="[nonce]">
243runOnLoad(function() {
244 var submit = document.getElementById('submit_btn');
245 submit.disabled = 'disabled';
246 var fieldname = document.getElementById('fieldname');
247 var oldName = '';
248 fieldname.focus();
249
250 var fieldNameRE = /^[[]a-z]([[]-_]?[[]a-z0-9])*$/i;
251
252 function checkFieldName() {
253 name = fieldname.value;
254 if (name != oldName) {
255 oldName = name;
256 feedback = document.getElementById('fieldnamefeedback');
257 submit.disabled = 'disabled';
258 if (name == '') {
259 feedback.textContent = 'Please choose a field name';
260 } else if (!fieldNameRE.test(name)) {
261 feedback.textContent = 'Invalid field name';
262 } else if (name.length > 30) {
263 feedback.textContent = 'Field name is too long';
264 } else {
265 _checkFieldNameOnServer('[projectname]', name, CS_env.token);
266 }
267 }
268 }
269
270 setInterval(checkFieldName, 700);
271
272 function updateForm(new_type) {
273 let choices_row = document.getElementById('choices_row');
274 choices_row.style.display = (new_type == 'enum_type') ? '' : 'none';
275
276 // Approval fields cannot be subfields of approvals.
277 let approval_subfield_display = (new_type == 'approval_type') ? 'none' : '';
278 let approval_subfield_rows = document.getElementsByClassName('js-make_approval_subfield');
279 Array.prototype.forEach.call(approval_subfield_rows, row => {
280 row.style.display = approval_subfield_display;
281 });
282
283 // Enum and Approval fields cannot be gate subfields.
284 let gate_subfield_display = (new_type == 'enum_type' || new_type == 'approval_type') ? 'none': '';
285 let phase_subfield_rows = document.getElementsByClassName('js-make_phase_subfield');
286 Array.prototype.forEach.call(phase_subfield_rows, row => {
287 row.style.display = gate_subfield_display;
288 });
289
290 // Prevent users from making a field a Gate and Approval subfield.
291 if ($('parent_input')) {
292 let phase_input = $('phase_input');
293 let parent_input = $('parent_input');
294 parent_input.addEventListener('change', () => {
295 if (parent_input.value === '') {
296 phase_input.disabled = false;
297 } else {
298 phase_input.disabled = true;
299 }
300 });
301 phase_input.addEventListener('change', () => {
302 if (phase_input.checked) {
303 parent_input.disabled = true;
304 } else {
305 parent_input.disabled = false;
306 }
307 });
308 };
309
310 let int_row = document.getElementById('int_row');
311 int_row.style.display = (new_type == 'int_type') ? '' : 'none';
312
313 let str_row = document.getElementById('str_row');
314 str_row.style.display = (new_type == 'str_type') ? '' : 'none';
315
316 let user_row_display = (new_type == 'user_type') ? '' : 'none';
317 document.getElementById('user_row').style.display = user_row_display;
318 document.getElementById('user_row2').style.display = user_row_display;
319 document.getElementById('user_row3').style.display = user_row_display;
320
321 let date_row_display = (new_type == 'date_type') ? '' : 'none';
322 document.getElementById('date_row').style.display = date_row_display;
323
324 let approval_row_display = (new_type == 'approval_type') ? '' : 'none';
325 let approval_row_hide = (new_type == 'approval_type') ? 'none' : '';
326 let new_type_is_approval = (new_type == 'approval_type');
327 document.getElementById(
328 'multi_row').style.display = approval_row_hide;
329 document.getElementById(
330 'importance_row').style.display = approval_row_hide;
331 document.getElementById(
332 'applicable_row').style.display = approval_row_hide;
333 document.getElementById(
334 'field_restriction').style.display = approval_row_hide;
335 if (new_type_is_approval) {
336 document.getElementById('editors_input').style.display = 'none';
337 } else {
338 if (document.getElementById('editors_checkbox').checked) {
339 document.getElementById('editors_input').style.display = '';
340 } else {
341 document.getElementById('editors_input').style.display = 'none';
342 }
343 }
344 document.getElementById(
345 'editors_checkbox').disabled = new_type_is_approval;
346 document.getElementById(
347 'member_editors').disabled = new_type_is_approval || !document.getElementById('editors_checkbox').checked;
348 document.getElementById('approval_row').style.display = approval_row_display;
349 document.getElementById('approval_row2').style.display = approval_row_display;
350 }
351
352 let type_select = document.getElementById('field_type');
353 updateForm(type_select.value);
354 type_select.addEventListener("change", function() {
355 updateForm(type_select.value);
356 });
357
358 let needs_perm_span = document.getElementById('needs_perm_span');
359 let needs_perm = document.getElementById('needs_perm');
360 function enableNeedsPerm(enable) {
361 needs_perm_span.style.color = enable ? 'inherit' : '#999';
362 needs_perm.disabled = enable ? '' : 'disabled';
363 if (!enable) needs_perm.value = '';
364 }
365 enableNeedsPerm(false);
366
367 //Enable editors input only when restricting the field.
368 document.getElementById('editors_checkbox').onchange = function() {
369 let member_editors = document.getElementById('member_editors');
370 let editors_input = document.getElementById('editors_input');
371 if (this.checked) {
372 editors_input.style.display = '';
373 } else {
374 editors_input.style.display = 'none';
375 }
376 member_editors.disabled = !this.checked;
377 };
378
379 let needs_member = document.getElementById("needs_member");
380 if (needs_member)
381 needs_member.addEventListener("change", function() {
382 enableNeedsPerm(needs_member.checked);
383 });
384
385 let acobElements = document.getElementsByClassName("acob");
386 for (let i = 0; i < acobElements.length; ++i) {
387 let el = acobElements[[]i];
388 el.addEventListener("focus", function(event) {
389 _acrob(null);
390 _acof(event);
391 });
392 }
393
394 $('member_approvers').addEventListener("focus", function(event) {
395 _acof(event);
396 });
397
398});
399</script>
400
401
402[include "../framework/footer.ezt"]