| author | ymh <ymh.work@gmail.com> |
| Tue, 10 Jan 2017 17:36:30 +0100 | |
| changeset 649 | 2b9c120dba55 |
| parent 543 | 5f7bebdcfc0d |
| permissions | -rw-r--r-- |
| 52 | 1 |
/* Saves the Full JSON once */ |
2 |
||
|
320
154b121a43f1
enhance save on click (snapshot mode) and update django app
cavaliet
parents:
293
diff
changeset
|
3 |
Rkns.jsonIOSaveOnClick = function(_renkan, _opts) { |
| 52 | 4 |
var _proj = _renkan.project, |
5 |
_saveWarn = false, |
|
6 |
_onLeave = function() { |
|
7 |
return "Project not saved"; |
|
8 |
}; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
190
diff
changeset
|
9 |
if (typeof _opts.http_method === "undefined") { |
| 52 | 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, |
|
|
368
3abc79964948
Close #33 - Add loading status var to set up a loading bar while the renkan is loading
rougeronj
parents:
359
diff
changeset
|
22 |
beforeSend: function(){ |
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
368
diff
changeset
|
23 |
_proj.set({loadingStatus:true}); |
|
368
3abc79964948
Close #33 - Add loading status var to set up a loading bar while the renkan is loading
rougeronj
parents:
359
diff
changeset
|
24 |
}, |
| 52 | 25 |
success: 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
|
26 |
_renkan.dataloader.load(_data); |
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
368
diff
changeset
|
27 |
_proj.set({loadingStatus:false}); |
|
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
368
diff
changeset
|
28 |
_proj.set({saveStatus:0}); |
| 52 | 29 |
} |
30 |
}); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
116
diff
changeset
|
31 |
}; |
| 52 | 32 |
var _save = function() { |
33 |
_proj.set("saved_at", new Date()); |
|
34 |
var _data = _proj.toJSON(); |
|
35 |
Rkns.$.ajax({ |
|
36 |
type: _opts.http_method, |
|
37 |
url: _opts.url, |
|
38 |
contentType: "application/json", |
|
39 |
data: JSON.stringify(_data), |
|
|
357
70e577b0cdc6
add save_status var to specify the status of the renkan (saved/to-save/saving)
rougeronj
parents:
320
diff
changeset
|
40 |
beforeSend: function(){ |
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
368
diff
changeset
|
41 |
_proj.set({saveStatus:2}); |
|
357
70e577b0cdc6
add save_status var to specify the status of the renkan (saved/to-save/saving)
rougeronj
parents:
320
diff
changeset
|
42 |
}, |
| 52 | 43 |
success: function(data, textStatus, jqXHR) { |
44 |
$(window).off("beforeunload", _onLeave); |
|
45 |
_saveWarn = false; |
|
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
368
diff
changeset
|
46 |
_proj.set({saveStatus:0}); |
|
320
154b121a43f1
enhance save on click (snapshot mode) and update django app
cavaliet
parents:
293
diff
changeset
|
47 |
//document.location.hash = "#id=" + data.id; |
|
154b121a43f1
enhance save on click (snapshot mode) and update django app
cavaliet
parents:
293
diff
changeset
|
48 |
//$(".Rk-Notifications").text("Saved as "+document.location.href).fadeIn().delay(2000).fadeOut(); |
| 52 | 49 |
} |
50 |
}); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
116
diff
changeset
|
51 |
}; |
| 52 | 52 |
var _checkLeave = function() { |
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
368
diff
changeset
|
53 |
_proj.set({saveStatus:1}); |
|
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
368
diff
changeset
|
54 |
|
| 52 | 55 |
var title = _proj.get("title"); |
56 |
if (title && _proj.get("nodes").length) { |
|
57 |
$(".Rk-Save-Button").removeClass("disabled"); |
|
58 |
} else { |
|
59 |
$(".Rk-Save-Button").addClass("disabled"); |
|
60 |
} |
|
61 |
if (title) { |
|
62 |
$(".Rk-PadTitle").css("border-color","#333333"); |
|
63 |
} |
|
64 |
if (!_saveWarn) { |
|
65 |
_saveWarn = true; |
|
66 |
$(window).on("beforeunload", _onLeave); |
|
67 |
} |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
116
diff
changeset
|
68 |
}; |
| 52 | 69 |
_load(); |
70 |
_proj.on("add:nodes add:edges add:users change", function(_model) { |
|
|
357
70e577b0cdc6
add save_status var to specify the status of the renkan (saved/to-save/saving)
rougeronj
parents:
320
diff
changeset
|
71 |
_model.on("change remove", function(_model) { |
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
368
diff
changeset
|
72 |
if(!(_model.changedAttributes.length === 1 && _model.hasChanged('saveStatus'))) { |
|
357
70e577b0cdc6
add save_status var to specify the status of the renkan (saved/to-save/saving)
rougeronj
parents:
320
diff
changeset
|
73 |
_checkLeave(); |
|
70e577b0cdc6
add save_status var to specify the status of the renkan (saved/to-save/saving)
rougeronj
parents:
320
diff
changeset
|
74 |
} |
|
70e577b0cdc6
add save_status var to specify the status of the renkan (saved/to-save/saving)
rougeronj
parents:
320
diff
changeset
|
75 |
}); |
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
368
diff
changeset
|
76 |
if(!(_proj.changedAttributes.length === 1 && _proj.hasChanged('saveStatus'))) { |
|
357
70e577b0cdc6
add save_status var to specify the status of the renkan (saved/to-save/saving)
rougeronj
parents:
320
diff
changeset
|
77 |
_checkLeave(); |
|
70e577b0cdc6
add save_status var to specify the status of the renkan (saved/to-save/saving)
rougeronj
parents:
320
diff
changeset
|
78 |
} |
| 52 | 79 |
}); |
| 190 | 80 |
_renkan.renderer.save = function() { |
81 |
if ($(".Rk-Save-Button").hasClass("disabled")) { |
|
| 52 | 82 |
if (!_proj.get("title")) { |
83 |
$(".Rk-PadTitle").css("border-color","#ff0000"); |
|
84 |
} |
|
85 |
} else { |
|
86 |
_save(); |
|
87 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
190
diff
changeset
|
88 |
}; |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
116
diff
changeset
|
89 |
}; |