19 Rkns.$.ajax({ |
19 Rkns.$.ajax({ |
20 url: _opts.url, |
20 url: _opts.url, |
21 data: getdata, |
21 data: getdata, |
22 success: function(_data) { |
22 success: function(_data) { |
23 _proj.set(_data, {validate: true}); |
23 _proj.set(_data, {validate: true}); |
|
24 _proj.set({save_status:0}); |
24 _renkan.renderer.autoScale(); |
25 _renkan.renderer.autoScale(); |
25 } |
26 } |
26 }); |
27 }); |
27 }; |
28 }; |
28 var _save = function() { |
29 var _save = function() { |
31 Rkns.$.ajax({ |
32 Rkns.$.ajax({ |
32 type: _opts.http_method, |
33 type: _opts.http_method, |
33 url: _opts.url, |
34 url: _opts.url, |
34 contentType: "application/json", |
35 contentType: "application/json", |
35 data: JSON.stringify(_data), |
36 data: JSON.stringify(_data), |
|
37 beforeSend: function(){ |
|
38 _proj.set({save_status:2}); |
|
39 }, |
36 success: function(data, textStatus, jqXHR) { |
40 success: function(data, textStatus, jqXHR) { |
37 $(window).off("beforeunload", _onLeave); |
41 $(window).off("beforeunload", _onLeave); |
38 _saveWarn = false; |
42 _saveWarn = false; |
|
43 _proj.set({save_status:0}); |
39 //document.location.hash = "#id=" + data.id; |
44 //document.location.hash = "#id=" + data.id; |
40 //$(".Rk-Notifications").text("Saved as "+document.location.href).fadeIn().delay(2000).fadeOut(); |
45 //$(".Rk-Notifications").text("Saved as "+document.location.href).fadeIn().delay(2000).fadeOut(); |
41 } |
46 } |
42 }); |
47 }); |
43 }; |
48 }; |
44 var _checkLeave = function() { |
49 var _checkLeave = function() { |
|
50 _proj.set({save_status:1}); |
|
51 |
45 var title = _proj.get("title"); |
52 var title = _proj.get("title"); |
46 if (title && _proj.get("nodes").length) { |
53 if (title && _proj.get("nodes").length) { |
47 $(".Rk-Save-Button").removeClass("disabled"); |
54 $(".Rk-Save-Button").removeClass("disabled"); |
48 } else { |
55 } else { |
49 $(".Rk-Save-Button").addClass("disabled"); |
56 $(".Rk-Save-Button").addClass("disabled"); |
56 $(window).on("beforeunload", _onLeave); |
63 $(window).on("beforeunload", _onLeave); |
57 } |
64 } |
58 }; |
65 }; |
59 _load(); |
66 _load(); |
60 _proj.on("add:nodes add:edges add:users change", function(_model) { |
67 _proj.on("add:nodes add:edges add:users change", function(_model) { |
61 _model.on("change remove", function(_model) { |
68 _model.on("change remove", function(_model) { |
62 _checkLeave(); |
69 if(!(_model.changedAttributes.length == 1 && _model.hasChanged('save_status'))) { |
63 }); |
70 _checkLeave(); |
64 _checkLeave(); |
71 } |
|
72 }); |
|
73 if(!(_proj.changedAttributes.length == 1 && _proj.hasChanged('save_status'))) { |
|
74 _checkLeave(); |
|
75 } |
65 }); |
76 }); |
66 _renkan.renderer.save = function() { |
77 _renkan.renderer.save = function() { |
67 if ($(".Rk-Save-Button").hasClass("disabled")) { |
78 if ($(".Rk-Save-Button").hasClass("disabled")) { |
68 if (!_proj.get("title")) { |
79 if (!_proj.get("title")) { |
69 $(".Rk-PadTitle").css("border-color","#ff0000"); |
80 $(".Rk-PadTitle").css("border-color","#ff0000"); |