close 55 - On login, add user to project and set current user of renken to this new user
authorrougeronj
Thu, 05 Feb 2015 13:18:29 +0100
changeset 440 4c4cfe573486
parent 439 23062d01db3d
child 441 7eee076e994e
close 55 - On login, add user to project and set current user of renken to this new user
src/hdalab/static/hdalab/js/renkan-manual-save.js
src/hdalab/templates/renkan_edit.html
--- a/src/hdalab/static/hdalab/js/renkan-manual-save.js	Tue Feb 03 16:24:07 2015 +0100
+++ b/src/hdalab/static/hdalab/js/renkan-manual-save.js	Thu Feb 05 13:18:29 2015 +0100
@@ -34,12 +34,8 @@
                 _proj.set({save_status:0});
             	_renkan.renderer.autoScale();
             	
-            	// Green color when user is authenticated
             	if(_opts.user_authenticated==true){
-            	    _proj.addUser({
-                		_id:_renkan.options.user_id,
-                		title:_renkan.options.user_name
-                	});
+            		_renkan.setCurrentUser(_opts.user_id, _opts.user_name);
             	}
             	canRemoveChangeShape = true;
             	_saveWarn = false;
@@ -48,13 +44,6 @@
         });
     };
     var _save = function() {
-    	if (_opts.login_user==true){
-    		_proj.addUser({
-        		_id:_opts.user_id,
-        		title:_opts.user_name
-        	});
-    		_opts.login_user=false;
-    	}
         _proj.set("saved_at", new Date());
         var _data = _proj.toJSON();
         Rkns.$.ajax({
@@ -73,6 +62,13 @@
             }
         });
     };
+    var _changeDispositionDisable = function() {
+    	if(canRemoveChangeShape && !changeShapeRemoved){
+        	$(".renkan_help ul").addClass("disable");
+        	$(".renkan_help ul li ul").remove();
+            changeShapeRemoved = true;
+        }
+    }
     var _checkLeave = function() {
     	_proj.set({save_status:1});
     	
@@ -89,24 +85,25 @@
             _saveWarn = true;
             $(window).on("beforeunload", _onLeave);
         }
-        
-        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) {
+    _proj.on("add:nodes add:edges change", function(_model) {
 		_model.on("change remove", function(_model) {
         	if(!(_model.changedAttributes.length == 1 && _model.hasChanged('save_status'))) {
         		_checkLeave();
+        		_changeDispositionDisable()
         	}
         });
     	if(!(_proj.changedAttributes.length == 1 && _proj.hasChanged('save_status'))) {
             _checkLeave();
+            if (!_proj.hasChanged('saved_at')){
+            	_changeDispositionDisable()
+            }
     	}
     });
+    _proj.on("add:users", function(){
+    	_checkLeave();
+    });
     _renkan.renderer.save = function() {
         if(_opts.user_authenticated==true){
             if ($(".Rk-Save-Button").hasClass("disabled")) {
--- a/src/hdalab/templates/renkan_edit.html	Tue Feb 03 16:24:07 2015 +0100
+++ b/src/hdalab/templates/renkan_edit.html	Thu Feb 05 13:18:29 2015 +0100
@@ -31,8 +31,8 @@
         <script src="{% static 'hdalab/js/renkan-manual-save.js' %}"></script>
         <script src="{% static 'hdalab/js/hdalab-renkan-bins.js' %}"></script>
         <script type="text/javascript">
-            var io_options = {}, dialog=false;
-            function startRenkan(){
+            var io_options = {}, dialog=false, _rkn;
+           	function startRenkan(){
                 var _renkan = new Rkns.Renkan({
                     manual_save: true,
                 	user_color_editable: false,
@@ -86,6 +86,7 @@
                 io_options = { url: "{% url 'renkan_get_put' %}" + window.location.search, user_authenticated: {% if user.is_authenticated %}true{% else %}false{% endif %} };
                 Rkns.jsonIOSaveOnClick(_renkan, io_options);
                 
+                _rkn = _renkan;
             };
             
             $(function() {
@@ -112,15 +113,15 @@
                         success: function(data, textStatus, jqXHR) {
                             var d = $(data);
                             if(d.hasClass("ok")){
-                                io_options.user_authenticated = true;
                                 io_options.login_user = true;
                                 io_options.user_id= d.attr("id");
                                 io_options.user_name= $("#username",d).html();
+                                io_options.user_authenticated = true;
                                 
-                                $("#menu.profile").html(d.html());
-                                $(".Rk-CurrentUser-Name").html(io_options.user_name);                           
+                                _rkn.setCurrentUser(io_options.user_id, io_options.user_name);
+                                $("#menu.profile").html(d.html());                           
+                                $(".Rk-Save-Button").click();
                                 dialog.dialog( "close" );
-                                $(".Rk-Save-Button").click();
                                 return true;
                             }
                             $("#dialog-form").html(data);