/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. <!--
  2. The MIT License
  3. Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Yahoo! Inc., CloudBees, Inc.
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. -->
  20. <!--
  21. Overall form that should be placed inside <l:main-panel>
  22. Attributes:
  23. @descriptors : collection of Descriptors
  24. @nameTitle : title of the name text field
  25. @copyTitle : title of the copy option
  26. @copyNames : options of names to choose from as the copy source. null to hide "copy" option
  27. @checkUrl : form field validation url
  28. -->
  29. <?jelly escape-by-default='true'?>
  30. <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">
  31. <j:set var="descriptors" value="${h.filterDescriptors(it,attrs.descriptors)}" />
  32. <s:form method="post" action="createItem">
  33. <s:entry title="${attrs.nameTitle}">
  34. <s:textbox id="name" name="name" checkUrl="'${rootURL}/${attrs.checkUrl}?value='+encodeURIComponent(this.value)"
  35. onchange="updateOk(this.form)" onkeyup="updateOk(this.form)" />
  36. <script>$('name').focus();</script>
  37. </s:entry>
  38. <j:forEach var="descriptor" items="${descriptors}">
  39. <s:block>
  40. <input type="radio" name="mode" value="${descriptor.class.name}" onchange="updateOk(this.form)" onclick="updateOk(this.form)" />
  41. <st:nbsp/>
  42. <label class="attach-previous"><b>${descriptor.displayName}</b></label>
  43. </s:block>
  44. <s:entry>
  45. <st:set var="instance" value="${descriptor}" />
  46. <st:include page="newInstanceDetail.jelly" it="${descriptor}" />
  47. </s:entry>
  48. </j:forEach>
  49. <j:if test="${!empty(attrs.copyNames)}">
  50. <s:block>
  51. <input type="radio" name="mode" value="copy" onchange="updateOk(this.form)" onclick="updateOk(this.form)" />
  52. <st:nbsp/>
  53. <label class="attach-previous"><b>${attrs.copyTitle}</b></label>
  54. </s:block>
  55. <s:entry>
  56. ${%Copy from}
  57. <s:editableComboBox id="from" name="from" items="${attrs.copyNames}" />
  58. </s:entry>
  59. </j:if>
  60. <s:block>
  61. <!--
  62. when there's only one radio above, form.elements['mode]' won't return an array, which makes the script complex.
  63. So always force non-empty array
  64. -->
  65. <input type="radio" name="mode" value="dummy1" style="display:none" />
  66. <input type="radio" name="mode" value="dummy2" style="display:none" />
  67. <input type="submit" name="Submit" value="OK" id="ok" style="margin-left:5em" />
  68. </s:block>
  69. </s:form>
  70. <script><![CDATA[
  71. var okButton = makeButton($('ok'),null);
  72. function updateOk(form) {
  73. function state() {
  74. if($('name').value.length==0) return true;
  75. var radio = form.elements['mode'];
  76. if (radio.length==2) return false; // this means we only have dummy checkboxes
  77. for(i=0;i<radio.length;i++)
  78. if(radio[i].checked)
  79. return false;
  80. return true;
  81. }
  82. okButton.set('disabled',state(),false);
  83. }
  84. updateOk(okButton.getForm());
  85. ]]></script>
  86. </j:jelly>