PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/hudson-core/src/main/resources/lib/form/expandableTextbox.jelly

http://github.com/hudson/hudson
Unknown | 82 lines | 73 code | 9 blank | 0 comment | 0 complexity | 86a7f364a25ff7e1c6f846827421f864 MD5 | raw file
 1<!--
 2The MIT License
 3
 4Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe
 5
 6Permission is hereby granted, free of charge, to any person obtaining a copy
 7of this software and associated documentation files (the "Software"), to deal
 8in the Software without restriction, including without limitation the rights
 9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22THE SOFTWARE.
23-->
24
25<!--
26  TODO: support @checkUrl
27-->
28<?jelly escape-by-default='true'?>
29<j:jelly xmlns:j="jelly:core" xmlns:d="jelly:define" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
30  <st:documentation>
31    single-line textbox that can be expanded into a multi-line textarea.
32
33    This control is useful for a field that expects multiple whitespaec-separated tokens
34    (such as URLs, glob patterns, etc.) When the user only enters a few tokens,
35    they can keep it as a single line to save space, but to enter a large number of values,
36    this can be turned into textarea for better visibility.
37
38    If the initial value is already multi-line text, the control starts with
39    textarea.
40
41    On the server side, your program is responsible for treating ' ', \t, \r, and \n for
42    separators. (StringTokenizer would do this.)
43
44    <st:attribute name="field">
45      Used for databinding. TBD.
46    </st:attribute>
47    <st:attribute name="name">
48      This becomes @name of the &lt;input> tag.
49      If @field is specified, this value is inferred from it.
50    </st:attribute>
51    <st:attribute name="value">
52      The initial value of the field. This becomes the @value of the &lt;input> tag.
53      If @field is specified, the current property from the "instance" object
54      will be set as the initial value automatically,
55      which is the recommended approach.
56    </st:attribute>
57  </st:documentation>
58  <f:prepareDatabinding />
59  <j:set var="value" value="${attrs.value?:instance[attrs.field]}" />
60  <j:choose>
61    <j:when test="${h.isMultiline(value)}">
62      <!-- multiline text area to begin with -->
63      <f:textarea name='${attrs.name}' value="${value}" field="${attrs.field}"/>
64    </j:when>
65    <j:otherwise>
66      <!-- single line textbox with expand button -->
67      <table border="0" style="width:100%" cellspacing="0" cellpadding="0">
68        <tr>
69          <td width="*">
70            <j:set var="name" value="${attrs.name ?: '_.'+attrs.field}" />
71            <input class="setting-input" type="text"
72                   name="${name}" value="${value}"
73                   id="textarea.${name}" />
74          </td><td width="1">
75            <input type="button" value="&#x25BC;" onclick="expandTextArea(this,'textarea.${name}')"
76                tooltip="${%tooltip}"/>
77          </td>
78        </tr>
79      </table>
80    </j:otherwise>
81  </j:choose>
82</j:jelly>