-
Notifications
You must be signed in to change notification settings - Fork 244
/
select.jelly
186 lines (184 loc) · 9.21 KB
/
select.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
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License
~
~ Copyright (c) 2011-2016, CloudBees, Inc., Stephen Connolly.
~
~ 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:t="/lib/hudson">
<st:documentation>
A <code>select</code> control that supports the data binding and AJAX updates with support for adding credentials.
Your descriptor should have the 'doFillXyzItems' method, which returns a StandardListBoxModel
representation of the credentials in your drop-down list box, and your instance field should
hold the current value.
<st:attribute name="clazz">
Additional CSS classes that the control gets.
</st:attribute>
<st:attribute name="field">
Used for databinding.
</st:attribute>
<st:attribute name="default">
The default value of the text box, in case both @value is and 'instance[field]' is null.
</st:attribute>
<st:attribute name="expressionAllowed">
If expressions are allowed then the user can choose between a select drop down and entering an expression.
</st:attribute>
<st:attribute name="includeUser">
If the user's scoped stores should be included
</st:attribute>
<st:attribute name="includeUserCaution">
Feature flag: show a checkbox and caution message for including user's scoped stores.
This is useful on forms controlled by other users.
</st:attribute>
<st:attribute name="context">
The context within which to look up the stores. (defaults to <code>it</code> (jelly) / <code>my</code> (groovy))
</st:attribute>
<st:attribute name="checkMethod">
Specify <code>post</code> if a <code>doCheckXXX</code> method is <code>@RequirePOST</code>
(for example because it checks <code>CredentialsProvider.USE_ITEM</code> permission).
</st:attribute>
</st:documentation>
<f:prepareDatabinding/>
<j:set var="value" value="${attrs.value ?: instance[attrs.field] ?: attrs.default}" />
<j:set var="paramValue" value="${attrs.expressionAllowed and value.startsWith('${') and value.endsWith('}')}"/>
<j:set var="paramDefault" value="${attrs.expressionAllowed and attrs.default.startsWith('${') and attrs.default.endsWith('}')}"/>
<j:set var="selectHelper" value="${app.getDescriptorByName('com.cloudbees.plugins.credentials.CredentialsSelectHelper')}"/>
<j:set var="includeUser" value="${attrs.includeUser ? true : false}"/>
<j:set var="context" value="${selectHelper.resolveContext(attrs.context ?: it)}"/>
<st:adjunct includes="lib.credentials.dialog"/>
<div class="credentials-select-control">
<j:if test="${attrs.expressionAllowed}">
<label field-disabled="true">
<input type="radio" name="${attrs.name ?: '_.'+attrs.field}" value="select"
class="credentials-select-radio-control" checked="${paramValue?null:'true'}"/>
${%fixedSelection}
</label>
<label field-disabled="true">
<input type="radio" name="${attrs.name ?: '_.'+attrs.field}" value="param"
class="credentials-select-radio-control" checked="${paramValue?'true':null}"/>
${%paramExpression}
</label>
</j:if>
<div field-disabled="${paramValue?'true':null}"
class="credentials-select-content-select ${paramValue?'credentials-select-content-inactive':'credentials-select-content-active'}">
<j:choose>
<j:when test="${includeUser and attrs.includeUserCaution}">
<div class="include-user-credentials jenkins-form-item jenkins-form-item--tight">
<div class="jenkins-checkbox-help-wrapper">
<span class="jenkins-checkbox">
<input type="checkbox"
name="includeUser"
/>
<label class="attach-previous" field-disabled="true">${%includeUserCredentials}</label>
</span>
<span class="help-btn"><t:help href="#" /></span>
</div>
<div class="help-content" hidden="hidden">
<p>${%includeUserCredentialsHelp}</p>
<div class="from-plugin">
(from <a href="https://wiki.jenkins.io/display/JENKINS/Credentials+Plugin">Credentials Plugin</a>)
</div>
</div>
<div class="warning user-credentials-caution" hidden="hidden">
${%userCredentialsCaution}
</div>
</div>
</j:when>
<j:otherwise>
<input type="hidden" name="includeUser" value="${includeUser}"/>
</j:otherwise>
</j:choose>
<f:select clazz="${attrs.clazz} credentials-select" field="${attrs.field}"
default="${paramDefault?'':attrs.default}" value="${paramValue?(paramDefault?'':attrs.default):value}"
checkMethod="${attrs.checkMethod}"/>
<!-- TODO add support for checking permissions against stores in request path -->
<j:set var="storeItems" value="${selectHelper.getStoreItems(context, includeUser)}"/>
<j:choose>
<j:when test="${selectHelper.hasCreatePermission(context, includeUser) and storeItems != null and !storeItems.isEmpty()}">
<button class="credentials-add-menu hetero-list-add jenkins-!-margin-top-2" menualign="${attrs.menuAlign}"
suffix="${attrs.name}">
<l:icon src="symbol-add"/>
${%Add}
</button>
<div class="credentials-add-menu-items yuimenu">
<div class="bd">
<ul class="first-of-type">
<j:forEach var="storeItem" items="${storeItems}">
<j:choose>
<j:when test="${storeItem.enabled}">
<li class="yuimenuitem" data-url="${request.contextPath}/${storeItem.url}/dialog">
<span class="yuimenuitemlabel" tooltip="${storeItem.description}">
<l:icon class="${storeItem.iconClassName} icon-sm"/>
${storeItem.displayName}
</span>
</li>
</j:when>
<j:otherwise>
<li class="yuimenuitem" disabled="disabled">
<span class="yuimenuitemlabel" tooltip="${storeItem.description}" disabled="disabled">
<l:icon class="${storeItem.iconClassName} icon-sm"/>
${storeItem.displayName}
</span>
</li>
</j:otherwise>
</j:choose>
</j:forEach>
</ul>
</div>
</div>
</j:when>
<j:otherwise>
<button class="credentials-add jenkins-!-margin-top-2">
<l:icon src="symbol-add"/>
${%Add}
</button>
</j:otherwise>
</j:choose>
</div>
<j:if test="${attrs.expressionAllowed}">
<div class="credentials-select-content-param ${paramValue?'credentials-select-content-active':'credentials-select-content-inactive'}">
<f:textbox value="${paramValue?value:(paramDefault?attrs.default:'')}" clazz="${attrs.clazz} credentials-select"
field="${attrs.field}" default="${paramDefault?attrs.default:''}"/>
<div class="error" style="display:none;">
${%invalidExpression}
</div>
</div>
</j:if>
</div>
<script>
// HACK: can be removed once base version of Jenkins has fix of https://issues.jenkins-ci.org/browse/JENKINS-26578
// conditionally include the adjunct resources as AdjunctManager doesn't do this correctly for CSS
if (!document.getElementById('lib.credentials.select.select')) {
var link = document.createElement('link');
link.id = 'lib.credentials.select.select';
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = "${request.contextPath+'/'+app.getAdjuncts(null).rootURL+'/lib/credentials/select/select.css'}";
link.media = 'all';
document.getElementsByTagName('head')[0].appendChild(link);
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "${request.contextPath+'/'+app.getAdjuncts(null).rootURL+'/lib/credentials/select/select.js'}";
document.getElementsByTagName('body')[0].appendChild(script);
}
</script>
</j:jelly>