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
11 * Oliver Kopp - initial API and implementation and/or initial documentation
12 * Yves Schubert - switch to bootstrap 3
13 *******************************************************************************/
15 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
16 <%@taglib prefix="t" tagdir="/WEB-INF/tags"%>
17 <%@taglib prefix="ct" tagdir="/WEB-INF/tags/common"%>
18 <%@taglib prefix="w" uri="http://www.eclipse.org/winery/repository/functions"%>
20 <%-- createResource of winery-support.js could be used. However, currently selects are not supported --%>
21 <div class="modal fade" id="addPropertyDiag">
22 <div class="modal-dialog">
23 <div class="modal-content">
24 <div class="modal-header">
25 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
26 <h4 class="modal-title">Add Property</h4>
28 <div class="modal-body">
29 <form id="addPropertyForm">
30 <div class="form-group">
31 <label class="control-label" for="propName">Name</label>
32 <input name="key" class="form-control" id="propName" type="text" />
35 <div class="form-group">
36 <label class="control-label" for="propType">Type</label>
37 <select name="type" class="form-control" id="propType">
38 <c:forEach var="t" items="${it.availablePropertyTypes}">
39 <option value="${t}">${t}</option>
45 <div class="modal-footer">
46 <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
47 <button type="button" class="btn btn-primary" onclick="createProperty();">Add</button>
54 function noneClicked() {
55 disableKVproperties();
56 clearXSDElementSelection();
57 clearXSDTypeSelection();
59 url: "propertiesdefinition/",
62 error: function(jqXHR, textStatus, errorThrown) {
63 vShowAJAXError("Could not remove properties definition", jqXHR, errorThrown);
68 function clearXSDElementSelection() {
69 $("#xsdelement").editable('setValue', "", true);
72 function clearXSDTypeSelection() {
73 $("#xsdtype").editable('setValue', "", true);
77 $("#xsdelement").editable({
81 source: ${w:allXSDElementDefinitionsForTypeAheadSelection()}
83 $("#xsdelement").on("click", function(e){
84 $("#xsdelementradio").prop("checked", true);
87 $("#xsdtype").editable({
89 source: ${w:allXSDTypeDefinitionsForTypeAheadSelection()}
91 $("#xsdtype").on("click", function(e){
92 $("#xsdtyperadio").prop("checked", true);
95 /* make UI more nice: enable click on label */
96 $("#textnone").on("click", function(e){
97 $("#nopropdef").prop("checked", true);
100 $("#textxmlelement").on("click", function(e){
101 $("#xsdelementradio").prop("checked", true);
102 disableKVproperties();
103 clearXSDTypeSelection();
105 $("#textxmltype").on("click", function(e){
106 $("#xsdtyperadio").prop("checked", true);
107 disableKVproperties();
108 clearXSDElementSelection();
110 $("#textcustomkv").on("click", function(e){
111 $("#customkv").prop("checked", true);
112 updateKVpropertiesVisibility();
113 setKVPropertiesOnServer();
114 clearXSDElementSelection();
115 clearXSDTypeSelection();
118 $('#kvPropsTabs a').click(function (e) {
123 $("#addPropertyDiag").on("shown.bs.modal", function() {
124 $("#propName").focus();
130 <%-- TODO: if clicked on the "label" of the input field (i.e., the content of the input tag), the input should be selected. This is not the default at HTML5 - see http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_radio --%>
132 <input id="nopropdef" type="radio" name="kind" value="none" <c:if test="${not it.isWineryKeyValueProperties and empty it.entityType.propertiesDefinition.element and empty t.entityType.propertiesDefinition.type}">checked="checked"</c:if>><span class="cursorpointer" id="textnone">(none)</span></input>
135 <input id="xsdelementradio" type="radio" name="kind" value="element" <c:if test="${not empty it.entityType.propertiesDefinition.element}">checked="checked"</c:if>><span class="cursorpointer" id="textxmlelement">XML element</span></input>
136 <a href="#" id="xsdelement" data-url="propertiesdefinition/" data-send="always" data-title="Select XSD Element" data-value="${it.entityType.propertiesDefinition.element}"><c:if test="${not empty it.entityType.propertiesDefinition.element}">${it.entityType.propertiesDefinition.element.localPart}</c:if></a>
139 <input id="xsdtyperadio" type="radio" name="kind" value="type" <c:if test="${not empty it.entityType.propertiesDefinition.type}">checked="checked"</c:if>><span class="cursorpointer" id="textxmltype">XML type</span></input>
140 <a href="#" id="xsdtype" data-url="propertiesdefinition/" data-send="always" data-title="Select XSD Type" data-value="${it.entityType.propertiesDefinition.type}"><c:if test="${not empty it.entityType.propertiesDefinition.type}">${it.entityType.propertiesDefinition.type.localPart}</c:if></a>
144 <input id="customkv" type="radio" name="kind" value="KV" <c:if test="${it.isWineryKeyValueProperties and not it.isWineryKeyValuePropertiesDerivedFromXSD}">checked="checked"</c:if>><span class="cursorpointer" id="textcustomkv">Custom key/value pairs</span></input>
147 <div id="Properties" style="display:none; margin-left:20px;">
148 <ul class="nav nav-tabs" id="kvPropsTabs">
149 <li class="active"><a href="#kvProps">Properties</a></li>
150 <li><a href="#wrapper">Wrapping</a></li>
153 <div class="tab-content">
154 <div class="tab-pane active" id="kvProps">
156 <button class="rightbutton btn btn-danger btn-xs" type="button" onclick="deleteOnServerAndInTable(propertiesTableInfo, 'Property', 'propertiesdefinition/winery/list/');">Remove</button>
157 <button class="rightbutton btn btn-primary btn-xs" type="button" onclick="$('#addPropertyDiag').modal('show');">Add</button>
159 <table cellpadding="0" cellspacing="0" border="0" class="display" id="propertiesTable">
167 <c:if test="${it.isWineryKeyValueProperties}">
168 <c:forEach var="t" items="${it.propertyDefinitionKVList}">
171 <%-- FIXME: t.type is the short type, but we need the full type. Currently, there is no way to get the full type for a short type --%>
180 <div class="tab-pane" id="wrapper">
181 <form id="wrapperelementform" enctype="multipart/form-data">
183 <div style="width:400px;">
184 <div class="form-group">
185 <label for="wrapperelement_name">Name of Wrapper Element</label>
186 <a href="#" class="form-control" id="wrapperelement_name" data-url="propertiesdefinition/winery/elementname" data-send="always" data-title="Local Name" data-type="text" data-value="${it.elementName}"></a>
188 <t:namespaceChooser idOfInput="wrapperelement_ns" selected="${it.namespace}" allNamespaces="${w:allNamespaces()}"></t:namespaceChooser>
197 function disableKVproperties() {
198 $("#Properties").hide();
201 function enableKVproperties() {
202 $("#Properties").show();
205 function updateKVpropertiesVisibility() {
206 if ($("input[name='kind']:checked").val() == "KV") {
207 enableKVproperties();
209 disableKVproperties();
213 function setKVPropertiesOnServer() {
215 url: "propertiesdefinition/winery/",
218 error: function(jqXHR, textStatus, errorThrown) {
219 vShowAJAXError("Could change to custom key/value pairs", jqXHR, errorThrown);
225 // put change function on all inputs to get notified of any change by the user
226 $("input[name='kind']").on("change", function(e) {
227 // we do not POST something to the server as only concrete values really trigger a change on server side
228 var target = e.currentTarget.value;
229 if (target == "none") {
231 } else if (target == "element") {
232 disableKVproperties();
233 clearXSDTypeSelection();
234 } else if (target == "type") {
235 disableKVproperties();
236 clearXSDElementSelection();
237 enableKVproperties();
238 } else if (target == "KV") {
239 <c:if test="${not it.isWineryKeyValuePropertiesDerivedFromXSD}">
240 <%-- only empty the k/v properties if not derived from XSD--%>
241 setKVPropertiesOnServer();
243 clearXSDElementSelection();
244 clearXSDTypeSelection();
246 vShowError("UI not consistent to code");
250 // initialization - display the custom box to enter k/vs only if KV is selected
251 updateKVpropertiesVisibility();
253 $("#wrapperelement_name").editable({
257 params: function(params) {
258 // adjust params according to Winery's expectations
260 params.name = params.value;
264 }).on("save", function(e, params) {
265 vShowSuccess("Successfully updated local name of wrapper element");
268 $("#wrapperelement_ns").on("change", function(e) {
270 url: "propertiesdefinition/winery/namespace",
273 contentType: "text/plain",
276 error: function(jqXHR, textStatus, errorThrown) {
277 vShowAJAXError("Could not update namespace", jqXHR, errorThrown);
279 success: function(data, textStatus, jqXHR) {
280 vShowSuccess("Successfully updated namespace");
286 var propertiesTableInfo = {
287 id: '#propertiesTable'
290 require(["winery-support"], function(ws) {
291 ws.initTable(propertiesTableInfo);
294 function createProperty() {
296 key: $("#propName").val(),
297 type: $('#propType :selected').text()
300 url: "propertiesdefinition/winery/list/",
303 contentType: "application/json",
305 data: JSON.stringify(data),
306 error: function(jqXHR, textStatus, errorThrown) {
307 vShowAJAXError("Could not add property", jqXHR, errorThrown);
309 success: function(data, textStatus, jqXHR) {
310 var name = $('#propName').val();
311 var type = $('#propType :selected').text();
312 var dataToAdd = [name, type];
313 propertiesTableInfo.table.fnAddData(dataToAdd);
314 vShowSuccess("Property successfully added");
315 $('#addPropertyDiag').modal('hide');