-
Notifications
You must be signed in to change notification settings - Fork 144
/
branchSourceSelector.jelly
102 lines (91 loc) · 4.75 KB
/
branchSourceSelector.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
<!--
The MIT License
Copyright (c) 2004-2013, 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:l="/lib/layout" xmlns:f="/lib/form" xmlns:branch="/lib/branch-api">
<st:documentation>
Allows selecting Branch Sources in a more intuitive way than using a standard hetero-list
<st:attribute name="field" use="required">
Used for the data binding.
</st:attribute>
<st:attribute name="sourceDescriptors" use="required">
The source descriptors to use.
</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="hasHeader">
For each item, add a caption from descriptor.getDisplayName().
This also activates drag&drop (where the header is a grip), and help text support.
</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>
<f:prepareDatabinding />
<j:set target="${attrs}" property="descriptors"
value="${attrs.descriptors ?: descriptor.getPropertyType(instance,attrs.field).getApplicableDescriptors()}" />
<j:set var="items" value="${instance[attrs.field]}"/>
<j:set var="targetType" value="${attrs.targetType?:it.class}"/>
<div class="hetero-list-container ${hasHeader?'with-drag-drop':''} ">
<!-- display existing items -->
<j:forEach var="i" items="${items}">
<j:set var="descriptor" value="${i.descriptor}" />
<j:set var="sourceDescriptor" value="${i.source.descriptor}" />
<j:set var="instance" value="${i}" />
<div name="${attrs.field}" class="repeated-chunk" descriptorId="${sourceDescriptor.id}">
<branch:branchSourceBody deleteCaption="${attrs.deleteCaption}">
<st:include from="${descriptor}" page="${descriptor.configPage}" optional="true" />
</branch:branchSourceBody>
</div>
</j:forEach>
<div class="repeatable-insertion-point" />
<div class="prototypes to-be-removed">
<!-- render one prototype for each type -->
<j:set var="instance" value="${null}" />
<j:set var="descriptor" value="${it.descriptor.branchSourceDescriptor}" />
<j:forEach var="sourceDescriptor" items="${attrs.sourceDescriptors}" varStatus="loop">
<div name="${attrs.field}" title="${sourceDescriptor.displayName}" tooltip="${sourceDescriptor.tooltip}" descriptorId="${sourceDescriptor.id}">
<j:set var="capture" value="${attrs.capture?:''}" />
<branch:branchSourceBody deleteCaption="${attrs.deleteCaption}">
<l:renderOnDemand tag="${divBasedFormLayout ? 'div' : 'tr'}" clazz="config-page" capture="descriptor,it,instance,sourceDescriptor,${capture}">
<l:ajax>
<st:include from="${descriptor}" page="${descriptor.configPage}" optional="true" />
</l:ajax>
</l:renderOnDemand>
</branch:branchSourceBody>
</div>
</j:forEach>
</div>
<div>
<input type="button" value="${attrs.addCaption?:'%Add'}" class="hetero-list-add" menualign="${attrs.menuAlign}" suffix="${attrs.field}"/>
</div>
</div>
</j:jelly>