|
20
|
1 |
/* Saves the Full JSON at each modification */ |
|
|
2 |
|
|
23
|
3 |
Rkns.jsonIO = function(_renkan, _opts) { |
|
|
4 |
var _proj = _renkan.project; |
|
20
|
5 |
if (typeof _opts.http_method == "undefined") { |
|
|
6 |
_opts.http_method = 'PUT'; |
|
|
7 |
} |
|
23
|
8 |
var _load = function() { |
|
|
9 |
Rkns.$.getJSON(_opts.url, function(_data) { |
|
24
|
10 |
_proj.set(_data); |
|
25
|
11 |
_renkan.renderer.autoScale(); |
|
4
|
12 |
}); |
|
1
|
13 |
} |
|
23
|
14 |
var _save = function() { |
|
24
|
15 |
var _data = _proj.toJSON(); |
|
23
|
16 |
Rkns.$.ajax({ |
|
|
17 |
type: _opts.http_method, |
|
|
18 |
url: _opts.url, |
|
|
19 |
contentType: "application/json", |
|
|
20 |
data: JSON.stringify(_data), |
|
|
21 |
success: function(data, textStatus, jqXHR) { |
|
4
|
22 |
} |
|
23
|
23 |
}); |
|
|
24 |
|
|
4
|
25 |
} |
|
23
|
26 |
var _thrSave = Rkns._.throttle(_save, 2000); |
|
|
27 |
_load(); |
|
|
28 |
_proj.on("add:nodes add:edges add:users", function(_model) { |
|
|
29 |
_model.on("change remove", function(_model) { |
|
|
30 |
_thrSave(); |
|
|
31 |
}); |
|
|
32 |
}); |
|
4
|
33 |
} |