Add winery source code
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / webapp / js / boundaryDefinitionsXSelection.js
1 /*******************************************************************************
2  * Copyright (c) 2014 University of Stuttgart.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *    Oliver Kopp - initial API and implementation
11  *    Tobias Binz - communication with the parent window
12  *******************************************************************************/
13
14  /**
15   * Called from the renderer as soon as the whole topology is loaded
16   */
17  function wineryViewExternalScriptOnLoad() {
18
19         function getIdOfNodeTemplateShape(element) {
20                 var nodeTemplate = element.closest("div.NodeTemplateShape");
21                 var id = nodeTemplate.children("div.headerContainer").children("div.id").text();
22                 return id;
23         }
24
25         jsPlumb.bind("ready", function() {
26                 jsPlumb.bind("click", function(conn, originalEvent) {
27                         var id = winery.connections[conn.id].id;
28                         var message = {
29                                 targetRelationshipTemplateRef: id
30                         }
31                         sendMessage(message);
32                 });
33         });
34
35
36         $("div.NodeTemplateShape").on("click", function(e) {
37                 var id = getIdOfNodeTemplateShape($(e.target));
38                 // send id and empty property as no property has been clicked
39                 var message = {
40                         targetObjectRef: id,
41                         targetPropertyRef: ""
42                 };
43                 sendMessage(message);
44
45                 return false;
46         });
47
48         $("tr.KVProperty").on("click", function(e) {
49                 var trKVProperty = $(e.target).closest("tr.KVProperty");
50                 var key = trKVProperty.children("td").children("span.KVPropertyKey").text();
51
52                 var content = trKVProperty.closest("div.content");
53                 var elementName = content.children("span.elementName").text();
54
55                 // form namespace-unaware XPath
56                 var xpath = "/*[local-name()='" + elementName + "']/*[local-name()='" + key + "']";
57
58                 var message = {
59                         targetPropertyRef: xpath,
60                         targetObjectRef: getIdOfNodeTemplateShape(trKVProperty)
61                 };
62                 sendMessage(message);
63
64                 // do not trigger click on NodeTemplateShape -> we included both values in the message
65                 return false;
66         });
67
68         $("div.requirements").on("click", function(e) {
69                 var reqorcap = $(e.target).closest("div.requirements");
70                 var id = reqorcap.children("div.id").text();
71
72                 var message = {
73                         reqRef: id
74                 };
75                 sendMessage(message);
76
77                 return false;
78         });
79
80         $("div.capabilities").on("click", function(e) {
81                 var reqorcap = $(e.target).closest("div.capabilities");
82                 var id = reqorcap.children("div.id").text();
83
84                 var message = {
85                         capRef: id
86                 };
87                 sendMessage(message);
88
89                 return false;
90         });
91
92  }
93
94 function sendMessage(message) {
95         window.parent.postMessage(message, "*");
96 }