Merge "Fix build errors in autorelease full clean build"
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.topologymodeler / src / main / webapp / WEB-INF / tags / common / templates / propertiesBasic.tag
1 <%--
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
9  *
10  * Contributors:
11  *    Oliver Kopp - initial API and implementation and/or initial documentation
12  *******************************************************************************/
13 --%>
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"%>
15
16 <%@tag import="org.eclipse.winery.common.constants.Namespaces" %>
17
18 <%@taglib prefix="o"  tagdir="/WEB-INF/tags/common/orioneditor"%>
19
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">&times;</button>
25                                 <h4 class="modal-title">Property</h4>
26                         </div>
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"/>
30                         </div>
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>
34                         </div>
35                 </div>
36         </div>
37 </div>
38
39 <script>
40 // global variable set by editPropertiesXML and read by savePropertiesXMLChanges
41 var nodeTemplateIdsTextAreaPropertiesXMLEditing;
42
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();
52         });
53         $("#PropertyXMLDiag").modal("show");
54         nodeTemplateIdSelectedForPropertiesXMLEditing = nodeTemplateId;
55 }
56
57 function savePropertiesXMLChanges() {
58         var val = window.winery.orionareas["PropertyXML"].editor.getText();
59         nodeTemplateIdsTextAreaPropertiesXMLEditing.text(val);
60         $("#PropertyXMLDiag").modal("hide");
61 }
62
63 /**
64  * @param properties - the properties div
65  * @param w - an XMLWriter
66  */
67 function savePropertiesFromDivToXMLWriter(properties, w, writeNamespaceDeclaration) {
68         if (properties.length != 0) {
69                 // properties exist
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
74
75                         var elementName = contentDiv.children("span.elementName").text();
76                         var namespace = contentDiv.children("span.namespace").text();
77
78                         w.writeStartElement("Properties");
79                         if (writeNamespaceDeclaration){
80                                 w.writeAttributeString("xmlns", "<%=Namespaces.TOSCA_NAMESPACE%>");
81                         }
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");
88                                 var value;
89                                 if (valueEl.hasClass("editable-empty")) {
90                                         value = "";
91                                 } else {
92                                         value = valueEl.text();
93                                         value = value.replace(/\]\]>/g, "]]]]><![CDATA[>");
94                                         value = "<![CDATA[" + value + "]]>";
95                                 }
96                                 w.writeStartElement(key);
97                                 w.writeString(value);
98                                 w.writeEndElement();
99                         });
100                         w.writeEndElement();
101                         // close "Properties"
102                         w.writeEndElement();
103                 } else {
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();
107                         w.writeXML(data);
108                 }
109         }
110
111 }
112 </script>