client/js/full-json.js
author ymh <ymh.work@gmail.com>
Wed, 09 Sep 2015 18:37:15 +0200
changeset 499 7d374d366b28
parent 444 19f0b7803aed
child 516 7d1d44b53af5
permissions -rw-r--r--
Correct strange bug on fill of editor box with a difference of beavior between paperjs 0.9.23 and 0.9.24. Real cause not found, but this correction visually solve the problem
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;
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    10
        _proj.set({
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    11
            loadingStatus : true
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    12
        });
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    13
        Rkns.$.getJSON(_opts.url, function(_data) {
444
19f0b7803aed add schema version + dataloaders to ensure data migrations + small correction for php server exmple + a readme for the php server example
ymh <ymh.work@gmail.com>
parents: 443
diff changeset
    14
            _renkan.dataloader.load(_data);
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    15
            _proj.set({
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    16
                loadingStatus : false
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    17
            });
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    18
            _proj.set({
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    19
                saveStatus : 0
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    20
            });
307
eaadfa988db4 try to improve renderer
ymh <ymh.work@gmail.com>
parents: 293
diff changeset
    21
            _renkan.renderer.redrawActive = true;
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    22
            _renkan.renderer.fixSize();
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 2
diff changeset
    23
        });
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 160
diff changeset
    24
    };
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    25
    var _save = function() {
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    26
        _proj.set({
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    27
            saveStatus : 2
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    28
        });
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    29
        var _data = _proj.toJSON();
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    30
        if (!_renkan.read_only) {
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    31
            Rkns.$.ajax({
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    32
                type : _opts.http_method,
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    33
                url : _opts.url,
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    34
                contentType : "application/json",
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    35
                data : JSON.stringify(_data),
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    36
                success : function(data, textStatus, jqXHR) {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    37
                    _proj.set({
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    38
                        saveStatus : 0
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    39
                    });
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    40
                }
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    41
            });
62
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    42
        }
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    43
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 160
diff changeset
    44
    };
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    45
    var _thrSave = Rkns._.throttle(function() {
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    46
        setTimeout(_save, 100);
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    47
    }, 1000);
282
12ee99b182cd enhance view management.
cavaliet
parents: 170
diff changeset
    48
    _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
    49
        _model.on("change remove", function(_model) {
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    50
            _thrSave();
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    51
        });
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    52
        _thrSave();
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    53
    });
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    54
    _proj.on("change", function() {
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    55
        if (!(_proj.changedAttributes.length === 1 && _proj
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    56
                .hasChanged('saveStatus'))) {
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    57
            _thrSave();
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    58
        }
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    59
    });
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    60
62
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    61
    _load();
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 160
diff changeset
    62
};