Skip to content

Commit

Permalink
Add toggle switch, add title
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Oct 7, 2021
1 parent 00eac4f commit 5baf1be
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/main/resources/jenkins/model/Jenkins/configure.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ THE SOFTWARE.
<st:include page="sidepanel.jelly" />
<f:breadcrumb-config-outline />
<l:main-panel>
<div class="jenkins-app-bar">
<div class="jenkins-app-bar__content">
<h1>Configure System</h1>
</div>
</div>
<div class="behavior-loading">${%LOADING}</div>
<f:form method="post" name="config" action="configSubmit">
<j:set var="instance" value="${it}" />
Expand Down
87 changes: 87 additions & 0 deletions core/src/main/resources/lib/form/toggleSwitch.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
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:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<st:documentation>
&lt;input type="checkbox"> tag that takes true/false for @checked, which is more Jelly friendly.

<st:attribute name="name" />
<st:attribute name="checked" />
<st:attribute name="value" />
<st:attribute name="json">
Normally, the submitted JSON will be boolean indicating whether the checkbox was checked or not.
This is sometimes inconvenient if you have a UI that lets user select a subset of a set.
If this attribute is present, the submitted JSON will have this as a string value if the checkbox is checked,
and none otherwise, making the subset selection easier.
</st:attribute>
<st:attribute name="default">
The default value of the check box, in case both @checked and @instance are null.
If this attribute is unspecified or null, it defaults to unchecked, otherwise checked.
</st:attribute>
<st:attribute name="id" />
<st:attribute name="onclick" />
<st:attribute name="class" />
<st:attribute name="negative" />
<st:attribute name="readonly">
If set to true, this will take precedence over the onclick attribute and prevent the state of the checkbox from being changed.

Note: if you want an actual read only checkbox then add:
&lt;j:set var="readOnlyMode" value="true"/&gt; inside your entry tag
See https://www.jenkins.io/doc/developer/views/read-only/#enabling-read-only-view-support
</st:attribute>
<st:attribute name="field">
Used for databinding. TBD.
</st:attribute>
<st:attribute name="title">
If specified, this human readable text will follow the checkbox, and clicking this text also
toggles the checkbox.
</st:attribute>
<st:attribute name="tooltip">
Used as tooltip of the checkbox, and, if a title is specified, of the title
</st:attribute>
</st:documentation>
<f:prepareDatabinding />
<j:set var="name" value="${attrs.name ?: '_.'+attrs.field}"/>
<j:set var="default" value="${attrs.default ?: false}"/>
<j:set var="value" value="${attrs.checked ?: instance[attrs.field] ?: default}"/>

<span class="jenkins-toggle-switch">
<input type="checkbox"
name="${name}"
value="${attrs.value}"
title="${attrs.tooltip}"
onclick="${attrs.readonly=='true' ? 'return false;' : attrs.onclick}"
id="${attrs.id}"
class="${attrs.class} ${attrs.negative!=null ? 'negative' : null} ${attrs.checkUrl!=null?'validated':''}"
checkUrl="${attrs.checkUrl}"
checkDependsOn="${attrs.checkDependsOn}" json="${attrs.json}"
disabled="${readOnlyMode ? 'true' : null}"
checked="${value ? 'true' : null}"/>
<label class="attach-previous">${attrs.title}</label>
<j:if test="${attrs.description != null and !attrs.description.trim().isEmpty()}">
<span class="jenkins-toggle-switch__description">${attrs.description}</span>
</j:if>
</span>
</j:jelly>

0 comments on commit 5baf1be

Please sign in to comment.