server/src/main/webapp/static/js/full-json.js
changeset 58 87569ad0ff53
parent 57 01f66ed90e32
child 59 69924ca1b233
equal deleted inserted replaced
57:01f66ed90e32 58:87569ad0ff53
     1 /* Saves the Full JSON at each modification */
       
     2 
       
     3 
       
     4 Rkns.jsonIO = function(_renkan, _opts) {
       
     5     var _proj = _renkan.project;
       
     6     if (typeof _opts.http_method == "undefined") {
       
     7         _opts.http_method = 'PUT';
       
     8     }
       
     9     var _load = function() {
       
    10         Rkns.$.getJSON(_opts.url, function(_data) {
       
    11             _proj.set(_data);
       
    12             _renkan.renderer.autoScale();
       
    13         });
       
    14     }
       
    15     var _save = function() {
       
    16         var _data = _proj.toJSON();
       
    17         Rkns.$.ajax({
       
    18             type: _opts.http_method,
       
    19             url: _opts.url,
       
    20             contentType: "application/json",
       
    21             data: JSON.stringify(_data),
       
    22             success: function(data, textStatus, jqXHR) {
       
    23             }
       
    24         });
       
    25         
       
    26     }
       
    27     var _thrSave = Rkns._.throttle(
       
    28         function() {
       
    29             setTimeout(_save, 100)
       
    30         }, 1000);
       
    31     _load();
       
    32     _proj.on("add:nodes add:edges add:users", function(_model) {
       
    33         _model.on("change remove", function(_model) {
       
    34             _thrSave();
       
    35         });
       
    36         _thrSave();
       
    37     });
       
    38 }