56b0712dbc1958a2f813c100d6dd97e5e5254266
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / webapp / WEB-INF / tags / namespaceChooser.tag
1 <%--
2 /*******************************************************************************
3  * Copyright (c) 2012-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  *    Oliver Kopp - initial API and implementation and/or initial documentation
12  *******************************************************************************/
13 --%>
14 <%@tag description="places a bootstrap form control to chooose a namespace. A new namespace can be created" pageEncoding="UTF-8"%>
15
16 <!--
17   This tag is shared at repository and topologytemplate.
18   Both versions differ from each other.
19   In the repository, ns.decoded is used.
20   In the topology modeler only "ns" is used:
21   In other words: The topology modeler passes a Collection<String>, whereas repository passes Collection<Namespace>
22  -->
23
24 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
25
26 <%@attribute name="allNamespaces" required="true" type="java.util.Collection" description="All known namespaces"%>
27 <%@attribute name="idOfInput" required="true" description="The id if the input field storing the namespace. Also used as name"%>
28 <%@attribute name="nameOfInput" required="false" description="The name if the input field storing the namespace. If not provided, ifOfInput is used"%>
29 <%@attribute name="selected" description="The currently selected namespace (optional)"%>
30
31 <c:if test="${empty nameOfInput}"><c:set var="nameOfInput" value="${idOfInput}"></c:set></c:if>
32
33 <!-- createArtifactTemplate class is required for artifactcreationdialog -->
34 <div class="form-group createArtifactTemplate">
35         <label for="${idOfInput}" class="control-label">Namespace</label>
36         <input type="hidden" class="form-control" name="${nameOfInput}" id="${idOfInput}"></input>
37 </div>
38
39 <script>
40 // we have to use data as select2 does not allow "createSearchChoice" when using <select> as underlying html element
41 $("#${idOfInput}").select2({
42         createSearchChoice: function(term) {
43                 // enables creation of new namespaces
44                 return {id:term, text:term};
45         },
46         data:[
47                 <c:forEach var="ns" items="${allNamespaces}" varStatus="loop">
48                         {id:"${ns.decoded}",text:"${ns.decoded}"}<c:if test="${!loop.last}">,</c:if>
49                 </c:forEach>
50         ]
51 }).select2("val", "${selected}");
52 </script>