5 if (typeof _opts.http_method === "undefined") { |
5 if (typeof _opts.http_method === "undefined") { |
6 _opts.http_method = 'PUT'; |
6 _opts.http_method = 'PUT'; |
7 } |
7 } |
8 var _load = function() { |
8 var _load = function() { |
9 _renkan.renderer.redrawActive = false; |
9 _renkan.renderer.redrawActive = false; |
10 _proj.set({loading_status:true}); |
10 _proj.set({ |
|
11 loading_status : true |
|
12 }); |
11 Rkns.$.getJSON(_opts.url, function(_data) { |
13 Rkns.$.getJSON(_opts.url, function(_data) { |
12 _proj.set(_data, {validate: true}); |
14 _proj.set(_data, { |
13 _proj.set({loading_status:false}); |
15 validate : true |
14 _proj.set({save_status:0}); |
16 }); |
|
17 _proj.set({ |
|
18 loading_status : false |
|
19 }); |
|
20 _proj.set({ |
|
21 save_status : 0 |
|
22 }); |
15 _renkan.renderer.redrawActive = true; |
23 _renkan.renderer.redrawActive = true; |
16 _renkan.renderer.autoScale(); |
24 _renkan.renderer.fixSize(); |
17 }); |
25 }); |
18 }; |
26 }; |
19 var _save = function() { |
27 var _save = function() { |
20 _proj.set({save_status:2}); |
28 _proj.set({ |
|
29 save_status : 2 |
|
30 }); |
21 var _data = _proj.toJSON(); |
31 var _data = _proj.toJSON(); |
22 if (!_renkan.read_only) { |
32 if (!_renkan.read_only) { |
23 Rkns.$.ajax({ |
33 Rkns.$.ajax({ |
24 type: _opts.http_method, |
34 type : _opts.http_method, |
25 url: _opts.url, |
35 url : _opts.url, |
26 contentType: "application/json", |
36 contentType : "application/json", |
27 data: JSON.stringify(_data), |
37 data : JSON.stringify(_data), |
28 success: function(data, textStatus, jqXHR) { |
38 success : function(data, textStatus, jqXHR) { |
29 _proj.set({save_status:0}); |
39 _proj.set({ |
|
40 save_status : 0 |
|
41 }); |
30 } |
42 } |
31 }); |
43 }); |
32 } |
44 } |
33 |
45 |
34 }; |
46 }; |
35 var _thrSave = Rkns._.throttle( |
47 var _thrSave = Rkns._.throttle(function() { |
36 function() { |
48 setTimeout(_save, 100); |
37 setTimeout(_save, 100); |
49 }, 1000); |
38 }, 1000); |
|
39 _proj.on("add:nodes add:edges add:users add:views", function(_model) { |
50 _proj.on("add:nodes add:edges add:users add:views", function(_model) { |
40 _model.on("change remove", function(_model) { |
51 _model.on("change remove", function(_model) { |
41 _thrSave(); |
52 _thrSave(); |
42 }); |
53 }); |
43 _thrSave(); |
54 _thrSave(); |
44 }); |
55 }); |
45 _proj.on("change", function() { |
56 _proj.on("change", function() { |
46 if(!(_proj.changedAttributes.length === 1 && _proj.hasChanged('save_status'))) { |
57 if (!(_proj.changedAttributes.length === 1 && _proj |
47 _thrSave(); |
58 .hasChanged('save_status'))) { |
48 } |
59 _thrSave(); |
|
60 } |
49 }); |
61 }); |
50 |
62 |
51 _load(); |
63 _load(); |
52 }; |
64 }; |