Merge "Inherit from oparent"
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / webapp / WEB-INF / tags / servicetemplates / boundarydefinitions / browseForServiceTemplatePropertyReqOrCap.tag
1 <%--
2 /*******************************************************************************
3  * Copyright (c) 2013-2014 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
15 <%@tag pageEncoding="UTF-8"%>
16
17 <%@taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
18 <%@taglib prefix="bd" tagdir="/WEB-INF/tags/servicetemplates/boundarydefinitions" %>
19
20 <%@attribute name="definedPropertiesAsJSONString" required="true" %>
21
22 <div class="modal fade z1051" id="browseForServiceTemplatePropertyDiag" >
23         <div class="modal-dialog">
24                 <div class="modal-content">
25                         <div class="modal-header">
26                                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
27                                 <h4 class="modal-title">Choose Property of Service Template</h4>
28                         </div>
29
30                         <div class="modal-body">
31                                 <p class="text-info">Please click on a node to select the element</p>
32                                 <div id='propertymappingstree'></div>
33                                 <form>
34                                         <fieldset>
35                                                 <div class="form-group">
36                                                         <label for="newServiceTemplatePropertyRef">Reference to the property of the Service Template</label>
37                                                         <input type="text" id="newServiceTemplatePropertyRef" class="form-control" />
38                                                 </div>
39                                         </fieldset>
40                                 </form>
41                         </div>
42
43                         <div class="modal-footer">
44                                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
45                                 <button type="button" class="btn btn-primary" onclick="setServiceTemplatePropertyRef();">Set</button>
46                         </div>
47                 </div>
48         </div>
49 </div>
50
51 <%-- Browse for property --%>
52 <%--
53 The following cannot be used as we return TWO things: the template and the property
54 <bd:browseForX XShort="Property" XLong="Node Template, Relationship Template, or directly a property" />
55 --%>
56 <div class="modal fade z1051" id="browseForTemplateProperty">
57         <div class="modal-dialog" style="width:1000px;">
58                 <div class="modal-content">
59                         <div class="modal-header">
60                                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
61                                 <h4 class="modal-title">Choose Node Template, Relationship Template, or directly a property</h4>
62                         </div>
63
64                         <div class="modal-body">
65                                 <p class="text-info">Please click on the desired element</p>
66                                 <iframe id="topologyTemplatePreview" class="topologyTemplatePreviewSizing" src="topologytemplate/?view=propertySelection&script=${pageContext.request.contextPath}/js/boundaryDefinitionsXSelection.js"></iframe>
67                                 <form>
68                                         <fieldset>
69                                                 <div class="form-group">
70                                                         <label for="newObjectRef">Reference to the object in the topology template</label>
71                                                         <input type="text" id="newObjectRef" class="form-control newObjectRef" /> <%-- newObjectRef required as  --%>
72                                                 </div>
73                                                 <div class="form-group">
74                                                         <label for="newObjectPropertyRef">Reference to the object's property</label>
75                                                         <input type="text" id="newObjectPropertyRef" class="form-control" />
76                                                 </div>
77                                         </fieldset>
78                                 </form>
79                         </div>
80
81                         <div class="modal-footer">
82                                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
83                                 <button type="button" class="btn btn-primary" onclick="setTemplateAndTemplatePropertyRef();">Set</button>
84                         </div>
85                 </div>
86         </div>
87 </div>
88
89 <bd:browseForReqOrCap label="Requirement" reqOrCap="Req" requirementsOrCapabilities="requirements"/>
90 <bd:browseForReqOrCap label="Capability"  reqOrCap="Cap" requirementsOrCapabilities="capabilities"/>
91
92 <script>
93 //global variable to hold the reference to the input field where the selection of the service template property should be written into
94 //Requried as both a property mapping and a property constraint refer to a property of the service template.
95 var fieldToWriteSelectedServiceTemplateProperty;
96
97 function setServiceTemplatePropertyRef() {
98         fieldToWriteSelectedServiceTemplateProperty.val($("#newServiceTemplatePropertyRef").val());
99         $("#browseForServiceTemplatePropertyDiag").modal("hide");
100 }
101
102 function browseForServiceTemplateProperty(field) {
103         fieldToWriteSelectedServiceTemplateProperty = field;
104         $("#newServiceTemplatePropertyRef").val(field.val());
105         $("#browseForServiceTemplatePropertyDiag").modal("show");
106 }
107
108
109 /**
110  * Opens topology and lets user select a node template, relationship template,
111  */
112 function browseForTemplateAndProperty() {
113         $("#newObjectRef").val($("#targetObjectRef").val());
114         $("#newObjectPropertyRef").val($("#targetPropertyRef").val());
115         $("#browseForTemplateProperty").modal("show");
116 }
117
118 function setTemplateAndTemplatePropertyRef() {
119         $("#targetObjectRef").val($("#newObjectRef").val());
120         // always copy over targetPropertyRef, even if it's empty
121         $("#targetPropertyRef").val($("#newObjectPropertyRef").val());
122
123         $("#browseForTemplateProperty").modal("hide");
124 }
125
126 <c:if test="${not empty definedPropertiesAsJSONString}">
127 // initialize the xmltree of the service template properties
128 // xmltree has to be inialized once and not more than once
129 // Therefore, we put it here and not in some shown events
130 require(["xmltree"], function(xmltree) {
131         new xmltree({
132                 xml: '${definedPropertiesAsJSONString}',
133                 container: '#propertymappingstree',
134                 startCollapsed: false,
135                 clickCallback: serviceTemplatePropertyClicked
136         });
137 });
138 </c:if>
139
140 function serviceTemplatePropertyClicked(li, xpath, event) {
141         require(["winery-support"], function(ws) {
142                 var pathFragmentRegExp = ws.QName_RegExp + "(.*)";
143                 var pathFragmentPattern = new RegExp(pathFragmentRegExp);
144
145                 // Transform the XPath to an XPath being namespace unaware
146                 // This is required as the OpenTOSCA container does not implement XPath processing in a namespace-aware manner
147                 var fragments = xpath.split("/");
148                 var path = [];
149                 $(fragments).each(function(i,e) {
150                         var res = pathFragmentPattern.exec(e);
151                         if (res != null) {
152                                 if (typeof res[1] !== undefined) {
153                                         e = "*[local-name()='" + res[3] + "']" + res[5];
154                                 }
155                         }
156                         path.push(e);
157                 });
158                 xpath = path.join("/");
159
160                 $("#newServiceTemplatePropertyRef").val(xpath);
161         });
162 }
163
164 /* communication with the iframe is at boundarydefinitions.jsp as we also need it for "Interfaces" */
165
166 </script>