summaryrefslogtreecommitdiff
path: root/scripts/buttons.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-08-17 18:31:30 +0300
committerAlon Levy <alon@pobox.com>2014-08-17 18:31:31 +0300
commit49c6e53c2b677abfa8aa2adabd77f92605ee3744 (patch)
tree147004e1ab2b4140d8b3497862cfbdaa2ed9cfe7 /scripts/buttons.js
parenta4206a91a314226bbff69094069e118bbd54bb65 (diff)
drag&drop load of json, plus save (kinda), some refactoring
save & load json moved from buttons to rhizicore.js added a save as button (need to switch to normal ui for that menu, it's fixed right now) save not correct - instead of a save dialog since it is a json file the browser just displays it (even though it's base64 encoded).
Diffstat (limited to 'scripts/buttons.js')
-rw-r--r--scripts/buttons.js54
1 files changed, 12 insertions, 42 deletions
diff --git a/scripts/buttons.js b/scripts/buttons.js
index 79a961ff..dd449722 100644
--- a/scripts/buttons.js
+++ b/scripts/buttons.js
@@ -6,30 +6,15 @@ var key="#47989379";
$('.save').click(function(){
+ var json = graph.save_to_json();
+ console.log(json);
+ localStorage.setItem(key, json);
+});
- var d = {"nodes":[], "links":[]};
- console.log(nodes);
- for(var i = 0 ; i < nodes.length ; i++){
- var node = nodes[i];
- d['nodes'].push({
- "id":node.id,
- "type":node.type,
- "state":"perm",
- "start":node.start,
- "end":node.end,
- "status": node.status
- });
- }
- for(var j=0 ; j < links.length ; j++){
- var link = links[j];
- d['links'].push({
- "source":link.source.id,
- "target":link.target.id,
- "name":link.name
- });
- }
- console.log(JSON.stringify(d));
- localStorage.setItem(key, JSON.stringify(d));
+$('.saveToFile').click(function() {
+ var json = graph.save_to_json();
+ console.log(json);
+ location.href = 'data:text/json;base64,' + window.btoa(json);
});
$('.load').click(function(){
@@ -40,25 +25,10 @@ $('.load').click(function(){
}
if(acceptLoad){
- links=[];
- nodes=[];
- var data = JSON.parse(localStorage.getItem(key));
- if (data == null) {
- console.log('load callback: no data to load');
- return;
- }
- 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();
+ links=[]; // TODO - not global
+ nodes=[]; // TODO - not global
+ var json_blob = localStorage.getItem(key)
+ graph.load_from_json(json_blob);
}
});