aboutsummaryrefslogtreecommitdiffstats
path: root/winery/org.eclipse.winery.repository/src/main/webapp/WEB-INF/tags/servicetemplates/boundarydefinitions/browseForServiceTemplatePropertyReqOrCap.tag
blob: 430d4db5c859423c72bed3a1593e6f6f999ab05a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<%--
/*******************************************************************************
 * Copyright (c) 2013-2014 University of Stuttgart.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and the Apache License 2.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *    Oliver Kopp - initial API and implementation and/or initial documentation
 *******************************************************************************/
--%>

<%@tag pageEncoding="UTF-8"%>

<%@taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="bd" tagdir="/WEB-INF/tags/servicetemplates/boundarydefinitions" %>

<%@attribute name="definedPropertiesAsJSONString" required="true" %>

<div class="modal fade z1051" id="browseForServiceTemplatePropertyDiag" >
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">Choose Property of Service Template</h4>
			</div>

			<div class="modal-body">
				<p class="text-info">Please click on a node to select the element</p>
				<div id='propertymappingstree'></div>
				<form>
					<fieldset>
						<div class="form-group">
							<label for="newServiceTemplatePropertyRef">Reference to the property of the Service Template</label>
							<input type="text" id="newServiceTemplatePropertyRef" class="form-control" />
						</div>
					</fieldset>
				</form>
			</div>

			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				<button type="button" class="btn btn-primary" onclick="setServiceTemplatePropertyRef();">Set</button>
			</div>
		</div>
	</div>
</div>

<%-- Browse for property --%>
<%--
The following cannot be used as we return TWO things: the template and the property
<bd:browseForX XShort="Property" XLong="Node Template, Relationship Template, or directly a property" />
--%>
<div class="modal fade z1051" id="browseForTemplateProperty">
	<div class="modal-dialog" style="width:1000px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">Choose Node Template, Relationship Template, or directly a property</h4>
			</div>

			<div class="modal-body">
				<p class="text-info">Please click on the desired element</p>
				<iframe id="topologyTemplatePreview" class="topologyTemplatePreviewSizing" src="topologytemplate/?view=propertySelection&script=${pageContext.request.contextPath}/js/boundaryDefinitionsXSelection.js"></iframe>
				<form>
					<fieldset>
						<div class="form-group">
							<label for="newObjectRef">Reference to the object in the topology template</label>
							<input type="text" id="newObjectRef" class="form-control newObjectRef" /> <%-- newObjectRef required as  --%>
						</div>
						<div class="form-group">
							<label for="newObjectPropertyRef">Reference to the object's property</label>
							<input type="text" id="newObjectPropertyRef" class="form-control" />
						</div>
					</fieldset>
				</form>
			</div>

			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				<button type="button" class="btn btn-primary" onclick="setTemplateAndTemplatePropertyRef();">Set</button>
			</div>
		</div>
	</div>
</div>

<bd:browseForReqOrCap label="Requirement" reqOrCap="Req" requirementsOrCapabilities="requirements"/>
<bd:browseForReqOrCap label="Capability"  reqOrCap="Cap" requirementsOrCapabilities="capabilities"/>

<script>
//global variable to hold the reference to the input field where the selection of the service template property should be written into
//Requried as both a property mapping and a property constraint refer to a property of the service template.
var fieldToWriteSelectedServiceTemplateProperty;

function setServiceTemplatePropertyRef() {
	fieldToWriteSelectedServiceTemplateProperty.val($("#newServiceTemplatePropertyRef").val());
	$("#browseForServiceTemplatePropertyDiag").modal("hide");
}

function browseForServiceTemplateProperty(field) {
	fieldToWriteSelectedServiceTemplateProperty = field;
	$("#newServiceTemplatePropertyRef").val(field.val());
	$("#browseForServiceTemplatePropertyDiag").modal("show");
}


/**
 * Opens topology and lets user select a node template, relationship template,
 */
function browseForTemplateAndProperty() {
	$("#newObjectRef").val($("#targetObjectRef").val());
	$("#newObjectPropertyRef").val($("#targetPropertyRef").val());
	$("#browseForTemplateProperty").modal("show");
}

function setTemplateAndTemplatePropertyRef() {
	$("#targetObjectRef").val($("#newObjectRef").val());
	// always copy over targetPropertyRef, even if it's empty
	$("#targetPropertyRef").val($("#newObjectPropertyRef").val());

	$("#browseForTemplateProperty").modal("hide");
}

<c:if test="${not empty definedPropertiesAsJSONString}">
// initialize the xmltree of the service template properties
// xmltree has to be inialized once and not more than once
// Therefore, we put it here and not in some shown events
require(["xmltree"], function(xmltree) {
	new xmltree({
		xml: '${definedPropertiesAsJSONString}',
		container: '#propertymappingstree',
		startCollapsed: false,
		clickCallback: serviceTemplatePropertyClicked
	});
});
</c:if>

function serviceTemplatePropertyClicked(li, xpath, event) {
	require(["winery-support"], function(ws) {
		var pathFragmentRegExp = ws.QName_RegExp + "(.*)";
		var pathFragmentPattern = new RegExp(pathFragmentRegExp);

		// Transform the XPath to an XPath being namespace unaware
		// This is required as the OpenTOSCA container does not implement XPath processing in a namespace-aware manner
		var fragments = xpath.split("/");
		var path = [];
		$(fragments).each(function(i,e) {
			var res = pathFragmentPattern.exec(e);
			if (res != null) {
				if (typeof res[1] !== undefined) {
					e = "*[local-name()='" + res[3] + "']" + res[5];
				}
			}
			path.push(e);
		});
		xpath = path.join("/");

		$("#newServiceTemplatePropertyRef").val(xpath);
	});
}

/* communication with the iframe is at boundarydefinitions.jsp as we also need it for "Interfaces" */

</script>