/
expandableTextbox.jelly
88 lines (79 loc) · 3.68 KB
/
expandableTextbox.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
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe
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.
-->
<!--
TODO: support @checkUrl
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
<st:documentation>
A single-line textbox that can be expanded into a multi-line textarea.
This control is useful for a field that expects multiple whitespace-separated tokens
(such as URLs, glob patterns, etc.) When the user only enters a few tokens,
they can keep it as a single line to save space, but to enter a large number of values,
this can be turned into textarea for better visibility.
If the initial value is already multi-line text, the control starts with
textarea.
On the server side, your program is responsible for treating ' ', \t, \r, and \n for
separators. (StringTokenizer would do this.)
<st:attribute name="field">
Used for databinding. TBD.
</st:attribute>
<st:attribute name="name"> <![CDATA[
This becomes @name of the <input> tag.
If @field is specified, this value is inferred from it.
]]>
</st:attribute>
<st:attribute name="value"> <![CDATA[
The initial value of the field. This becomes the @value of the <input> tag.
If @field is specified, the current property from the "instance" object
will be set as the initial value automatically,
which is the recommended approach.
]]>
</st:attribute>
</st:documentation>
<f:prepareDatabinding />
<j:set var="value" value="${attrs.value?:instance[attrs.field]}" />
<j:choose>
<j:when test="${h.isMultiline(value)}">
<!-- multiline text area to begin with -->
<f:textarea name='${attrs.name}' value="${value}" field="${attrs.field}"/>
</j:when>
<j:otherwise>
<!-- single line textbox with expand button -->
<f:possibleReadOnlyField>
<div class="expanding-input">
<div class="expanding-input__input">
<j:set var="name" value="${attrs.name ?: '_.'+attrs.field}" />
<input class="jenkins-input" type="text"
name="${name}" value="${value}"
id="textarea.${name}" />
<j:if test="${customizedFields != null and attrs.field != null and (value ?: '') != ''}">
<j:mute>${customizedFields.add(name)}</j:mute>
</j:if>
</div>
<div class="expanding-input__button">
<input type="button" value="▼" onclick="expandTextArea(this,'textarea.${h.jsStringEscape(name)}')"
tooltip="${%tooltip}"/>
</div>
</div>
</f:possibleReadOnlyField>
</j:otherwise>
</j:choose>
</j:jelly>