Merge "Fix build errors in autorelease full clean build"
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.topologymodeler / src / main / webapp / WEB-INF / tags / common / spinnerwithinphty.tag
1 <%--
2 /*******************************************************************************
3  * Copyright (c) 2013 University of Stuttgart.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and the Apache License 2.0 which both accompany this distribution,
7  * and are available at http://www.eclipse.org/legal/epl-v10.html
8  * and http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Contributors:
11  *    Yves Schubert - initial API and implementation and/or initial documentation
12  *    Oliver Kopp - minor improvements
13  *******************************************************************************/
14 --%>
15 <%@tag description="A spinner with the possibility to set to inphty via button" pageEncoding="UTF-8"%>
16 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
17
18 <%-- Code copied between repository and topology-modeler --%>
19
20 <%--
21 Could also be realized as
22  * HTML5 Web Component (http://www.ibm.com/developerworks/library/wa-html5components1/) or
23  * x-tags (http://www.x-tags.org/)
24 We decided to use JSP tags to avoid an additional JavaScript library
25 --%>
26
27 <%@attribute name="label" required="true"%>
28 <%@attribute name="id" required="true"%>
29 <%@attribute name="min"%>
30 <%@attribute name="max" required="false" description="Maximum value. Default is 1000. The underlying library does not allow arbitrary high values."%>
31 <%@attribute name="name" required="false" description="The name of the input field. Defaults to the id"%>
32 <%@attribute name="withinphty" required="false" description="If set, then an inphty button is provded"%>
33 <%@attribute name="value"%>
34 <%@attribute name="width" required="false" description="The Column with according to bootstrap rules. Default is 3 (should not be smaller)."%>
35 <%@attribute name="changedfunction" required="false" description="Called if value changed"%>
36
37 <%-- Set default name value if required --%>
38 <c:if test="${empty name}">
39         <c:set var="name" value="${id}"></c:set>
40 </c:if>
41
42 <c:if test="${empty width}">
43         <c:set var="width" value="3"></c:set>
44 </c:if>
45
46 <div class="form-group">
47         <label for="${id}">${label}</label>
48         <div class="row">
49                 <div class="col-lg-${width}">
50                     <div class="input-group">
51                                 <input id="${id}" class="spinner form-control" name="${name}" type="text" <c:if test="${not empty changedfunction}">onblur="${changedfunction}();"</c:if>/>
52                                 <c:if test="${not empty withinphty}">
53                                         <span class="input-group-addon" style="cursor: pointer; border-left:0" onclick="setToInfin('${id}'<c:if test="${not empty changedfunction}">, ${changedfunction}</c:if>);">&infin;</span>
54                                 </c:if>
55                         </div>
56                 </div>
57         </div>
58 </div>
59
60 <script>
61 <%--
62 included multiple times.
63 Drawback when not using HTML5 components and keeping the JavaScript functions closed to the HTML code
64 --%>
65 function setToInfin(id, changedFunction) {
66         var spinner = $("#" + id);
67         spinner.val('∞'); // &inphty; - jQuery does not decode that, but places the plain text. Therefore, we directly pass the char we want
68         if (changedFunction !== undefined) {
69                 changedFunction();
70         }
71 }
72
73 $(function() {
74         var param = {}
75         <c:if test="${not empty min}">
76         param.minimum = "${min}";
77         </c:if>
78         <c:if test="${empty max}">
79         param.maximum = 1000;
80         </c:if>
81
82         // use bootstrap-spinedit plugin
83         $("#${id}").spinedit(param);
84
85         <c:if test="${not empty changedfunction}">
86         $("#${id}").on('valueChanged', ${changedfunction});
87         </c:if>
88
89 });
90
91 </script>
92