Index: controlies/trunk/applications/controlies/views/laptops_groups/form.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops_groups/form.html	(revision 367)
+++ controlies/trunk/applications/controlies/views/laptops_groups/form.html	(revision 368)
@@ -16,7 +16,7 @@
     function send(){
 
         restartStyle();
-        jQuery.post('call/json/modify', jQuery("#form_data").serialize(), function(result) {
+        jQuery.post("{{=URL(c='laptops_groups',f='call',args=['json','addLaptop'])}}", jQuery("#form_data").serialize(), function(result) {
             switch(result.response){
                 case "OK":{
                     jQuery('#message').html("Operación realizada correctamente").css("color","green").effect("highlight", {"color":"yellow"}, 1000);
@@ -48,9 +48,7 @@
 </script>
  
 <form id="form_data" onsubmit="return send();">
-    <input type="hidden" id="action" name="action"/>
-    <input type="hidden" id="username" name="username"/>
-    <input type="hidden" id="id_laptop" name="id_laptop"/>    
+    <input type="hidden" id="username" name="username"/>    
     <div>
 		<p><span id="id_trademarkTag">Marca / Modelo</span><br>
 			<select type="text" id="id_trademark" name="id_trademark">
Index: controlies/trunk/applications/controlies/views/laptops_groups/index.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops_groups/index.html	(revision 367)
+++ controlies/trunk/applications/controlies/views/laptops_groups/index.html	(revision 368)
@@ -106,8 +106,9 @@
 					sortname: 'cn',
 					sortorder: "desc",
 					onSelectRow: function(uid){
-						cellValue = jQuery("#"+subgrid_table_id).getCell(uid, 'serial_number');
-
+						cellValue = jQuery.trim(jQuery("#"+subgrid_table_id).getCell(uid, 'serial_number'));
+						jQuery("#"+subgrid_table_id).setCell(uid, 'serial_number',cellValue);
+						
 						if(uid && uid!==lastsel){
 							jQuery("#"+subgrid_table_id).jqGrid('restoreRow',lastsel);
 						}
@@ -130,7 +131,8 @@
 												addLaptop(jQuery("#"+subgrid_table_id).getCell(uid, 'serial_number'),uid);
 							                },
 							                "No": function() {
-							                	jQuery("#"+subgrid_table_id).setCell(uid, 'serial_number',' ');
+							                	if (cellValue=="") cellValue=null;
+							                	jQuery("#"+subgrid_table_id).setCell(uid, 'serial_number',cellValue);
 							                    $(this).dialog( "close" );
 							                }
 							            }
@@ -146,18 +148,21 @@
 							                "Sí": function() {
 							                	newSerial = jQuery("#"+subgrid_table_id).getCell(uid, 'serial_number');							                	
 							                    $(this).dialog( "close" );
-										        $.post("{{=URL(c='laptops_groups',f='call',args=['json','reassignmentSerialNumber'])}}","username="+uid+"&serial="+cellValue+"&newSerial="+newSerial ,  function(request) {
+										        $.post("{{=URL(c='laptops_groups',f='call',args=['json','reassignmentSerialNumber'])}}","username="+uid+"&serial_number="+cellValue+"&newSerial="+newSerial ,  function(request) {
 										        	jQuery("#"+subgrid_table_id).trigger("reloadGrid"); 
 										        });    
 							                },
 							                "No": function() {
-							                	if (cellValue=="") cellValue=" ";
+							                	if (cellValue=="") cellValue=null;
 							                	jQuery("#"+subgrid_table_id).setCell(uid, 'serial_number',cellValue);
 							                    $(this).dialog( "close" );
 							                }
 							            }
 							        }).dialog('open');
-								}								
+								}
+								if(a.response=="unassignment"){
+							        $.post("{{=URL(c='laptops_groups',f='call',args=['json','reassignmentSerialNumber'])}}","username="+uid+"&serial_number="+cellValue+"&newSerial=" ,  function(request) {});    
+								}	
 							}
 						
 						);
@@ -205,11 +210,10 @@
 	jQuery("#dialog-form").load("form.html", function() {
 		getAllLaptopTypes();
 		            	
-	    jQuery("#form_data #action").val("add");
 	    jQuery("#form_data #username").val(uid);
         jQuery("#form_data #serial_number").attr("readonly","true");
         jQuery("#form_data #serial_number").css("background-color","#DDD");
-	    jQuery("#form_data #serial_number").val(serial_number);
+	    jQuery("#form_data #serial_number").val(jQuery.trim(serial_number));
 	    jQuery("#form_data #messageForm").html("Todos los campos son obligatorios");                                     
 	
 	    x = (jQuery(window).width()-350)/2;
@@ -229,7 +233,7 @@
 
 
 function getAllLaptopTypes(){
-    $.post("call/json/getAllLaptopTypes",   function(result) {
+    $.post("{{=URL(c='laptops',f='call',args=['json','getAllLaptopTypes'])}}",   function(result) {
         $.each( result.response, function(i, l){
             jQuery("#form_data #id_trademark").append("<option value='"+l.id_trademark+"'>"+l.trademark+"</option>");
         });                    
@@ -236,28 +240,6 @@
     });             
 }
 
-function rowSelected(){
-        var uid = jQuery("#list").jqGrid('getGridParam','selrow'); 
-    
-        if( uid == null ){
-            jQuery( "#dialog-alert" ).dialog({
-                resizable: false,
-                height:150,
-                width:290,
-                modal: true,
-                buttons: { "Aceptar": function() { $( this ).dialog( "close" ); }}
-            }).dialog('open');
-            return false;
-        }
-        return uid;
-}           
-
-
-function getAllUsers(){
-        $.post("{{=URL(c='usuarios',f='call',args=['json','getAllUsers'])}}",   function(users) { 
-        });             
-}
-
 </script>
 
 
Index: controlies/trunk/applications/controlies/controllers/laptops_groups.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/laptops_groups.py	(revision 367)
+++ controlies/trunk/applications/controlies/controllers/laptops_groups.py	(revision 368)
@@ -57,64 +57,66 @@
 @service.json
 @auth.requires_login()
 def modifySerialNumber():
+    serialNumber = request.vars["serial_number"].strip()
+
     my = SQLiteConnection()
-    l = Laptops(my,"","","")
-    id_laptop = l.existsSerialNumber(request.vars['serial_number'])
-    response=""
-    if not id_laptop:
-        response = "not_exists"
+    
+    if serialNumber=="":
+        response = "unassignment"
     else:
-        lh = LaptopsHistory(my,"",id_laptop,"","","","","","")
-        data = lh.getLastHistory()
-        if data["username"]!="" and data["username"]!=request.vars['id']:
-            response = "already_assigned"
+        l = Laptops(my,"","","")
+        id_laptop = l.existsSerialNumber(serialNumber)
+        response=""
+        if not id_laptop:
+            response = "not_exists"
         else:
-            ld=conecta()
-            u = Users(ld,"","","","",request.vars["id"],"","","","")
-            userData = u.getUserData() 
-            ld.close() 
+            lh = LaptopsHistory(my,"",id_laptop,"","","","","","")
+            data = lh.getLastHistory()
+            if data["username"]!="" and data["username"]!=request.vars['id']:
+                response = "already_assigned"
+            elif data["username"]!="" and data["username"]==request.vars['id']:
+                response = "OK"
+            else:
+                userData = getUserData(request.vars["id"])
+    
+                lh = LaptopsHistory(my,"",id_laptop,"2","1",userData["nif"],request.vars["id"],userData["name"],"Reasignado")
+                lh.add()
+                response="OK"
 
-            lh = LaptopsHistory(my,"",id_laptop,"2","1",userData["nif"],request.vars["id"],userData["name"],"Reasignado")
-            lh.add()
-            response="OK"
+    return dict(response=response)
 
-    return dict(response=response) 
-
 @service.json
 @auth.requires_login()
 def reassignmentSerialNumber():
+    serialNumber = request.vars["serial_number"].strip()
+    newSerialNumber = request.vars["newSerial"].strip()
+    
     my = SQLiteConnection()
     l = Laptops(my,"","","")
             
-    if request.vars["serial"]!="":
-        id_laptop = l.existsSerialNumber(request.vars['serial'])        
-        unassignment = LaptopsHistory(my,"",id_laptop,"1","","","","","Desasignado")
-        unassignment.add()
+    if serialNumber!="":
+        id_laptop = l.existsSerialNumber(serialNumber)
+        unassignmentLaptop(id_laptop)
     
-    ld=conecta()
-    u = Users(ld,"","","","",request.vars["username"],"","","","")
-    userData = u.getUserData() 
-    ld.close() 
+    if newSerialNumber!="":
+        userData = getUserData(request.vars["username"])
+    
+        id_laptop = l.existsSerialNumber(newSerialNumber)
+        lh = LaptopsHistory(my,"",id_laptop,"2","1",userData["nif"],request.vars["username"],userData["name"],"Reasignado")
+        lh.add()
 
-    id_laptop = l.existsSerialNumber(request.vars['newSerial'])
-    lh = LaptopsHistory(my,"",id_laptop,"2","1",userData["nif"],request.vars["username"],userData["name"],"Reasignado")
-    lh.add()
-    response="OK"
+    return dict(response="OK") 
 
-    return dict(response=response) 
-
 @service.json
 @auth.requires_login()    
-def modify():
+def addLaptop():
+    serialNumber = request.vars["serial_number"].strip()
     my = SQLiteConnection()
-    l = Laptops(my,"",request.vars["serial_number"],request.vars["id_trademark"])
-    response = l.process(request.vars["action"])
+    l = Laptops(my,"",serialNumber,request.vars["id_trademark"])
+    response = l.process("add")
     
     if response=="OK":
-        ld=conecta()
-        u = Users(ld,"","","","",request.vars["username"],"","","","")
-        userData = u.getUserData() 
-        ld.close() 
+        userData = getUserData(request.vars["username"])
 
         max = l.getMaxId()
         lh = LaptopsHistory(my,"",max,"2","1",userData["nif"],request.vars["username"],userData["name"],"Reasignado")
@@ -121,20 +123,24 @@
         
         id_laptop = lh.userAssignment()
         if id_laptop:
-             unassignment = LaptopsHistory(my,"",id_laptop,"1","","","","","Desasignado")
-             unassignment.add()
+            unassignmentLaptop(id_laptop)
              
         lh.add()
     
     return dict(response = response)  
 
-@service.json
-def getAllLaptopTypes():
+def getUserData(username):
+    ld=conecta()
+    u = Users(ld,"","","","",username,"","","","")
+    userData = u.getUserData() 
+    ld.close()
+    return userData
+
+def unassignmentLaptop(id_laptop):
     my = SQLiteConnection()
-    l = Laptops(my,"","","")
-    response = l.getAllLaptopTypes()
-    return dict(response=response)
-
+    unassignment = LaptopsHistory(my,"",id_laptop,"1","","","","","Desasignado")
+    unassignment.add()
+    
 def search():
     return dict()
 
