client/js/full-json.js
author rougeronj
Tue, 22 Sep 2015 15:14:10 +0200
changeset 543 5f7bebdcfc0d
parent 516 7d1d44b53af5
permissions -rw-r--r--
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view. We don't use redraw_active in save-once and full-json, because it was making the view initialization dependent of these file which are externals. Small fix to hide the "set saved view" button when there is only one view.
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() {
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
     9
        _proj.set({
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    10
            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
    11
        });
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    12
        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
    13
            _renkan.dataloader.load(_data);
543
5f7bebdcfc0d Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents: 516
diff changeset
    14
            
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
            });
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 2
diff changeset
    21
        });
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 160
diff changeset
    22
    };
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    23
    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
    24
        _proj.set({
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    25
            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
    26
        });
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    27
        var _data = _proj.toJSON();
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    28
        if (!_renkan.read_only) {
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    29
            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
    30
                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
    31
                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
    32
                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
    33
                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
    34
                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
    35
                    _proj.set({
443
4c7ab16e5845 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents: 414
diff changeset
    36
                        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
    37
                    });
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    38
                }
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 116
diff changeset
    39
            });
62
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    40
        }
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    41
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 160
diff changeset
    42
    };
414
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    43
    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
    44
        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
    45
    }, 1000);
516
7d1d44b53af5 small fixes to be sure the project and the view are loaded before using it
rougeronj
parents: 444
diff changeset
    46
    
7d1d44b53af5 small fixes to be sure the project and the view are loaded before using it
rougeronj
parents: 444
diff changeset
    47
    //TODO: Rearrange to avoid the 2 firts PUT due to a change in the project model
7d1d44b53af5 small fixes to be sure the project and the view are loaded before using it
rougeronj
parents: 444
diff changeset
    48
    // Take car of setting up the listener correctly to listen the save action on the view
282
12ee99b182cd enhance view management.
cavaliet
parents: 170
diff changeset
    49
    _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
    50
        _model.on("change remove", function(_model) {
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    51
            _thrSave();
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 20
diff changeset
    52
        });
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    53
        _thrSave();
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    54
    });
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    55
    _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
    56
        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
    57
                .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
    58
            _thrSave();
276042cb477c correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents: 370
diff changeset
    59
        }
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 105
diff changeset
    60
    });
293
fba23fde14ba Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
    61
62
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 36
diff changeset
    62
    _load();
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 160
diff changeset
    63
};