diff -r 7e132e2a48ca -r 267d67791e05 server/src/main/webapp/static/js/full-json.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/main/webapp/static/js/full-json.js Tue Dec 25 21:29:11 2012 +0100 @@ -0,0 +1,38 @@ +/* Saves the Full JSON at each modification */ + + +Rkns.jsonIO = function(_renkan, _opts) { + var _proj = _renkan.project; + if (typeof _opts.http_method == "undefined") { + _opts.http_method = 'PUT'; + } + var _load = function() { + Rkns.$.getJSON(_opts.url, function(_data) { + _proj.set(_data); + _renkan.renderer.autoScale(); + }); + } + var _save = function() { + var _data = _proj.toJSON(); + Rkns.$.ajax({ + type: _opts.http_method, + url: _opts.url, + contentType: "application/json", + data: JSON.stringify(_data), + success: function(data, textStatus, jqXHR) { + } + }); + + } + var _thrSave = Rkns._.throttle( + function() { + setTimeout(_save, 100) + }, 1000); + _load(); + _proj.on("add:nodes add:edges add:users", function(_model) { + _model.on("change remove", function(_model) { + _thrSave(); + }); + _thrSave(); + }); +}