diff options
author | 2016-08-31 16:47:33 +0800 | |
---|---|---|
committer | 2016-08-31 16:47:33 +0800 | |
commit | fa49e78cc199526a9e33b59c5194f8e3bf0f0952 (patch) | |
tree | 3478e867a8f304266dbceca6e992cceca410ede4 /winery/org.eclipse.winery.topologymodeler/src/main/webapp/WEB-INF/tags/common/templates/propertiesBasic.tag | |
parent | 159d40f0011559c8f82338b29dca1bffd700f2c8 (diff) |
Add winery source code
Change-Id: I1c5088121d79b71098c3cba1996c6f784737532e
Issue-id: TOSCA-49
Signed-off-by: huangjian <huang.jian12@zte.com.cn>
Diffstat (limited to 'winery/org.eclipse.winery.topologymodeler/src/main/webapp/WEB-INF/tags/common/templates/propertiesBasic.tag')
-rw-r--r-- | winery/org.eclipse.winery.topologymodeler/src/main/webapp/WEB-INF/tags/common/templates/propertiesBasic.tag | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/winery/org.eclipse.winery.topologymodeler/src/main/webapp/WEB-INF/tags/common/templates/propertiesBasic.tag b/winery/org.eclipse.winery.topologymodeler/src/main/webapp/WEB-INF/tags/common/templates/propertiesBasic.tag new file mode 100644 index 0000000..5e850b1 --- /dev/null +++ b/winery/org.eclipse.winery.topologymodeler/src/main/webapp/WEB-INF/tags/common/templates/propertiesBasic.tag @@ -0,0 +1,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> |