aboutsummaryrefslogtreecommitdiffstats
path: root/winery/org.eclipse.winery.repository/src/main/webapp/WEB-INF/tags/parameters/parametersJS.tag
blob: 021c8c06c45ff4575197290908534855960dc449 (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
167
168
169
170
171
172
173
174
175
176
177
<%--
/*******************************************************************************
 * Copyright (c) 2012-2013,2015 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 description="Input and Output parameters handling. Used at interface/operation and plan" pageEncoding="UTF-8"%>

<%@attribute name="afterLoad" description="JavaScript code to be executed after successfully loading/initialization"%>

<script>
var inputParametersTableInfo = {
	id: '#inputparameterstab'
};

var outputParametersTableInfo = {
	id: '#outputparameterstab'
};

$(function() {
	// for options see http://datatables.net/usage/options#sDom
	var opts = {
				"sDom": '<"H"r>t<"F"ip>',
				"iDisplayLength" : 3
			};

	require(["winery-support"], function(ws) {
		ws.initTable(inputParametersTableInfo, opts);
		$(inputParametersTableInfo.id).click(function(event) {
			if (inputParametersTableInfo.selectedRow) {
				// something has been selected
				$("#removeInParBtn").removeAttr("disabled");
			} else {
				// row has been deselected
				$("#removeInParBtn").attr("disabled", "disabled");
			}
		});

		ws.initTable(outputParametersTableInfo, opts, function() {
			${afterLoad}
		});
		$(outputParametersTableInfo.id).click(function(event) {
			if (outputParametersTableInfo.selectedRow) {
				// something has been selected
				$("#removeOutParBtn").removeAttr("disabled");
			} else {
				// row has been deselected
				$("#removeOutParBtn").attr("disabled", "disabled");
			}
		});
	});

});

function afterInputParameterCreation(serializedArray, resData, textStatus, jqXHR) {
	var required;
	if (serializedArray.length == 2) {
		required = "no";
	} else {
		required = serializedArray[2].value;
	}
	addRowToParameterstable(inputParametersTableInfo, serializedArray[0].value, serializedArray[1].value, required);
}

function afterOutputParameterCreation(serializedArray, resData, textStatus, jqXHR) {
	var required;
	if (serializedArray.length == 2) {
		required = "no";
	} else {
		required = serializedArray[2].value;
	}
	addRowToParameterstable(outputParametersTableInfo, serializedArray[0].value, serializedArray[1].value, required);
}

function createInputParameter(baseURL) {
	var url = baseURL + "inputparameters/";
	createResource('Input Parameter', [
			{'label': 'Name', 'name':'name'},
			{
				label: 'Type',
				name: 'type',
				hint:'TOSCA v1.0 does not specify any type system here. The content of this field is a string. The concrete semantics is left open. The convension is to use the xsd prefix for XML Schema basic types.'
			},
			{'label':'Required', 'name':'required', 'type': 'checkbox'}
		],
		url,
		afterInputParameterCreation);
}

function createOutputParameter(baseURL) {
	var url = baseURL + "outputparameters/";
	createResource('Output Parameter', [
			{'label': 'Name', 'name':'name'},
			{
				label: 'Type',
				name: 'type',
				hint:'TOSCA v1.0 does not specify any type system here. The content of this field is a string. The concrete semantics is left open. The convension is to use the xsd prefix for XML Schema basic types.'
			},
			{'label':'Required', 'name':'required', 'type': 'checkbox'}
		],
		url,
		afterOutputParameterCreation);
}

function addRowToParameterstable(tableInfo, name, type, required) {
	var checked;
	required = required.toLowerCase();
	if ((required == "yes") || (required == "on")) {
		checked = ' checked="checked"';
	} else {
		checked = "";
	}
	var checkbox = '<input type="checkbox"' + checked + ' disabled="disabled"></input>';
	var addData = [name, type, checkbox];
	tableInfo.table.fnAddData(addData);
}

function deleteInputParameter() {
	deleteOnServerAndInTable(inputParametersTableInfo, "Input Parameter", getOperationURL() + "inputparameters/");
}

function deleteOutputParameter() {
	deleteOnServerAndInTable(outputParametersTableInfo, "Output Parameter", getOperationURL() + "outputparameters/");
}

/**
 * only called if operation is selected
 *
 * @param url: the URL to query the parameters data
 * @param inOrOut: "In"|"Out"
 */
function updateParameters(url, tableInfo, inOrOut) {
	$.ajax({
		"url": url,
		dataType: "json",
		success: function(data) {
			tableInfo.table.fnClearTable();
			$.each(data, function(number, item) {
				var paramURL = url + item + "/";
				$.ajax({
					async: false,
					dataType: "json",
					url: paramURL,
					error: function(jqXHR, textStatus, errorThrown) {
						vShowAJAXError("Could not fetch operation information", jqXHR, errorThrown);
					},
					success: function(data) {
						addRowToParameterstable(tableInfo, data.name, data.type, data.required);
					}
				});
			});
			$("#add" + inOrOut + "ParBtn").removeAttr("disabled");

			// remove button should always be disalbed as it gets enabled only after clicking a row in the table
			$("#remove" + inOrOut + "ParBtn").attr("disabled", "disabled");
		},
		error: function(jqXHR, textStatus, errorThrown) {
			vShowAJAXError("Could not fetch interface", jqXHR, errorThrown);
		}
	});
}

function updateInputAndOutputParameters(baseURL) {
	var url = baseURL + "inputparameters/";
	updateParameters(url, inputParametersTableInfo, "In");
	url = baseURL + "outputparameters/";
	updateParameters(url, outputParametersTableInfo, "Out");
}

</script>