client/js/full-json.js
author veltr
Tue, 26 Feb 2013 17:04:24 +0100
changeset 66 9b459e41e2df
parent 62 f9019462465a
child 67 d341117f9370
permissions -rw-r--r--
Added drag-and-drop and image from local drive
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
bd58970ffd16 Refactoring to better fit the MVVM pattern
veltr
parents: 14
diff changeset
     1
/* Saves the Full JSON at each modification */
bd58970ffd16 Refactoring to better fit the MVVM pattern
veltr
parents: 14
diff changeset
     2
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
     3
Rkns.jsonIO = function(_renkan, _opts) {
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
     4
    var _proj = _renkan.project;
20
bd58970ffd16 Refactoring to better fit the MVVM pattern
veltr
parents: 14
diff changeset
     5
    if (typeof _opts.http_method == "undefined") {
bd58970ffd16 Refactoring to better fit the MVVM pattern
veltr
parents: 14
diff changeset
     6
        _opts.http_method = 'PUT';
bd58970ffd16 Refactoring to better fit the MVVM pattern
veltr
parents: 14
diff changeset
     7
    }
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
     8
    var _load = function() {
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
     9
        Rkns.$.getJSON(_opts.url, function(_data) {
24
121a24be9da4 Added Wikipedia Search
veltr
parents: 23
diff changeset
    10
            _proj.set(_data);
25
b5ada3bb8e53 Bugfixes
veltr
parents: 24
diff changeset
    11
            _renkan.renderer.autoScale();
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 2
diff changeset
    12
        });
1
45cca39b00ac First rendering tests
veltr
parents:
diff changeset
    13
    }
62
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    14
    if (!_renkan.read_only) {
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    15
        var _save = function() {
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    16
            var _data = _proj.toJSON();
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    17
            Rkns.$.ajax({
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    18
                type: _opts.http_method,
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    19
                url: _opts.url,
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    20
                contentType: "application/json",
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    21
                data: JSON.stringify(_data),
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    22
                success: function(data, textStatus, jqXHR) {
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    23
                }
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    24
            });
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    25
            
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    26
        }
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    27
        var _thrSave = Rkns._.throttle(
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    28
            function() {
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    29
                setTimeout(_save, 100)
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    30
            }, 1000);
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    31
        _proj.on("add:nodes add:edges add:users", function(_model) {
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    32
            _model.on("change remove", function(_model) {
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    33
                _thrSave();
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    34
            });
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    35
            _thrSave();
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    36
        });
62
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    37
        _proj.on("change", function() {
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    38
            _thrSave();
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    39
        });
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    40
    }
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    41
    _load();
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 2
diff changeset
    42
}