From 49c6e53c2b677abfa8aa2adabd77f92605ee3744 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Sun, 17 Aug 2014 18:31:30 +0300 Subject: 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). --- scripts/buttons.js | 54 ++++++++++++---------------------------------------- scripts/rhizicore.js | 49 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 44 deletions(-) (limited to 'scripts') 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