| author | rougeronj |
| Thu, 05 Feb 2015 13:19:42 +0100 | |
| changeset 383 | ba1f278841a2 |
| parent 370 | 8dff53b60f4e |
| child 414 | 276042cb477c |
| 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() { |
| 307 | 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 | 11 |
Rkns.$.getJSON(_opts.url, function(_data) { |
| 105 | 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 | 15 |
_renkan.renderer.redrawActive = true; |
| 116 | 16 |
_renkan.renderer.autoScale(); |
| 4 | 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 | 23 |
Rkns.$.ajax({ |
24 |
type: _opts.http_method, |
|
25 |
url: _opts.url, |
|
26 |
contentType: "application/json", |
|
27 |
data: JSON.stringify(_data), |
|
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 | 30 |
} |
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 | 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 | 41 |
_thrSave(); |
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 |
}; |