Index: controlies/trunk/applications/controlies/models/menu.py
===================================================================
--- controlies/trunk/applications/controlies/models/menu.py	(revision 360)
+++ controlies/trunk/applications/controlies/models/menu.py	(revision 361)
@@ -47,8 +47,9 @@
             ]
    )]
 
-response.menu+=[('Base Datos', False, None,[            
+response.menu+=[('BD Portátiles', False, None,[            
             ('Portátiles', False,URL( 'laptops', 'index')),
+            ('Marcas', False,URL( 'laptops_trademarks', 'index')),   
             ]
    )]
 
Index: controlies/trunk/applications/controlies/views/laptops_trademarks/index.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops_trademarks/index.html	(nonexistent)
+++ controlies/trunk/applications/controlies/views/laptops_trademarks/index.html	(revision 361)
@@ -0,0 +1,207 @@
+<!-- Libreria Multiselect -->
+{{response.files.append(URL('static','js/multiselect/jquery.multiselect.css'))}}
+{{response.files.append(URL('static','js/multiselect/jquery.multiselect.min.js'))}}
+{{response.files.append(URL('static','js/multiselect/jquery.multiselect.es.js'))}}
+{{#response.files.append(URL('static','css/helper.css'))}}
+{{#response.files.append(URL('static','css/dropdown.css'))}}
+{{#response.files.append(URL('static','css/default.advanced.css'))}}
+ 
+{{extend 'layout.html'}}
+
+        <div id="tabla_clientes" class="centerGrid">
+            <table width="100%" align="center">
+            <tr>
+                <td style="width:2%"></td>
+                <td style="text-align:center;"><table id="list" width="100%"></table></td>
+                <td style="width:2%"></td>
+            </tr>
+            </table>
+            <div id="pager" style=""></div> 
+            <div id="filter" style="margin-left:30%;display:none">Buscar nada</div>
+        </div>
+
+        <div id="dialog-form"></div>
+
+        <div id="dialog-confirm" title="¿Borrar el registro seleccionado?" style="display:none;">
+            <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Este elemento quedará permanentemente eliminado. ¿Está seguro?</p>
+        </div>
+
+        <div id="dialog-alert" title="Atención" style="display:none;">
+            <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Para operar sobre un registro debe seleccionarlo previamente.</p>
+        </div>
+
+
+<script type="text/javascript">  
+    
+    jQuery(function() {
+        jQuery("#dialog-confirm").dialog({ autoOpen: false });
+        jQuery("#dialog-alert").dialog({ autoOpen: false });
+    });
+    
+                
+    function print_grid(){  
+          jQuery("#list").jqGrid({
+                url:"/controlies/laptops_trademarks/call/json/list",
+                data: "{}",
+                datatype: 'json',
+                mtype: 'GET',
+                contentType: "application/json; charset=utf-8",
+                complete: function(jsondata, stat) {
+                    if (stat == "success") {
+                        var thegrid = jQuery("#list")[0];
+                        thegrid.addJSONData(JSON.parse(jsondata.responseText).d);
+                    }
+                },
+                
+                colNames:['Marca','Modelo'],
+                colModel:[ 
+                    {name:'trademark',index:'trademark', width:60, align:"center"},
+                    {name:'model',index:'model', width:115, align:"center"}],
+                rowNum:25,
+                height:335,
+                width: 900,
+                rowList:[25,50,75],  
+                pager: '#pager', 
+                sortname: 'trademark', 
+                autowidth: false,
+                viewrecords: true, 
+                sortorder: "asc", 
+                caption:"Marcas de Portátiles"    
+        
+          }); 
+          jQuery("#list").jqGrid('navGrid','#pager',{add:false,edit:false,del:false,search:false,refresh:false});
+        
+            jQuery("#list").jqGrid('navButtonAdd','#pager',{
+                    caption: "Insertar",
+                    buttonicon :'ui-icon-plus',
+                    onClickButton : function (){ 
+                        addRecord();
+                    } 
+            }); 
+            jQuery("#list").jqGrid('navButtonAdd','#pager',{
+                    caption: "Modificar", 
+                    buttonicon :'ui-icon-pencil',
+                    onClickButton : function (){ 
+                        modifyRecord();
+                } 
+            }); 
+            jQuery("#list").jqGrid('navButtonAdd','#pager',{
+                    caption: "Borrar", 
+                    buttonicon :'ui-icon-trash',
+                    onClickButton : function (){ 
+                        deleteRecord();
+                } 
+            });  
+          
+          jQuery("#list").jqGrid('filterToolbar'); 
+       
+    }
+    
+    
+    function rowSelected(){
+            var id = jQuery("#list").jqGrid('getGridParam','selrow'); 
+        
+            if( id == null ){
+                jQuery( "#dialog-alert" ).dialog({
+                    resizable: false,
+                    height:150,
+                    width:290,
+                    modal: true,
+                    buttons: { "Aceptar": function() { $( this ).dialog( "close" ); }}
+                }).dialog('open');
+                return false;
+            }
+            return id;
+    }           
+    
+    function addRecord(){
+    
+            jQuery("#messageLoading").show();
+        
+            jQuery("#dialog-form").html("").css("display","none");
+            jQuery("#dialog-form").load("form.html", function() {
+				            	
+                jQuery("#form_data #action").val("add");
+                jQuery("#form_data #messageForm").html("Todos los campos son obligatorios");                                     
+        
+                x = (jQuery(window).width()-350)/2;
+                y = (jQuery(window).height()-500)/2;
+        
+                jQuery("#messageLoading").hide();
+        
+                jQuery("#dialog-form").dialog({
+                    resizable: false,
+                    position: top,
+                    modal: true,
+                    width: 350,
+                    title: "Añadir Marca/Modelo"
+                }).dialog('option', 'position', [x, y]);
+            });
+    }
+    
+    function modifyRecord(){
+			var id;
+
+			jQuery("#messageLoading").show();
+			
+			var id = rowSelected();
+			if(id==false)
+				return false;
+
+			jQuery("#dialog-form").html("").css("display","none");
+			jQuery("#dialog-form").load("form.html", function() {
+
+				jQuery("#form_data #action").val("modify");
+				jQuery("#form_data #messageForm").html("Todos los campos son obligatorios");
+				
+				jQuery.post('call/json/getTrademarkData',{ id_trademark: id }, function(result) {						
+
+					jQuery("#form_data #id_trademark").val(result.response['id_trademark']);
+					jQuery("#form_data #trademark").val(result.response['trademark']);
+					jQuery("#form_data #model").val(result.response['model']);					
+
+					x = (jQuery(window).width()-350)/2;
+					y = (jQuery(window).height()-500)/2;
+					
+					jQuery("#messageLoading").hide();
+					
+					jQuery("#dialog-form").dialog({
+						resizable: false,
+						modal: true,
+						width: 350,
+						title: "Modificar Marca/Modelo"
+					}).dialog('option', 'position', [x, y]);                        
+				});               
+			});
+    }
+    
+    function deleteRecord(){
+        
+            var id = rowSelected();
+            if(id==false)
+                return false;
+        
+            jQuery( "#dialog-confirm" ).dialog({
+                resizable: false,
+                height:160,
+                width:350,
+                modal: true,
+                buttons: {
+                    "Borrar": function() {
+                        jQuery.post("call/json/delete","id_trademark="+id, function(data){
+                            jQuery("#dialog-confirm").dialog( "close" );
+                            jQuery("#list").trigger("reloadGrid");
+                        });
+                    },
+                    "Cancelar": function() {
+                        $(this).dialog( "close" );
+                    }
+                }
+            }).dialog('open');
+    }
+
+</script>
+
+<script type="text/javascript">
+  jQuery(document).ready(function(){ print_grid();}); 
+</script>

Property changes on: controlies/trunk/applications/controlies/views/laptops_trademarks/index.html
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: controlies/trunk/applications/controlies/views/laptops_trademarks/form.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops_trademarks/form.html	(nonexistent)
+++ controlies/trunk/applications/controlies/views/laptops_trademarks/form.html	(revision 361)
@@ -0,0 +1,63 @@
+<script language="javascript">
+
+    $(function() {
+        $("#id_trademark").focus();
+        $("#saveButton").button({ icons: { primary: "ui-icon-disk"}});
+        $("#cancelButton")
+            .button({ icons: { primary: "ui-icon-close"}})
+            .click( function(){ $('#dialog-form').dialog('close'); });
+    });
+
+    function restartStyle(){
+        $("#form_data p span").css("color","black");
+        $('#message').html("");
+    }
+
+    function send(){
+
+        restartStyle();
+        jQuery.post('call/json/modify', 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);
+					jQuery("#list").trigger("reloadGrid");					
+					setTimeout("$('#dialog-form').dialog('close')",1000);
+                    break;
+                }
+                case "fail":{
+                    jQuery('#message').html("Se produjo un error").effect("highlight", {"color":"yellow"}, 1000);
+                    break;
+                }
+                case "trademark_model_exists":{
+                    jQuery('#trademarkTag').css("color","red");
+                    jQuery('#trademark').effect("highlight", {"color":"yellow"}, 1000).focus();
+                    jQuery('#modelTag').css("color","red");
+                    jQuery('#model').effect("highlight", {"color":"yellow"}, 1000).focus();
+                    jQuery('#message').html("Ya existe esa Marca/Modelo").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");
+                    break;
+                }
+            }
+        });
+
+        return false;
+    }
+
+</script>
+ 
+<form id="form_data" onsubmit="return send();">
+    <input type="hidden" id="action" name="action"/>
+    <input type="hidden" id="id_trademark" name="id_trademark"/>    
+    <div>
+		<p><span id="trademarkTag">Marca</span><br><input type="text" id="trademark" name="trademark"/></p>
+		<p><span id="modelTag">Modelo</span><br><input type="text" id="model" name="model"/></p>
+    </div>
+    <div id="message" style="text-align:center; font-weight:bold; color:red; padding:3px; "></div>
+    <div style="text-align:center;"><button id="saveButton" type="submit" style="width:100px;">Guardar</button>&nbsp;&nbsp;<button type="button" id="cancelButton" style="width:100px;">Cancelar</button></div>
+    <p style="padding-top:10px; text-align:center; font-size:10px;" id="messageForm"></p>       
+</form>

Property changes on: controlies/trunk/applications/controlies/views/laptops_trademarks/form.html
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: controlies/trunk/applications/controlies/controllers/laptops_trademarks.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/laptops_trademarks.py	(nonexistent)
+++ controlies/trunk/applications/controlies/controllers/laptops_trademarks.py	(revision 361)
@@ -0,0 +1,56 @@
+# coding: utf8
+from applications.controlies.modules.LaptopsTrademarks import LaptopsTrademarks
+from applications.controlies.modules.SQLiteConnection import SQLiteConnection
+from applications.controlies.modules.Utils import Utils
+from applications.controlies.modules.Users import Users
+
+def index():
+    my = SQLiteConnection()
+    my.define_tables()    
+    return dict()
+
+################## LAPTOPS ####################
+
+@service.json
+@auth.requires_login()
+def list():    
+    my = SQLiteConnection()
+    l = LaptopsTrademarks(my,"","","")
+    response = l.list(request.vars)
+    return response
+
+@service.json
+def getTrademarkData():
+    my = SQLiteConnection()
+    l = LaptopsTrademarks(my,request.vars['id_trademark'],"","")
+    response = l.getTrademarkData()
+    return dict(response=response)
+
+@service.json
+@auth.requires_login()    
+def modify():
+    my = SQLiteConnection()
+    l = LaptopsTrademarks(my,request.vars["id_trademark"],request.vars["trademark"],request.vars["model"])
+    response = l.process(request.vars["action"])
+    return dict(response = response)            
+
+@service.json
+@auth.requires_login()       
+def delete():
+    my = SQLiteConnection()
+    l = LaptopsTrademarks(my,request.vars["id_trademark"],"","")
+    response = l.delete()                         
+    return dict(response=response)
+
+def form():
+    return dict()
+
+def call():
+    """
+    exposes services. for example:
+    http://..../[app]/default/call/jsonrpc
+    decorate with @services.jsonrpc the functions to expose
+    supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
+    """
+    session.forget()
+    return service()

Property changes on: controlies/trunk/applications/controlies/controllers/laptops_trademarks.py
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: controlies/trunk/applications/controlies/controllers/laptops.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/laptops.py	(revision 360)
+++ controlies/trunk/applications/controlies/controllers/laptops.py	(revision 361)
@@ -5,7 +5,9 @@
 from applications.controlies.modules.Utils import Utils
 from applications.controlies.modules.Users import Users
 
-def index():    
+def index():
+    my = SQLiteConnection()
+    my.define_tables()    
     return dict()
 
 ################## LAPTOPS ####################
Index: controlies/trunk/applications/controlies/controllers/default.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/default.py	(revision 360)
+++ controlies/trunk/applications/controlies/controllers/default.py	(revision 361)
@@ -44,7 +44,6 @@
             auth.settings.login_methods[0].func_defaults=tuple(new_parameters)
 
 
-
     return dict(form=auth())
 
 @auth.requires_login()
Index: controlies/trunk/applications/controlies/modules/SQLiteConnection.py
===================================================================
--- controlies/trunk/applications/controlies/modules/SQLiteConnection.py	(revision 360)
+++ controlies/trunk/applications/controlies/modules/SQLiteConnection.py	(revision 361)
@@ -30,7 +30,6 @@
     
     def __init__(self):
         self.db = DAL('sqlite://controlies.sqlite')
-        self.define_tables()
 
     def define_tables(self):
         self.db.define_table('laptops', 
Index: controlies/trunk/applications/controlies/modules/Laptops.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Laptops.py	(revision 360)
+++ controlies/trunk/applications/controlies/modules/Laptops.py	(revision 361)
@@ -102,6 +102,18 @@
         except LookupError:
             pass
 
+        try:
+            if str(args['username']) != "None":
+                sql = sql+" AND lh.username LIKE '%"+str(args['username'])+"%'"
+        except LookupError:
+            pass
+
+        try:
+            if str(args['state']) != "None":
+                sql = sql+" AND s.state LIKE '%"+str(args['state'])+"%'"
+        except LookupError:
+            pass
+
         sql = sql + " GROUP BY l.id_laptop"
         sql = sql + " ORDER BY "+args['sidx']+" "+args['sord']+", lh.datetime desc"
 
Index: controlies/trunk/applications/controlies/modules/LaptopsTrademarks.py
===================================================================
--- controlies/trunk/applications/controlies/modules/LaptopsTrademarks.py	(nonexistent)
+++ controlies/trunk/applications/controlies/modules/LaptopsTrademarks.py	(revision 361)
@@ -0,0 +1,182 @@
+##############################################################################
+# -*- coding: utf-8 -*-
+# Project:      ControlIES
+# Module:       LaptopsTrademarks.py
+# Purpose:      LaptopsTrademarks class
+# Language:     Python 2.5
+# Date:         12-Jun-2012.
+# Ver:          31-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
+
+class LaptopsTrademarks(object):
+
+    def __init__(self):
+        pass
+    
+    def __init__(self,SQLite,id_trademark,trademark,model):
+        self.SQLite = SQLite
+        self.id_trademark = id_trademark        
+        self.trademark = trademark
+        self.model = model        
+        
+    def validation(self,action):
+
+        if self.trademark == "":
+            return "trademark"
+
+        if self.model == "":
+            return "model"
+                
+        exists = self.existsTrademarkModel(self.trademark,self.model)
+        
+        if action=="add" and exists!=False:
+            return "trademark_model_exists"
+
+        if action=="modify" and exists!=False:
+            if exists!=self.id_trademark:
+                return "trademark_model_exists"
+                
+        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 * FROM laptops_trademarks WHERE 1=1 "
+        
+        try:
+            if str(args['trademark']) != "None":
+                sql = sql+" AND trademark LIKE '%"+str(args['trademark'])+"%'"
+        except LookupError:
+            pass
+
+        try:
+            if str(args['model']) != "None":
+                sql = sql+" AND model LIKE '%"+str(args['model'])+"%'"
+        except LookupError:
+            pass
+
+        sql = sql + " ORDER BY "+args['sidx']+" "+args['sord']+""
+        result = db.executesql(sql)
+
+        rows = []
+        for reg in result:
+            row = {
+				"id":reg[0],
+				"cell":[reg[1],reg[2]],
+				"trademark":reg[1],
+				"model":reg[2]
+            }
+            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_trademarks (id_trademark, trademark, model) "
+        sql = sql + "VALUES(null,'"+self.trademark+"','"+self.model+"')"
+
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+        
+        return "OK"
+            
+            
+    def modify(self):
+        sql = "UPDATE laptops_trademarks SET trademark='"+self.trademark+"', model='"+self.model+"' "
+        sql = sql + "WHERE id_trademark='"+str(self.id_trademark)+"'"
+
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+                    
+        return "OK"
+
+
+    def delete(self):
+        sql = "DELETE FROM laptops_trademarks WHERE id_trademark='"+str(self.id_trademark)+"'"
+
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+            
+        return "OK"
+
+
+    def existsTrademarkModel(self,trademark,model):
+        
+        sql = "SELECT id_trademark FROM laptops_trademarks WHERE trademark='"+trademark+"' AND model='"+model+"'"
+
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+
+        if len(result) > 0:
+            return str(result[0][0])
+        
+        return False
+        
+    def getTrademarkData(self):
+		
+        sql="SELECT * FROM laptops_trademarks WHERE id_trademark='"+str(self.id_trademark)+"'"
+
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+
+        data = {
+            "id_trademark":str(result[0][0]),
+            "trademark":result[0][1],
+            "model":str(result[0][2])
+        }
+        return data

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