blob: 5e850b1ff35bfe0e01e84893fac3019a196a82a5 (
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
|
<%--
/*******************************************************************************
* 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
*******************************************************************************/
--%>
<%@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"%>
<%@tag import="org.eclipse.winery.common.constants.Namespaces" %>
<%@taglib prefix="o" tagdir="/WEB-INF/tags/common/orioneditor"%>
<div class="modal fade" id="PropertyXMLDiag">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Property</h4>
</div>
<div class="modal-body">
<!-- embed the XML editor without a save button. We provide the save button by ourselves -->
<o:orioneditorarea areaid="PropertyXML" withoutsavebutton="true"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" onclick="savePropertiesXMLChanges();">Save</button>
</div>
</div>
</div>
</div>
<script>
// global variable set by editPropertiesXML and read by savePropertiesXMLChanges
var nodeTemplateIdsTextAreaPropertiesXMLEditing;
function editPropertiesXML(nodeTemplateId) {
// code mirror does not update content if field not fully shown
// therefore, we hook in into the "shown" event
$("#PropertyXMLDiag").off("shown.bs.modal");
$("#PropertyXMLDiag").on("shown.bs.modal", function() {
nodeTemplateIdsTextAreaPropertiesXMLEditing = $("#" + nodeTemplateId).children(".propertiesContainer").children(".content").children("textarea");
var val = nodeTemplateIdsTextAreaPropertiesXMLEditing.val();
window.winery.orionareas["PropertyXML"].editor.setText(val);
window.winery.orionareas["PropertyXML"].fixEditorHeight();
});
$("#PropertyXMLDiag").modal("show");
nodeTemplateIdSelectedForPropertiesXMLEditing = nodeTemplateId;
}
function savePropertiesXMLChanges() {
var val = window.winery.orionareas["PropertyXML"].editor.getText();
nodeTemplateIdsTextAreaPropertiesXMLEditing.text(val);
$("#PropertyXMLDiag").modal("hide");
}
/**
* @param properties - the properties div
* @param w - an XMLWriter
*/
function savePropertiesFromDivToXMLWriter(properties, w, writeNamespaceDeclaration) {
if (properties.length != 0) {
// properties exist
var contentDiv = properties.children("div.content");
var xmlProperties = contentDiv.children("textarea.properties_xml");
if (xmlProperties.length == 0) {
// K/V properties -> winery special: XSD defined at node type
var elementName = contentDiv.children("span.elementName").text();
var namespace = contentDiv.children("span.namespace").text();
w.writeStartElement("Properties");
if (writeNamespaceDeclaration){
w.writeAttributeString("xmlns", "<%=Namespaces.TOSCA_NAMESPACE%>");
}
w.writeStartElement(elementName);
w.writeAttributeString("xmlns", namespace);
properties.children("div.content").children("table").children("tbody").children("tr").each(function() {
var keyEl = $(this).children("td:first-child");
var key = keyEl.text();
var valueEl = keyEl.next().children("a");
var value;
if (valueEl.hasClass("editable-empty")) {
value = "";
} else {
value = valueEl.text();
value = value.replace(/\]\]>/g, "]]]]><![CDATA[>");
value = "<![CDATA[" + value + "]]>";
}
w.writeStartElement(key);
w.writeString(value);
w.writeEndElement();
});
w.writeEndElement();
// close "Properties"
w.writeEndElement();
} else {
// just put the content of the XML field as child of the current node template
// The sourrinding tag "properties" is included in the XML field
var data = xmlProperties.text();
w.writeXML(data);
}
}
}
</script>
|