Add Edge - Alpha

Versió Alpha d'afegir arestes. No toca DB però fa com si l'hagués afegit al graf local.
diff --git a/js/script.js b/js/script.js
index 5d7a5e4..6fcf868 100644
--- a/js/script.js
+++ b/js/script.js
@@ -63,6 +63,7 @@
 
     s.graph.nodes().forEach(function(n) {
       n.color = n.originalColor;
+	  n.label = n.originalLabel;
     });
 
     s.graph.edges().forEach(function(e) {
@@ -78,6 +79,13 @@
   min: function() {
     document.querySelector("#dialog").style.display = "none";
     document.querySelector("#summary-dialog").style.display = "block";
+  },
+  addEdge: function() {
+	document.querySelector("#addedge-input").style.display = "block";  
+	document.querySelector("#edge-list").style.display = "none";
+	autocomplete(document.getElementById("addedge-input"), graf.nodes, "addEdge");
+	// Focus on the addEdge input bar
+	document.getElementById("addedge-input").focus();
   }
 };
 
@@ -122,6 +130,7 @@
         s.graph.addNode({
           id: graf.nodes[i].id,
           label: graf.nodes[i].name,
+		  originalLabel: graf.nodes[i].name,
           x: graf.nodes[i].x,
           y: graf.nodes[i].y,
           size: 10,
@@ -143,32 +152,14 @@
         var nodeId = e.data.node.id,
             toKeep = s.graph.neighbors(nodeId);
         //toKeep[nodeId] = e.data.node;
-
-        s.graph.nodes().forEach(function(n) {
-          if (toKeep[n.id] || n.id == nodeId) {
-            n.color = n.originalColor;
-          } else {
-            n.color = '#333';
-          }
-        });
-
-        s.graph.edges().forEach(function(e) {
-          if ((e.source == nodeId || e.target == nodeId) && (toKeep[e.source] || toKeep[e.target])) {
-            e.color = '#fff';
-          } else {
-            e.color = '#333';
-          }
-        });
-
-        s.refresh();
-
-        dialog.show(nodeId, toKeep);
+		clickNode(s, nodeId, toKeep);
       });
 
       document.querySelector("#quit-dialog").addEventListener("click", dialog.close);
       document.querySelector("#quit2-dialog").addEventListener("click", dialog.close);
       document.querySelector("#max-dialog").addEventListener("click", dialog.max);
       document.querySelector("#min-dialog").addEventListener("click", dialog.min);
+	  document.querySelector("#addedge-button").addEventListener("click", dialog.addEdge);
 
       document.querySelector("#zoomin").addEventListener("click", function() {
         s.camera.goTo({
@@ -194,4 +185,29 @@
 	);
 }
 
+function clickNode(s, nodeId, toKeep) {
+	s.graph.nodes().forEach(function(n) {
+          if (toKeep[n.id] || n.id == nodeId) {
+            n.color = n.originalColor;
+			n.label = n.originalLabel;
+			console.log("Hola");
+          } else {
+            n.color = '#333';
+			n.label = '';
+          }
+        });
+
+        s.graph.edges().forEach(function(e) {
+          if ((e.source == nodeId || e.target == nodeId) && (toKeep[e.source] || toKeep[e.target])) {
+            e.color = '#fff';
+          } else {
+            e.color = '#333';
+          }
+        });
+
+        s.refresh();
+
+        dialog.show(nodeId, toKeep);
+}
+
 window.addEventListener("load", init);