aboutsummaryrefslogtreecommitdiffstats
path: root/winery/org.eclipse.winery.repository/src/main/webapp/jsp/servicetemplates/selfservicemetadata/selfservicemetadata.jsp
blob: d4d92336f493c57a28dfd9f4a815f28230c3231a (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<%--
/*******************************************************************************
 * Copyright (c) 2012-2013 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
 *******************************************************************************/
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="o" tagdir="/WEB-INF/tags/common/orioneditor"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
<%@taglib prefix="w" uri="http://www.eclipse.org/winery/repository/functions"%>

<%-- Upload functionality inspired by plans.jsp. That code could be generalized somehow in a .tag file --%>

<ul class="nav nav-tabs" id="myTab">
	<li class="active"><a href="#description">Description</a></li>
	<li><a href="#images">Images</a></li>
	<li><a href="#options">Options</a></li>
	<li><a href="#xml" id="showXMLTab">XML</a></li>
</ul>

<div class="tab-content">

	<div class="tab-pane active" id="description">
		<div class="form-group">
			<label class="label-form">Name</label>
			<a href="#" class="form-control" data-send="always" id="displayName" data-url="selfserviceportal/displayname" data-tile="Enter Display Name">${it.application.displayName}</a>
		</div>

		<div class="form-group">
			<label class="label-form">Description</label>
			<div class="form-control" id="applicationDescriptionDiv">${it.application.description}</div>
		</div>
	</div>

	<div class="tab-pane" id="images">

		<t:imageUpload
		label="Icon"
		URL="selfserviceportal/icon.jpg"
		id="upIcon"
		width="16px"
		accept="image/*"/>

		<t:imageUpload
		label="Preview"
		URL="selfserviceportal/image.jpg"
		id="upImage"
		width="100px"
		accept="image/*"/>

	</div>

	<div class="tab-pane" id="options">
		<button class="rightbutton btn btn-xs btn-danger" name="remove" onclick="deleteOnServerAndInTable(optionsTableInfo, 'Option', 'selfserviceportal/options/', 0, 1);">Remove</button>
		<button class="rightbutton btn btn-xs btn-info" name="add" onclick="$('#addOptionDiag').modal('show');">Add</button>
		<!--  <button class="rightbutton btn btn-xs btn-default" name="edit" onclick="openOptionEditor();">Edit</button> -->

		<table id="optionsTable">
			<thead>
				<tr>
					<th>Id</th>
					<th>Name</th>
					<th>Icon</th>
					<th>Plan Service Name</th>
				</tr>
			</thead>
			<tbody>
				<c:if test="${not empty it.application}">
					<c:forEach var="option" items="${it.application.options.option}">
						<tr>
							<td>${option.id}</td>
							<td>${option.name}</td>
							<td><img src="selfserviceportal/options/${w:URLencode(option.id)}/icon.jpg" style="width:50px;"></td>
							<td>${option.planServiceName}</td>
						</tr>
					</c:forEach>
				</c:if>
			</tbody>
		</table>
	</div>

	<div class="tab-pane" id="xml">
		<o:orioneditorarea areaid="XML" url="selfserviceportal/" reloadAfterSuccess="true">${it.applicationAsXMLStringEncoded}</o:orioneditorarea>
	</div>

</div>

<script>
function letUserChooseAFile() {
	$('#fileInput').trigger('click');
	$('#chooseBtn').focus();
}

$('#showXMLTab').on('shown.bs.tab', function (e) {
	window.winery.orionareas['XML'].fixEditorHeight();
});
</script>

<div class="modal fade" id="addOptionDiag">
	<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">Add Option</h4>
		</div>
		<div class="modal-body">
			<form id="addOptionForm" enctype="multipart/form-data" action="selfserviceportal/options/" method="post">
				<div class="form-group">
					<label class="control-label">Name</label>
					<input name="name" type="text" class="form-control" required="required">
				</div>

				<div class="form-group">
					<label class="control-label">Description</label>
					<textarea id="optionDescription" name="description" class="form-control" required="required"></textarea>
				</div>

				<div class="form-group">
					<label class="control-label" for="fileDiv">Icon</label>
					<div style="display: block; width: 100%" id="iconDiv">
						<input id="fileInput" name="file" type="file" style="display:none" accept="image/*">
						<input name="fileText" id="fileText" type="text" class="form-control" style="width:300px; display:inline;" onclick="letUserChooseAFile();" required="required">
						<button type="button" id="chooseBtn" class="btn btn-default btn-xs" onclick="letUserChooseAFile();">Choose</button>
					</div>
				</div>

				<div class="form-group">
					<label class="control-label">Plan Service Name</label>
					<input name="planServiceName" type="text" class="form-control" required="required">
				</div>

				<div class="form-group">
					<label class="control-label">Plan Input Message</label>
					<textarea name="planInputMessage" class="form-control" required="required" rows="20">&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
&lt;soapenv:Header/&gt;
&lt;soapenv:Body&gt;
&lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</textarea>
				</div>

			</form>
		</div>
		<div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
			<button type="button" class="btn btn-primary" data-loading-text="Uploading..." id="addOptionBtn">Add</button>
		</div>
	</div>
	</div>
</div>


<script>
$("#displayName").editable({
	ajaxOptions: {type: "PUT"},
	success: function() {
		vShowSuccess("Successfully updated display name");
	},
	error: function(response) {
		vShowError("Could not update display name: " + response.status + " " + response.responseText);
	}
});

$("#applicationDescriptionDiv").editable({
	type: "wysihtml5",
	send: "always",
	url: "selfserviceportal/description",
	ajaxOptions: {type: "PUT"},
	success: function() {
		vShowSuccess("Successfully updated description");
	},
	error: function(response) {
		vShowError("Could not update description: " + response.status + " " + response.responseText);
	}
});

$("#optionDescription").wysihtml5();

var optionsTableInfo = {
	id: '#optionsTable'
};

$('#myTab a').click(function (e) {
	e.preventDefault();
	$(this).tab('show');
});

$(function() {
	// initialize table and hide first column
	require(["winery-support"], function(ws) {
		ws.initTable(optionsTableInfo, {
			"aoColumnDefs": [
				{ "bSearchable": false, "bVisible": false, "aTargets": [ 0 ] }
			]
		});
	});

	$("#addOptionDiag").on("hidden.bs.modal", function() {
		// we currently do not send data back from the server
		// we emulate the AJAX refresh by a reaload
		doTheTabSelection(function() {
			$('#myTab a[href="#options"]').tab('show');
		});
	});
});

function createOption(data) {
	if (highlightRequiredFields()) {
		vShowError("Please fill out all required fields");
		return;
	}
	data.submit();
}

requirejs(["jquery.fileupload"], function(){
	$('#addOptionForm').fileupload({
		// dropping should only be available in the addOptionDialog. This, however, does not work correctly
		dropZone: $("#addOptionDiag")
	}).bind("fileuploadadd", function(e, data) {
		$.each(data.files, function (index, file) {
			$("#fileText").val(file.name);
		});
		$("#addOptionBtn").off("click");
		$("#addOptionBtn").on("click", function() {
			createOption(data);
		});
	}).bind("fileuploadstart", function(e) {
		$("#addOptionBtn").button("loading");
	}).bind('fileuploadfail', function(e, data) {
		vShowAJAXError("Could not add option", data.jqXHR, data.errorThrown);
		$("#addOptionBtn").button("reset");
	}).bind('fileuploaddone', function(e, data) {
		vShowSuccess("Option created successfully.");

		// reset the add button
		$("#addOptionBtn").button("reset");
		// do not allow submission of the old files on a click if the dialog is opened another time
		$("#addOptionBtn").off("click");

		// TODO: add data
		//embeddedPlansTableInfo.table.fnAddData(data.result.tableData);
		// current workaround: event on hidden.bs.modal

		$('#addOptionDiag').modal('hide');
	});
});

</script>