| author | rougeronj |
| Tue, 16 Jun 2015 11:36:09 +0200 | |
| changeset 482 | a55c33989404 |
| parent 444 | 19f0b7803aed |
| child 516 | 7d1d44b53af5 |
| 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; |
|
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 | 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 | 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 | 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 | 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 | 40 |
} |
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 | 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 | 50 |
_thrSave(); |
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 |
}; |