PageRenderTime 18ms CodeModel.GetById 10ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://github.com/hudson/hudson
Unknown | 97 lines | 86 code | 11 blank | 0 comment | 0 complexity | 019f3814cf49a938a3b7402fd08ada77 MD5 | raw file
 1<!--
 2The MIT License
 3
 4Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Yahoo! Inc., CloudBees, Inc.
 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  Overall form that should be placed inside <l:main-panel>
27
28  Attributes:
29    @descriptors : collection of Descriptors
30    @nameTitle   : title of the name text field
31    @copyTitle   : title of the copy option
32    @copyNames   : options of names to choose from as the copy source. null to hide "copy" option
33    @checkUrl    : form field validation url
34-->
35<?jelly escape-by-default='true'?>
36<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:s="/lib/form">
37  <j:set var="descriptors" value="${h.filterDescriptors(it,attrs.descriptors)}" />
38
39  <s:form method="post" action="createItem">
40    <s:entry title="${attrs.nameTitle}">
41      <s:textbox id="name" name="name" checkUrl="'${rootURL}/${attrs.checkUrl}?value='+encodeURIComponent(this.value)"
42                 onchange="updateOk(this.form)" onkeyup="updateOk(this.form)" />
43      <script>$('name').focus();</script>
44    </s:entry>
45
46    <j:forEach var="descriptor" items="${descriptors}">
47      <s:block>
48        <input type="radio" name="mode" value="${descriptor.class.name}" onchange="updateOk(this.form)" onclick="updateOk(this.form)" />
49        <st:nbsp/>
50        <label class="attach-previous"><b>${descriptor.displayName}</b></label>
51      </s:block>
52      <s:entry>
53        <st:set var="instance" value="${descriptor}" />
54        <st:include page="newInstanceDetail.jelly" it="${descriptor}" />
55      </s:entry>
56    </j:forEach>
57    <j:if test="${!empty(attrs.copyNames)}">
58      <s:block>
59        <input type="radio" name="mode" value="copy" onchange="updateOk(this.form)" onclick="updateOk(this.form)" />
60        <st:nbsp/>
61        <label class="attach-previous"><b>${attrs.copyTitle}</b></label>
62      </s:block>
63      <s:entry>
64        ${%Copy from}
65        <s:editableComboBox id="from" name="from" items="${attrs.copyNames}" />
66      </s:entry>
67    </j:if>
68
69    <s:block>
70      <!--
71        when there's only one radio above, form.elements['mode]' won't return an array, which makes the script complex.
72        So always force non-empty array
73       -->
74      <input type="radio" name="mode" value="dummy1" style="display:none" />
75      <input type="radio" name="mode" value="dummy2" style="display:none" />
76      <input type="submit" name="Submit" value="OK" id="ok" style="margin-left:5em" />
77    </s:block>
78  </s:form>
79  <script><![CDATA[
80    var okButton = makeButton($('ok'),null);
81
82    function updateOk(form) {
83      function state() {
84        if($('name').value.length==0)   return true;
85        var radio = form.elements['mode'];
86        if (radio.length==2)  return false; // this means we only have dummy checkboxes
87        for(i=0;i<radio.length;i++)
88          if(radio[i].checked)
89            return false;
90        return true;
91      }
92
93      okButton.set('disabled',state(),false);
94    }
95    updateOk(okButton.getForm());
96  ]]></script>
97</j:jelly>