-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.js
40 lines (36 loc) · 831 Bytes
/
file.js
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
//code for importing and exporting the data
theData = null;
function loadData(file)
{
var r = new FileReader();
r.onload = (function(f) {
return function(e) {
parseFile(e.target.result);
}
})(file[0]);
r.readAsText(file[0]);//asynchron reading
}
function saveData()
{
if(theData == null)
{
alert("No Data loaded");
return;
}
var d = new Date();
var filename = "noten_" + d.toISOString() + ".myjson";
var data = JSON.stringify(theData, undefined, 2);
var s = d3.select("body").append("a").html("download").attr("href", 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(data)).attr("download", filename).attr("id", "downloadlink");
s[0][0].click();
s.remove();
}
function parseFile(s)
{
theData = JSON.parse(s);
drawMainMenu();
}
function newJson()
{
theData = {};
drawMainMenu();
}