client/js/save-once.js
changeset 357 70e577b0cdc6
parent 320 154b121a43f1
child 359 9fc64b41466c
--- a/client/js/save-once.js	Sun Jan 04 22:41:27 2015 +0100
+++ b/client/js/save-once.js	Sun Jan 04 22:42:49 2015 +0100
@@ -21,6 +21,7 @@
             data: getdata,
             success: function(_data) {
                 _proj.set(_data, {validate: true});
+                _proj.set({save_status:0});
             	_renkan.renderer.autoScale();
             }
         });
@@ -33,15 +34,21 @@
             url: _opts.url,
             contentType: "application/json",
             data: JSON.stringify(_data),
+            beforeSend: function(){
+            	_proj.set({save_status:2});
+            },
             success: function(data, textStatus, jqXHR) {
                 $(window).off("beforeunload", _onLeave);
                 _saveWarn = false;
+                _proj.set({save_status:0});
                 //document.location.hash = "#id=" + data.id;
                 //$(".Rk-Notifications").text("Saved as "+document.location.href).fadeIn().delay(2000).fadeOut();
             }
         });
     };
     var _checkLeave = function() {
+    	_proj.set({save_status:1});
+    	
         var title = _proj.get("title");
         if (title && _proj.get("nodes").length) {
             $(".Rk-Save-Button").removeClass("disabled");
@@ -58,10 +65,14 @@
     };
     _load();
     _proj.on("add:nodes add:edges add:users change", function(_model) {
-        _model.on("change remove", function(_model) {
-            _checkLeave();
-        });
-        _checkLeave();
+	    _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() {
         if ($(".Rk-Save-Button").hasClass("disabled")) {