summaryrefslogtreecommitdiff
path: root/scripts/buttons.js
blob: 6dbec35ab8797da1850d3715b37123fa7f7fe344 (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

$('.tutorial').click(function(){});

var key="#47989379";


$('.save').click(function(){

  var jsonsave='{"nodes":[';
  console.log(nodes);
  for(var i=0;i<nodes.length;i++){
    var node=nodes[i];
    jsonsave+='{"id":"'+node.id+'","type":"'+node.type+'","state":"'+"perm"+'","start":"'+node.start+'","end":"'+node.end+'","status":"'+node.status+'"}';
    if(i!==nodes.length-1)jsonsave+=',';
  }
  jsonsave+='],"links":[';

  for(var j=0;j<links.length;j++){
    var link=links[j];
    jsonsave+='{"source":"'+link.source.id+'","target":"'+link.target.id+'","name":"'+link.name+'"}';
    if(j!==links.length-1)jsonsave+=",";
  }
  jsonsave+=']}';
  console.log(JSON.stringify(jsonsave));
  localStorage.setItem(key, JSON.stringify(jsonsave));

});

$('.load').click(function(){
  var acceptLoad=true;
  if (nodes.length>0){
    acceptLoad = confirm('All unsaved changes will be deleted, are you sure?');
  }

  if(acceptLoad){
    links=[];
    nodes=[];
    var data = JSON.parse(JSON.parse(localStorage.getItem(key)));
    console.log(data);
    for(var i=0; i<data["nodes"].length; i++){
      var node=data.nodes[i];
      graph.addNodeComplete(node.id,node.type,"perm",new Date(node.start),new Date(node.end),node.status);
    }

    for(var j=0; j<data["links"].length; j++){
      var link=data.links[j];
      graph.addLink(link.source,link.target,link.name,"perm");
    }
    graph.recenterZoom();
    graph.update();
  }

});

  $('.deliverabletest').click(function(){
    deliverableTest();
  });

function fetchNode(id){
  for( x in nodes){
    if(x.id===id){
      console.log("found");
      return x;
    }
  }
  return null;
}