| author | ymh <ymh.work@gmail.com> |
| Thu, 21 Apr 2016 16:17:50 +0200 | |
| changeset 606 | e7e699f3cf97 |
| parent 543 | 5f7bebdcfc0d |
| permissions | -rw-r--r-- |
| 20 | 1 |
/* Saves the Full JSON at each modification */ |
2 |
||
| 23 | 3 |
Rkns.jsonIO = function(_renkan, _opts) { |
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 | 6 |
_opts.http_method = 'PUT'; |
7 |
} |
|
| 23 | 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 | 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 | 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 | 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 | 38 |
} |
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 | 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 | 51 |
_thrSave(); |
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 |
}; |