Update Adduser and add save_status var to specify the status of the renkan (saved/saving/to-save)
--- a/src/hdalab/static/hdalab/js/renkan-manual-save.js Mon Dec 29 17:27:43 2014 +0100
+++ b/src/hdalab/static/hdalab/js/renkan-manual-save.js Sun Jan 04 22:44:16 2015 +0100
@@ -23,14 +23,16 @@
data: getdata,
success: function(_data) {
_proj.set(_data, {validate: true});
- _proj.addUser({
- _id:_renkan.options.user_id,
- title:_renkan.options.user_name
- });
+ _proj.set({save_status:0});
_renkan.renderer.autoScale();
+
// Green color when user is authenticated
if(_opts.user_authenticated==true){
$(".Rk-Save-Button").addClass("Rk-Save-Online");
+ _proj.addUser({
+ _id:_renkan.options.user_id,
+ title:_renkan.options.user_name
+ });
}
canRemoveChangeShape = true;
_saveWarn = false;
@@ -47,9 +49,10 @@
contentType: "application/json",
data: JSON.stringify(_data),
success: function(data, textStatus, jqXHR) {
- //console.log("save success !", data);
$(window).off("beforeunload", _onLeave);
_saveWarn = false;
+ _proj.set({save_status:0});
+
if(data.substr(0,6)=="rk_id="){
_opts.url = _opts.url.split("?")[0] + "?" + data;
}
@@ -57,6 +60,8 @@
});
};
var _checkLeave = function() {
+ _proj.set({save_status:1});
+
var title = _proj.get("title");
if (title && _proj.get("nodes").length) {
$(".Rk-Save-Button").removeClass("disabled");
@@ -70,26 +75,25 @@
_saveWarn = true;
$(window).on("beforeunload", _onLeave);
}
- };
- _load();
- _proj.on("add:nodes add:edges add:users change", function(_model) {
- _model.on("change remove", function(_model) {
- _checkLeave();
- if(canRemoveChangeShape && !changeShapeRemoved){
- $(".renkan_help ul").addClass("disable");
- $(".renkan_help ul li ul").remove();
- changeShapeRemoved = true;
- }
- });
- _checkLeave();
+
if(canRemoveChangeShape && !changeShapeRemoved){
$(".renkan_help ul").addClass("disable");
$(".renkan_help ul li ul").remove();
changeShapeRemoved = true;
}
+ };
+ _load();
+ _proj.on("add:nodes add:edges add:users change", function(_model) {
+ _model.on("change remove", function(_model) {
+ if(!(_model.changedAttributes.length == 1 && _model.hasChanged('save_status'))) {
+ _checkLeave();
+ }
+ });
+ if(!(_proj.changedAttributes.length == 1 && _proj.hasChanged('save_status'))) {
+ _checkLeave();
+ }
});
_renkan.renderer.save = function() {
- //console.log("manual save _opts.user_authenticated = ", _opts.user_authenticated);
if(_opts.user_authenticated==true){
if ($(".Rk-Save-Button").hasClass("disabled")) {
if (!_proj.get("title")) {