| author | ymh <ymh.work@gmail.com> |
| Fri, 25 Oct 2013 01:20:25 +0200 | |
| changeset 211 | d87f6bdee43d |
| parent 190 | a9040a7c47d9 |
| child 293 | fba23fde14ba |
| permissions | -rw-r--r-- |
| 52 | 1 |
/* Saves the Full JSON once */ |
2 |
||
3 |
Rkns.jsonIO = function(_renkan, _opts) { |
|
4 |
var _proj = _renkan.project, |
|
5 |
_saveWarn = false, |
|
6 |
_onLeave = function() { |
|
7 |
return "Project not saved"; |
|
8 |
}; |
|
9 |
if (typeof _opts.http_method == "undefined") { |
|
10 |
_opts.http_method = 'POST'; |
|
11 |
} |
|
12 |
var _load = function() { |
|
13 |
var getdata = {}, |
|
14 |
rx = /id=([^&#?=]+)/, |
|
15 |
matches = document.location.hash.match(rx); |
|
16 |
if (matches) { |
|
17 |
getdata.id = matches[1]; |
|
18 |
} |
|
19 |
Rkns.$.ajax({ |
|
20 |
url: _opts.url, |
|
21 |
data: getdata, |
|
22 |
success: function(_data) { |
|
| 105 | 23 |
_proj.set(_data, {validate: true}); |
| 116 | 24 |
_renkan.renderer.autoScale(); |
| 52 | 25 |
} |
26 |
}); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
116
diff
changeset
|
27 |
}; |
| 52 | 28 |
var _save = function() { |
29 |
_proj.set("saved_at", new Date()); |
|
30 |
var _data = _proj.toJSON(); |
|
31 |
Rkns.$.ajax({ |
|
32 |
type: _opts.http_method, |
|
33 |
url: _opts.url, |
|
34 |
contentType: "application/json", |
|
35 |
data: JSON.stringify(_data), |
|
36 |
success: function(data, textStatus, jqXHR) { |
|
37 |
$(window).off("beforeunload", _onLeave); |
|
38 |
_saveWarn = false; |
|
39 |
document.location.hash = "#id=" + data.id; |
|
40 |
$(".Rk-Notifications").text("Saved as "+document.location.href).fadeIn().delay(2000).fadeOut(); |
|
41 |
} |
|
42 |
}); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
116
diff
changeset
|
43 |
}; |
| 52 | 44 |
var _checkLeave = function() { |
45 |
var title = _proj.get("title"); |
|
46 |
if (title && _proj.get("nodes").length) { |
|
47 |
$(".Rk-Save-Button").removeClass("disabled"); |
|
48 |
} else { |
|
49 |
$(".Rk-Save-Button").addClass("disabled"); |
|
50 |
} |
|
51 |
if (title) { |
|
52 |
$(".Rk-PadTitle").css("border-color","#333333"); |
|
53 |
} |
|
54 |
if (!_saveWarn) { |
|
55 |
_saveWarn = true; |
|
56 |
$(window).on("beforeunload", _onLeave); |
|
57 |
} |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
116
diff
changeset
|
58 |
}; |
| 52 | 59 |
_load(); |
60 |
_proj.on("add:nodes add:edges add:users change", function(_model) { |
|
61 |
_model.on("change remove", function(_model) { |
|
62 |
_checkLeave(); |
|
63 |
}); |
|
64 |
_checkLeave(); |
|
65 |
}); |
|
| 190 | 66 |
_renkan.renderer.save = function() { |
67 |
if ($(".Rk-Save-Button").hasClass("disabled")) { |
|
| 52 | 68 |
if (!_proj.get("title")) { |
69 |
$(".Rk-PadTitle").css("border-color","#ff0000"); |
|
70 |
} |
|
71 |
} else { |
|
72 |
_save(); |
|
73 |
} |
|
| 190 | 74 |
} |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
116
diff
changeset
|
75 |
}; |