client/js/full-json.js
author rougeronj
Fri, 09 Jan 2015 16:54:21 +0100
changeset 370 8dff53b60f4e
parent 307 eaadfa988db4
child 414 276042cb477c
permissions -rw-r--r--
update full-json save to add the new save_status and loading_status attribute
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;
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
     5
    if (typeof _opts.http_method === "undefined") {
20
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() {
307
eaadfa988db4 try to improve renderer
ymh <ymh.work@gmail.com>
parents: 293
diff changeset
     9
        _renkan.renderer.redrawActive = false;
370
8dff53b60f4e update full-json save to add the new save_status and loading_status attribute
rougeronj
parents: 307
diff changeset
    10
        _proj.set({loading_status:true});
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    11
        Rkns.$.getJSON(_opts.url, function(_data) {
105
810a1c1015df fixed the position propagation bug
veltr
parents: 67
diff changeset
    12
            _proj.set(_data, {validate: true});
370
8dff53b60f4e update full-json save to add the new save_status and loading_status attribute
rougeronj
parents: 307
diff changeset
    13
            _proj.set({loading_status:false});
8dff53b60f4e update full-json save to add the new save_status and loading_status attribute
rougeronj
parents: 307
diff changeset
    14
            _proj.set({save_status:0});
307
eaadfa988db4 try to improve renderer
ymh <ymh.work@gmail.com>
parents: 293
diff changeset
    15
            _renkan.renderer.redrawActive = true;
116
07f9fc847d5d Autoscale is back
veltr
parents: 114
diff changeset
    16
            _renkan.renderer.autoScale();
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 2
diff changeset
    17
        });
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 160
diff changeset
    18
    };
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    19
    var _save = function() {
370
8dff53b60f4e update full-json save to add the new save_status and loading_status attribute
rougeronj
parents: 307
diff changeset
    20
    	_proj.set({save_status:2});
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    21
        var _data = _proj.toJSON();
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    22
        if (!_renkan.read_only) {
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    23
            Rkns.$.ajax({
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    24
                type: _opts.http_method,
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    25
                url: _opts.url,
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    26
                contentType: "application/json",
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    27
                data: JSON.stringify(_data),
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    28
                success: function(data, textStatus, jqXHR) {
370
8dff53b60f4e update full-json save to add the new save_status and loading_status attribute
rougeronj
parents: 307
diff changeset
    29
                	_proj.set({save_status:0});
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    30
                }
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    31
            });
62
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    32
        }
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    33
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 160
diff changeset
    34
    };
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    35
    var _thrSave = Rkns._.throttle(
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    36
        function() {
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 160
diff changeset
    37
            setTimeout(_save, 100);
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    38
        }, 1000);
282
12ee99b182cd enhance view management.
cavaliet
parents: 170
diff changeset
    39
    _proj.on("add:nodes add:edges add:users add:views", function(_model) {
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    40
        _model.on("change remove", function(_model) {
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    41
            _thrSave();
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    42
        });
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    43
        _thrSave();
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    44
    });
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    45
    _proj.on("change", function() {
370
8dff53b60f4e update full-json save to add the new save_status and loading_status attribute
rougeronj
parents: 307
diff changeset
    46
    	if(!(_proj.changedAttributes.length === 1 && _proj.hasChanged('save_status'))) {
8dff53b60f4e update full-json save to add the new save_status and loading_status attribute
rougeronj
parents: 307
diff changeset
    47
    		_thrSave();
8dff53b60f4e update full-json save to add the new save_status and loading_status attribute
rougeronj
parents: 307
diff changeset
    48
    	}
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    49
    });
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    50
62
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    51
    _load();
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 160
diff changeset
    52
};