-
Notifications
You must be signed in to change notification settings - Fork 80
/
traits.jelly
217 lines (204 loc) · 8.96 KB
/
traits.jelly
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
<!--
The MIT License
Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, CloudBees, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:f="/lib/form" xmlns:local="local" xmlns:si="/jenkins/scm/internal/form">
<!-- TODO switch to hetero-list or repeatableHeteroProperty once the dd-handle class can be removed -->
<st:documentation>
Data-bound only version of <f:hetero-list> specialized for traits.
<st:attribute name="field" use="required">
Used for the data binding. Note: if the descriptor implements a getXxxDescriptorLists that returns a List
of jenkins.scm.impl.form.NamedArrayList this will enable the sectioned listing of traits otherwise this
will fall back to looking for a getXxxDescriptors and finally inferrence of the descriptors.
</st:attribute>
<st:attribute name="default">
default configuration to use (if descriptor does not have a getFieldDefaults() method).
</st:attribute>
<st:attribute name="addCaption">
caption of the 'add' button.
</st:attribute>
<st:attribute name="deleteCaption">
caption of the 'delete' button.
</st:attribute>
<st:attribute name="targetType">
the type for which descriptors will be configured. Defaults to ${it.class} (optional)
</st:attribute>
<st:attribute name="menuAlign">
Menu alignment against the button. Defaults to tl-bl
</st:attribute>
<st:attribute name="capture">
Config fragments from descriptors are rendered lazily by default, which means
variables seen in the caller aren't visible to them. This attribute allows you
to nominate additional variables and their values to be captured for descriptors.
</st:attribute>
</st:documentation>
<d:taglib uri="local">
<d:tag name="blockWrapper">
<st:documentation>
This adds a wrapper for a group of fields
The wrapper will be a `table` tag on Jenkins Core less than ~2.237, and a `div` tag after that
</st:documentation>
<j:choose>
<j:when test="${divBasedFormLayout}">
<div>
<d:invokeBody/>
</div>
</j:when>
<j:otherwise>
<table style="width:100%">
<d:invokeBody/>
</table>
</j:otherwise>
</j:choose>
</d:tag>
<d:tag name="row">
<j:choose>
<j:when test="${divBasedFormLayout}">
<div class="tr">
<d:invokeBody/>
</div>
</j:when>
<j:otherwise>
<tr>
<d:invokeBody/>
</tr>
</j:otherwise>
</j:choose>
</d:tag>
<d:tag name="td">
<j:choose>
<j:when test="${divBasedFormLayout}">
<div>
<d:invokeBody/>
</div>
</j:when>
<j:otherwise>
<td colspan="3">
<d:invokeBody/>
</td>
</j:otherwise>
</j:choose>
</d:tag>
<d:tag name="body">
<local:blockWrapper>
<j:set var="help" value="${descriptor.helpFile}"/>
<local:row>
<local:td>
<div>
<b>${descriptor.displayName}</b>
</div>
</local:td>
<f:helpLink url="${help}"/>
</local:row>
<!-- TODO: help support is unintuitive; people should be able to see help from drop-down menu -->
<j:if test="${help!=null}">
<f:helpArea/>
</j:if>
<d:invokeBody/>
<f:class-entry descriptor="${descriptor}"/>
<f:block>
<div align="right">
<f:repeatableDeleteButton value="${attrs.deleteCaption}"/>
</div>
</f:block>
</local:blockWrapper>
</d:tag>
</d:taglib>
<st:adjunct includes="jenkins.scm.api.form.traits.traits"/>
<j:set var="targetType" value="${attrs.targetType?:it.class}"/>
<j:set var="descriptorLists" value="${descriptor[attrs.field+'DescriptorLists']}"/>
<j:if test="${descriptorLists==null}">
<!-- if you don't implement a descriptor.getXxxDescriptorLists then fall back to standard and no sections -->
<j:new var="descriptorLists" className="java.util.ArrayList"/>
<j:invoke on="${descriptorLists}" method="add">
<j:arg value="${descriptor[attrs.field+'Descriptors'] ?: descriptor.getPropertyType(instance,attrs.field).getApplicableItemDescriptors()}"/>
</j:invoke>
</j:if>
<j:set var="renderSections" value="${descriptorLists.size() > 1}"/>
<div class="hetero-list-container with-drag-drop one-each honor-order trait-container">
<!-- display existing items -->
<j:set var="instances"
value="${instance != null ? instance[attrs.field] : (attrs.default ?: descriptor[attrs.field+'Defaults'])}"/>
<j:forEach var="descriptors" items="${descriptorLists}" varStatus="descriptorsLoop">
<j:if test="${renderSections}">
<!-- hijack descriptorId to provide permanent placeholders for the section headers
descriptorId is not used in form submission, only to determine sections already present (one-each CSS style)
and to determine the placing of sections with the sequence (honor-order CSS style)
thus we get the section headers in the menu (but disabled) and the entries are added to their respective
sections
-->
<div name="${attrs.field}" class="repeated-chunk trait-section"
descriptorId="!fake@section/[${descriptorsLoop.index}]">
<span class="trait-section-header">
<span>${descriptors.getName()}</span>
</span>
</div>
</j:if>
<j:forEach var="i" items="${instances}">
<j:if test="${descriptors.contains(i.descriptor)}">
<j:set var="descriptor" value="${i.descriptor}"/>
<j:set var="instance" value="${i}"/>
<div name="${attrs.field}" class="repeated-chunk" descriptorId="${descriptor.id}">
<local:body deleteCaption="${attrs.deleteCaption}">
<st:include from="${descriptor}" page="${descriptor.configPage}" optional="true"/>
</local:body>
</div>
</j:if>
</j:forEach>
</j:forEach>
<div class="repeatable-insertion-point"/>
<div class="prototypes to-be-removed">
<j:forEach var="descriptors" items="${descriptorLists}" varStatus="descriptorsLoop">
<!-- render one prototype for each type -->
<j:set var="instance" value="${null}"/>
<j:set var="filteredDescriptors" value="${h.filterDescriptors(it,descriptors)}"/>
<j:if test="${!filteredDescriptors.isEmpty()}">
<j:if test="${renderSections}">
<div name="${attrs.field}" title="— ${descriptors.getName()} —"
descriptorId="!fake@section/[${descriptorsLoop.index}]">
<span class="trait-section-header">
<span>${descriptors.getName()}</span>
</span>
</div>
</j:if>
<j:forEach var="descriptor" items="${filteredDescriptors}" varStatus="loop">
<div name="${attrs.field}" title="${descriptor.displayName}"
tooltip="${descriptor.tooltip}"
descriptorId="${descriptor.id}">
<j:set var="capture" value="${attrs.capture?:''}"/>
<local:body deleteCaption="${attrs.deleteCaption}">
<l:renderOnDemand tag="${divBasedFormLayout ? 'div' : 'tr'}" clazz="config-page" capture="descriptor,it,instance,${capture}">
<l:ajax>
<st:include from="${descriptor}" page="${descriptor.configPage}" optional="true"/>
</l:ajax>
</l:renderOnDemand>
</local:body>
</div>
</j:forEach>
</j:if>
</j:forEach>
</div>
<div>
<input type="button" value="${attrs.addCaption?:'%Add'}" class="hetero-list-add trait-add"
menualign="${attrs.menuAlign}"
suffix="${attrs.field}"/>
</div>
</div>
</j:jelly>