Index: controlies/trunk/applications/controlies/views/laptops/history.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops/history.html	(revision 353)
+++ controlies/trunk/applications/controlies/views/laptops/history.html	(revision 354)
@@ -8,7 +8,7 @@
 
     function print_grid_historical(){  
           jQuery("#table_history #list_history").jqGrid({
-                url:"/controlies/laptops/call/json/listHistorical",
+                url:"/controlies/laptops/call/json/listHistory",
                 data: "{}",
                 datatype: 'json',
                 mtype: 'GET',
@@ -22,7 +22,7 @@
                 
                 colNames:['Fecha/Hora','Estado','Login','Nombre','Comentario'],
                 colModel:[ 
-                    {name:'datetime',index:'datetime', width:60, align:"center"},
+                    {name:'datetime',index:'datetime', width:70, align:"center"},
                     {name:'state',index:'state', width:60, align:"center"},
                     {name:'username',index:'username', width:50, align:"center"},
                     {name:'name',index:'name', width:100, align:"center"},             
@@ -68,6 +68,7 @@
 				getAllStates();
 				getAllUserTypes();
                 jQuery("#form_data_history #action").val("add");
+                jQuery("#form_data_history #id_laptop").val(jQuery("#form_history #id_laptop").val());
                 jQuery("#form_data_history #messageForm").html("Todos los campos son obligatorios");                                     
         
                 x = (jQuery(window).width()-350)/2;
Index: controlies/trunk/applications/controlies/views/laptops/form_history.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops/form_history.html	(revision 353)
+++ controlies/trunk/applications/controlies/views/laptops/form_history.html	(revision 354)
@@ -9,35 +9,29 @@
     });
 
     function restartStyle(){
-        $("#form_data p span").css("color","black");
-        $('#message').html("");
+        $("#form_data_history p span").css("color","black");
+        $('#messageHistory').html("");
     }
 
-    function send(){
+    function sendHistory(){
 
         restartStyle();
-        jQuery.post('call/json/modify', jQuery("#form_data_history").serialize(), function(result) {
+        jQuery.post('call/json/modifyHistory', jQuery("#form_data_history").serialize(), function(result) {
             switch(result.response){
                 case "OK":{
-                    jQuery('#message').html("Operación realizada correctamente").css("color","green").effect("highlight", {"color":"yellow"}, 1000);
-					jQuery("#list").trigger("reloadGrid");					
-					setTimeout("$('#dialog-form').dialog('close')",1000);
+                    jQuery('#messageHistory').html("Operación realizada correctamente").css("color","green").effect("highlight", {"color":"yellow"}, 1000);
+					jQuery("#list_history").trigger("reloadGrid");					
+					setTimeout("$('#dialog-form-history').dialog('close')",1000);
                     break;
                 }
                 case "fail":{
-                    jQuery('#message').html("Se produjo un error").effect("highlight", {"color":"yellow"}, 1000);
+                    jQuery('#messageHistory').html("Se produjo un error").effect("highlight", {"color":"yellow"}, 1000);
                     break;
                 }
-                case "serial_number_exists":{
-                    jQuery('#numero_serieTag').css("color","red");
-                    jQuery('#numero_serie').effect("highlight", {"color":"yellow"}, 1000).focus();
-                    jQuery('#message').html("Ya existe ese número de serie").effect("slide");                  
-                    break;
-                }
                 default:{
                     jQuery('#'+result.response+"Tag").css("color","red");
                     jQuery('#'+result.response).effect("highlight", {"color":"yellow"}, 1000).focus();
-                    jQuery('#message').html("Hay campos vacíos o incorrectos").effect("slide");
+                    jQuery('#messageHistory').html("Hay campos vacíos o incorrectos").effect("slide");
                     break;
                 }
             }
@@ -48,16 +42,17 @@
 
 </script>
  
-<form id="form_data_history" onsubmit="return send();">
+<form id="form_data_history" onsubmit="return sendHistory();">
     <input type="hidden" id="action" name="action"/>
-    <input type="hidden" id="id_laptop" name="id_laptop"/>    
+    <input type="hidden" id="id_laptop" name="id_laptop"/>
+    <input type="hidden" id="id_history" name="id_history"/>    
     <div>
-		<p><span id="id_statesTag">Estado (*)</span><br>
+		<p><span id="id_stateTag">Estado (*)</span><br>
 			<select type="text" id="id_state" name="id_state">
 				<option value="none">Seleccione...</option>
 			</select>
 		</p>
-		<p><span id="id_statesTag">Tipo usuario (*)</span><br>
+		<p><span id="id_user_typeTag">Tipo usuario (*)</span><br>
 			<select type="text" id="id_user_type" name="id_user_type">
 				<option value="none">Seleccione...</option>
 			</select>
@@ -66,7 +61,7 @@
 		<p><span id="nameTag">Nombre y Apellidos</span><br><input type="text" id="name" name="name" size="35" maxlength="200"/></p>
 		<p><span id="commentTag">Comentario</span><br><input type="text" id="comment" name="comment" size="35" maxlength="200"/></p>
     </div>
-    <div id="message" style="text-align:center; font-weight:bold; color:red; padding:3px; "></div>
+    <div id="messageHistory" style="text-align:center; font-weight:bold; color:red; padding:3px; "></div>
     <div style="text-align:center;"><button id="saveButtonFormHistory" type="submit" style="width:100px;">Guardar</button>&nbsp;&nbsp;<button type="button" id="cancelButtonFormHistory" style="width:100px;">Cancelar</button></div>
-    <p style="padding-top:10px; text-align:center; font-size:10px;" id="messageForm"></p>       
+    <p style="padding-top:10px; text-align:center; font-size:10px;" id="messageFormHistory"></p>       
 </form>
Index: controlies/trunk/applications/controlies/controllers/laptops.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/laptops.py	(revision 353)
+++ controlies/trunk/applications/controlies/controllers/laptops.py	(revision 354)
@@ -1,5 +1,6 @@
 # coding: utf8
 from applications.controlies.modules.Laptops import Laptops
+from applications.controlies.modules.LaptopsHistory import LaptopsHistory
 from applications.controlies.modules.SQLiteConnection import SQLiteConnection
 from applications.controlies.modules.Utils import Utils
 
@@ -6,6 +7,8 @@
 def index():    
     return dict()
 
+################## LAPTOPS ####################
+
 @service.json
 @auth.requires_login()
 def list():    
@@ -29,20 +32,14 @@
     return dict(response=response)
 
 @service.json
-def getAllStates():
+@auth.requires_login()    
+def modify():
     my = SQLiteConnection()
-    l = Laptops(my,"","","")
-    response = l.getAllStates()
-    return dict(response=response)
+    l = Laptops(my,request.vars["id_laptop"],request.vars["serial_number"],request.vars["id_trademark"])
+    response = l.process(request.vars["action"])
+    return dict(response = response)            
 
 @service.json
-def getAllUserTypes():
-    my = SQLiteConnection()
-    l = Laptops(my,"","","")
-    response = l.getAllUserTypes()
-    return dict(response=response)
-
-@service.json
 @auth.requires_login()       
 def delete():
     my = SQLiteConnection()
@@ -50,22 +47,39 @@
     response = l.delete()                         
     return dict(response=response)
 
+################## LAPTOPS HISTORY ####################
+
 @service.json
+@auth.requires_login()
+def listHistory():    
+    my = SQLiteConnection()
+    l = LaptopsHistory(my,"",request.vars["id_laptop"],"","","","","")
+    response = l.list(request.vars)
+    return response
+
+@service.json
 @auth.requires_login()    
-def modify():
+def modifyHistory():
     my = SQLiteConnection()
-    l = Laptops(my,request.vars["id_laptop"],request.vars["serial_number"],request.vars["id_trademark"])
+    l = LaptopsHistory(my,"",request.vars["id_laptop"],request.vars["id_state"],request.vars["id_user_type"],request.vars["username"],request.vars["name"],request.vars["comment"])
     response = l.process(request.vars["action"])
-    return dict(response = response)            
+    return dict(response = response)   
 
 @service.json
-@auth.requires_login()
-def listHistorical():    
+def getAllStates():
     my = SQLiteConnection()
-    l = Laptops(my,"","","")
-    response = l.listHistorical(request.vars)
-    return response
+    l = LaptopsHistory(my,"","","","","","","")
+    response = l.getAllStates()
+    return dict(response=response)
 
+@service.json
+def getAllUserTypes():
+    my = SQLiteConnection()
+    l = LaptopsHistory(my,"","","","","","","")
+    response = l.getAllUserTypes()
+    return dict(response=response)
+
+
 def laptops():
     return dict()
 
Index: controlies/trunk/applications/controlies/modules/SQLiteConnection.py
===================================================================
--- controlies/trunk/applications/controlies/modules/SQLiteConnection.py	(revision 353)
+++ controlies/trunk/applications/controlies/modules/SQLiteConnection.py	(revision 354)
@@ -50,6 +50,12 @@
                         Field('user_type','string'),
                         primarykey=['id_user_type'])
 
+        try:
+            self.db.users_types.insert(id_user_type='1',user_type='Profesor')
+            self.db.users_types.insert(id_user_type='2',user_type='Alumno')
+        except:
+            pass
+        
         self.db.define_table('laptops_historical', 
                         Field('id_historical','integer'),
                         Field('id_laptop','integer'),                        
@@ -59,13 +65,19 @@
                         Field('id_user_type','integer'),
                         Field('comment','string'),
                         Field('id_state','integer'),
-                        primarykey=['id_historical','id_laptop'])
+                        primarykey=['id_historical'])
 
         self.db.define_table('states', 
                         Field('id_state','integer'),
                         Field('state','string'),                        
                         primarykey=['id_state'])
-
+        try:
+            self.db.states.insert(id_state='1',state='Sin asignar')
+            self.db.states.insert(id_state='2',state='Asignado')
+            self.db.states.insert(id_state='3',state='En reparación')
+        except:
+            pass
+        
     def getDB(self):
         return self.db
 
Index: controlies/trunk/applications/controlies/modules/Laptops.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Laptops.py	(revision 353)
+++ controlies/trunk/applications/controlies/modules/Laptops.py	(revision 354)
@@ -136,49 +136,7 @@
 
         return { "page":page, "total":totalPages, "records":len(rows), "rows":rows[start:finish] }
 
-    def listHistorical(self,args):
-        db = self.SQLite.getDB()
 
-        sql = "SELECT * FROM laptops_historical lh INNER JOIN states s ON lh.id_state=s.id_state"
-        sql = sql + " WHERE lh.id_laptop='"+args["id_laptop"]+"'"
-        sql = sql + " ORDER BY "+args['sidx']+" "+args['sord']
-        result = db.executesql(sql)
-
-        rows = []
-        for reg in result:
-            row = {
-                "id":reg[0],
-                "cell":[reg[2],reg[9],reg[3],reg[4],reg[6]],
-                "datetime":reg[2],
-                "state":reg[9],
-                "username":reg[3],
-                "name":reg[4],
-                "comment":reg[6]
-            }
-            rows.append(row)
-
-        # grid parameters
-        limit = int(args['rows'])
-        page = int(args['page'])
-        start = limit * page - limit
-        finish = start + limit;             
-                    
-        # grid parameters
-        if len(rows) > 0:
-            totalPages = floor( len(rows) / int(limit) )
-            module = len(rows) % int(limit)
-
-            if module > 0:
-                totalPages = totalPages+1
-        else:
-            totalPages = 0
-
-        if page > totalPages:
-            page = totalPages
-
-        return { "page":page, "total":totalPages, "records":len(rows), "rows":rows[start:finish] }
-
-
     def add(self):
         sql = "INSERT INTO laptops (id_laptop, serial_number, id_trademark) "
         sql = sql + "VALUES(null,'"+self.serial_number+"','"+self.id_trademark+"')"
@@ -247,31 +205,3 @@
             }
             data.append(dataType)
         return data
-
-    def getAllStates(self):
-        sql="SELECT * FROM states ORDER BY state"
-        db = self.SQLite.getDB()
-        result = db.executesql(sql)
-
-        data=[]
-        for r in result:
-            dataType = {
-                "id_state":str(r[0]),
-                "state":r[1]
-            }
-            data.append(dataType)
-        return data
-
-    def getAllUserTypes(self):
-        sql="SELECT * FROM users_types ORDER BY user_type"
-        db = self.SQLite.getDB()
-        result = db.executesql(sql)
-
-        data=[]
-        for r in result:
-            dataType = {
-                "id_user_type":str(r[0]),
-                "user_type":r[1]
-            }
-            data.append(dataType)
-        return data
\ No newline at end of file
Index: controlies/trunk/applications/controlies/modules/LaptopsHistory.py
===================================================================
--- controlies/trunk/applications/controlies/modules/LaptopsHistory.py	(nonexistent)
+++ controlies/trunk/applications/controlies/modules/LaptopsHistory.py	(revision 354)
@@ -0,0 +1,177 @@
+##############################################################################
+# -*- coding: utf-8 -*-
+# Project:      ControlIES
+# Module:       LaptopsHistory.py
+# Purpose:      LaptopsHistory class
+# Language:     Python 2.5
+# Date:         6-Jun-2012.
+# Ver:          6-Jun-2012.
+# Author:       Manuel Mora Gordillo
+# Copyright:    2012 - Manuel Mora Gordillo <manuito @no-spam@ gmail.com>
+#
+# ControlIES is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# ControlIES is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with ControlIES. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from math import floor
+import datetime
+
+class LaptopsHistory(object):
+
+    def __init__(self):
+        pass
+    
+    def __init__(self,SQLite,id_history,id_laptop,id_state,id_user_type,username,name,comment):
+        self.SQLite = SQLite
+        self.id_history = id_history        
+        self.id_laptop = id_laptop
+        self.id_state = id_state
+        self.id_user_type = id_user_type
+        self.username = username
+        self.name = name
+        self.comment = comment
+        
+    def validation(self,action):
+
+        if self.id_state == "none":
+            return "id_state"
+
+        if self.id_user_type == "none":
+            return "id_user_type"
+
+        if self.username == "":
+            return "username"
+                
+        return "OK"
+
+    def process(self,action):
+        if action == "add":
+            val = self.validation(action)
+            
+            if val != "OK":
+                return val
+            else:
+                response = self.add()
+                return response
+
+        if action == "modify":
+            val = self.validation(action)
+            
+            if val != "OK":
+                return val
+            else:
+                response = self.modify()
+                return response
+        
+    def list(self,args):
+        db = self.SQLite.getDB()
+
+        sql = "SELECT id_historical, datetime, state, username, name, comment FROM laptops_historical lh INNER JOIN states s ON lh.id_state=s.id_state"
+        sql = sql + " WHERE lh.id_laptop='"+str(args["id_laptop"])+"'"
+        sql = sql + " ORDER BY "+args['sidx']+" "+args['sord']
+        result = db.executesql(sql)
+
+        rows = []
+        for reg in result:
+            d = datetime.datetime.strptime(str(reg[1]), '%Y-%m-%d %H:%M:%S')
+            new_dataformat = d.strftime('%d/%m/%Y %H:%M:%S')
+
+            row = {
+                "id":reg[0],
+                "cell":[new_dataformat,reg[2],reg[3],reg[4],reg[5]],
+                "datetime":new_dataformat,
+                "state":reg[2],
+                "username":reg[3],
+                "name":reg[4],
+                "comment":reg[5]
+            }
+            rows.append(row)
+
+        # grid parameters
+        limit = int(args['rows'])
+        page = int(args['page'])
+        start = limit * page - limit
+        finish = start + limit;             
+                    
+        # grid parameters
+        if len(rows) > 0:
+            totalPages = floor( len(rows) / int(limit) )
+            module = len(rows) % int(limit)
+
+            if module > 0:
+                totalPages = totalPages+1
+        else:
+            totalPages = 0
+
+        if page > totalPages:
+            page = totalPages
+
+        return { "page":page, "total":totalPages, "records":len(rows), "rows":rows[start:finish] }
+
+
+    def add(self):
+        now = datetime.datetime.now()
+        #date = str(now.year)+"-"+str(now.month)+"-"+str(now.day)+" "+str(now.hour)+"-"+str(now.minute)+"-"+str(now.second)
+        sql = "INSERT INTO laptops_historical (id_historical,id_laptop,datetime,username,name,id_user_type,comment,id_state) "
+        sql = sql + "VALUES(null,'"+self.id_laptop+"','"+now.strftime('%Y-%m-%d %H:%M:%S')+"','"+self.username+"','"+self.name+"','"+self.id_user_type+"','"+self.comment+"','"+self.id_state+"')"
+        print sql
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+        
+        return "OK"
+            
+            
+    def modify(self):
+        sql = "UPDATE laptops SET serial_number='"+self.serial_number+"', id_trademark='"+self.id_trademark+"' "
+        sql = sql + "WHERE id_laptop='"+str(self.id_laptop)+"'"
+
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+                    
+        return "OK"
+
+
+    def delete(self):
+        sql = "DELETE FROM laptops WHERE id_laptop='"+str(self.id_laptop)+"'"
+
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+            
+        return "OK"
+
+    def getAllStates(self):
+        sql="SELECT * FROM states ORDER BY state"
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+
+        data=[]
+        for r in result:
+            dataType = {
+                "id_state":str(r[0]),
+                "state":r[1]
+            }
+            data.append(dataType)
+        return data
+
+    def getAllUserTypes(self):
+        sql="SELECT * FROM users_types ORDER BY user_type"
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+
+        data=[]
+        for r in result:
+            dataType = {
+                "id_user_type":str(r[0]),
+                "user_type":r[1]
+            }
+            data.append(dataType)
+        return data
\ No newline at end of file

Property changes on: controlies/trunk/applications/controlies/modules/LaptopsHistory.py
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
