first commit
[osm/LW-UI.git] / static / src / projecthandler / osm / controller.js
1 if (typeof dreamer === 'undefined') {
2 var dreamer = {};
3 }
4 var level = {}
5
6 dreamer.OsmController = (function(global) {
7 'use strict';
8
9 var DEBUG = true;
10
11 OsmController.prototype.constructor = OsmController;
12
13 /**
14 * Constructor
15 */
16 function OsmController() {
17
18
19 }
20
21
22 OsmController.prototype.addNode = function(graph_editor, node, success, error) {
23 log('addNode');
24 var data_to_send = {
25 'group_id': node.info.group[0],
26 'element_id': node.id,
27 'element_type': node.info.type,
28 'element_desc_id': node.info.desc_id,
29 'x': node.x,
30 'y': node.y
31 };
32 new dreamer.GraphRequests().addNode(data_to_send, null, function() {
33 if (success)
34 success();
35 },error);
36 };
37
38 OsmController.prototype.addLink = function(graph_editor, link, success, error) {
39 log('addLink');
40 var data_to_send = {
41 'desc_id': link.desc_id,
42 'source': link.source.id,
43 'source_type': link.source.info.type,
44 'target': link.target.id,
45 'target_type': link.target.info.type,
46 'view': link.view,
47 'group': link.group
48 };
49 new dreamer.GraphRequests().addLink(link, null, function() {
50 graph_editor._deselectAllNodes();
51
52 if (typeof old_link !== 'undefined' && old_link.length > 0 && old_link[0].index !== 'undefined') {
53 graph_editor.parent.removeLink.call(graph_editor, old_link[0].index);
54 }
55 if (success) {
56 success();
57 }
58 },error);
59 };
60
61 OsmController.prototype.removeNode = function(graph_editor, node, success, error) {
62 log('removeNode');
63 var data_to_send = {
64 'group_id': node.info.group[0],
65 'element_id': node.id,
66 'element_type': node.info.type,
67 'element_desc_id': node.info.desc_id,
68 };
69 new dreamer.GraphRequests().removeNode(data_to_send, null, function() {
70 if (success) {
71 success();
72 }
73 },error);
74 };
75
76 OsmController.prototype.removeLink = function(graph_editor, link, success, error) {
77 log('removeLink');
78 var data_to_send = {
79 'desc_id': link.desc_id,
80 'source': link.source.id,
81 'source_type': link.source.info.type,
82 'target': link.target.id,
83 'target_type': link.target.info.type,
84 'view': link.view,
85 'group': link.group
86 };
87 new dreamer.GraphRequests().removeLink(data_to_send, function() {
88 if (success) {
89 success();
90 }
91 },error);
92 };
93
94 /**
95 * Log utility
96 */
97 function log(text) {
98 if (DEBUG)
99 console.log("::OsmController::", text);
100 }
101
102 return OsmController;
103 }(this));
104
105 if (typeof module === 'object') {
106 module.exports = dreamer.OsmController;
107 }