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 *******************************************************************************/
14 <%@tag description="Has to be included once before ussage of properties.tag. Used in topology modeler and in properties.jsp of entitytemplates" pageEncoding="UTF-8"%>
16 <%@tag import="org.eclipse.winery.common.constants.Namespaces" %>
18 <%@taglib prefix="o" tagdir="/WEB-INF/tags/common/orioneditor"%>
20 <div class="modal fade" id="PropertyXMLDiag">
21 <div class="modal-dialog">
22 <div class="modal-content">
23 <div class="modal-header">
24 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
25 <h4 class="modal-title">Property</h4>
27 <div class="modal-body">
28 <!-- embed the XML editor without a save button. We provide the save button by ourselves -->
29 <o:orioneditorarea areaid="PropertyXML" withoutsavebutton="true"/>
31 <div class="modal-footer">
32 <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
33 <button type="button" class="btn btn-primary" onclick="savePropertiesXMLChanges();">Save</button>
40 // global variable set by editPropertiesXML and read by savePropertiesXMLChanges
41 var nodeTemplateIdsTextAreaPropertiesXMLEditing;
43 function editPropertiesXML(nodeTemplateId) {
44 // code mirror does not update content if field not fully shown
45 // therefore, we hook in into the "shown" event
46 $("#PropertyXMLDiag").off("shown.bs.modal");
47 $("#PropertyXMLDiag").on("shown.bs.modal", function() {
48 nodeTemplateIdsTextAreaPropertiesXMLEditing = $("#" + nodeTemplateId).children(".propertiesContainer").children(".content").children("textarea");
49 var val = nodeTemplateIdsTextAreaPropertiesXMLEditing.val();
50 window.winery.orionareas["PropertyXML"].editor.setText(val);
51 window.winery.orionareas["PropertyXML"].fixEditorHeight();
53 $("#PropertyXMLDiag").modal("show");
54 nodeTemplateIdSelectedForPropertiesXMLEditing = nodeTemplateId;
57 function savePropertiesXMLChanges() {
58 var val = window.winery.orionareas["PropertyXML"].editor.getText();
59 nodeTemplateIdsTextAreaPropertiesXMLEditing.text(val);
60 $("#PropertyXMLDiag").modal("hide");
64 * @param properties - the properties div
65 * @param w - an XMLWriter
67 function savePropertiesFromDivToXMLWriter(properties, w, writeNamespaceDeclaration) {
68 if (properties.length != 0) {
70 var contentDiv = properties.children("div.content");
71 var xmlProperties = contentDiv.children("textarea.properties_xml");
72 if (xmlProperties.length == 0) {
73 // K/V properties -> winery special: XSD defined at node type
75 var elementName = contentDiv.children("span.elementName").text();
76 var namespace = contentDiv.children("span.namespace").text();
78 w.writeStartElement("Properties");
79 if (writeNamespaceDeclaration){
80 w.writeAttributeString("xmlns", "<%=Namespaces.TOSCA_NAMESPACE%>");
82 w.writeStartElement(elementName);
83 w.writeAttributeString("xmlns", namespace);
84 properties.children("div.content").children("table").children("tbody").children("tr").each(function() {
85 var keyEl = $(this).children("td:first-child");
86 var key = keyEl.text();
87 var valueEl = keyEl.next().children("a");
89 if (valueEl.hasClass("editable-empty")) {
92 value = valueEl.text();
93 value = value.replace(/\]\]>/g, "]]]]><![CDATA[>");
94 value = "<![CDATA[" + value + "]]>";
96 w.writeStartElement(key);
101 // close "Properties"
104 // just put the content of the XML field as child of the current node template
105 // The sourrinding tag "properties" is included in the XML field
106 var data = xmlProperties.text();