forked from jenkinsci/jenkins
/
textarea.jelly
113 lines (105 loc) · 5.32 KB
/
textarea.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
<!--
The MIT License
Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Johnathon Jamison, Yahoo! 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:f="/lib/form">
<st:documentation>
<textarea> tag on steroids.
The textarea will be rendered to fit the content. It also gets the resize handle.
<st:attribute name="field">
Used for databinding. TBD.
</st:attribute>
<st:attribute name="name">
This becomes @name of the <textarea> tag.
If @field is specified, this value is inferred from it.
</st:attribute>
<st:attribute name="value">
The initial value of the field. This becomes the value of the <textarea> 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: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="checkUrl">
If specified, the value entered in this input field will be checked (via AJAX)
against this URL, and errors will be rendered under the text field.
If @field is specified, this will be inferred automatically,
which is the recommended approach.
</st:attribute>
<st:attribute name="checkMethod">
If specified, the HTTP method to use for input field will be checked (via AJAX)
</st:attribute>
<st:attribute name="codemirror-mode">
Turns this text area into CodeMirror-assisted code editing text area.
This attribute specifies the mode of CodeMirror, such as "text/x-java".
See http://codemirror.net/ for more details.
</st:attribute>
<st:attribute name="codemirror-config">
Specifies additional key/value pairs in the JSON format (except the start and end bracket)
to be passed as CodeMirror option object.
</st:attribute>
<st:attribute name="previewEndpoint">
If specified, this text area has preview feature.
The previewEndpoint is used to obtain formatted html.
</st:attribute>
</st:documentation>
<f:prepareDatabinding />
<j:set var="default" value="${attrs.default ?: ''}"/>
<j:set var="value" value="${attrs.value ?: instance[attrs.field] ?: default}" />
<j:if test="${attrs['previewEndpoint']!=null || attrs['codemirror-mode']!=null}">
<st:adjunct includes="lib.form.textarea.textarea"/>
</j:if>
<j:if test="${attrs['codemirror-mode']!=null}">
<st:adjunct includes="
org.kohsuke.stapler.codemirror.mode.${attrs['codemirror-mode']}.${attrs['codemirror-mode']},
org.kohsuke.stapler.codemirror.theme.default"/>
</j:if>
<j:set var="name" value="${attrs.name ?: '_.'+attrs.field}"/>
<textarea id="${attrs.id}" style="${attrs.style}"
name ="${name}"
class="setting-input ${attrs.checkUrl!=null?'validated':''} ${attrs['codemirror-mode']!=null?'codemirror':''} ${attrs.class}"
checkUrl="${attrs.checkUrl}" checkDependsOn="${attrs.checkDependsOn}" checkMethod="${attrs.checkMethod}"
rows="${h.determineRows(value)}"
readonly="${attrs.readonly}"
codemirror-mode="${attrs['codemirror-mode']}"
codemirror-config="${attrs['codemirror-config']}">
<j:if test="${value != null && !empty(value.toString()) && (value.toString().codePointAt(0) == 10 || value.toString().codePointAt(0) == 13)}"><j:whitespace> </j:whitespace></j:if>
<st:out value="${value}" />
</textarea>
<j:if test="${customizedFields != null and attrs.field != null and value != default}">
<j:mute>${customizedFields.add(name)}</j:mute>
</j:if>
<!-- resize handle -->
<div class="textarea-handle"/>
<j:if test="${attrs.previewEndpoint!=null}">
<div class="textarea-preview-container">
<j:if test="${attrs.previewEndpoint == '/markupFormatter/previewDescription'}">
[${app.markupFormatter.descriptor.displayName}]<st:nbsp/>
</j:if>
<a href="#" class="textarea-show-preview" previewEndpoint="${attrs.previewEndpoint}">${%Preview}</a>
<st:nbsp/>
<a href="#" class="textarea-hide-preview">${%Hide preview}</a>
<div class="textarea-preview">
<!-- div for preview -->
</div>
</div>
</j:if>
</j:jelly>