Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 352

Añadido por Manu Mora Gordillo hace casi 13 años

Historial de portátiles

Ver diferencias:

controlies/trunk/applications/controlies/views/laptops/form_history.html
<script language="javascript">
$(function() {
$("#name").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 print_grid_historical(){
jQuery("#table_history #list_history").jqGrid({
url:"/controlies/laptops/call/json/listHistorical",
data: "{}",
datatype: 'json',
mtype: 'GET',
contentType: "application/json; charset=utf-8",
complete: function(jsondata, stat) {
if (stat == "success") {
var thegrid = jQuery("#table_history #list_history")[0];
thegrid.addJSONData(JSON.parse(jsondata.responseText).d);
}
},
colNames:['Fecha/Hora','Estado','Login','Nombre','Comentario'],
colModel:[
{name:'datetime',index:'datetime', width:60, 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"},
{name:'comment',index:'comment', width:100, align:"center"}
],
postData:{id_laptop:$("#form_data_history #id_laptop").val()},
rowNum:25,
height:150,
width: 780,
rowList:[25,50,75],
pager: '#pager_history',
sortname: 'datetime',
autowidth: false,
viewrecords: true,
sortorder: "desc",
caption:"Historial"
});
jQuery("#list_history").jqGrid('navGrid','#pager_history',{add:false,edit:false,del:false,search:false,refresh:false});
jQuery("#list_history").jqGrid('navButtonAdd','#pager_history',{
caption: "Insertar",
buttonicon :'ui-icon-plus',
onClickButton : function (){
addRecord();
}
});
jQuery("#list_history").jqGrid('navButtonAdd','#pager_history',{
caption: "Borrar",
buttonicon :'ui-icon-trash',
onClickButton : function (){
deleteRecord();
}
});
}
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 "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");
break;
}
}
});
return false;
}
</script>
<form id="form_data_history" onsubmit="return send();">
<input type="hidden" id="action" name="action"/>
<input type="hidden" id="id_laptop" name="id_laptop"/>
<div style="text-align:center;">
<b>Marca / Modelo:</b>&nbsp;<span id="id_trademark"></span>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
<b>Número Serie:</b>&nbsp;<span id="serial_number"></span>
</div>
<br><br>
<div>
<div id="table_history" class="centerGrid">
<table width="100%" align="center">
<tr>
<td style="width:2%"></td>
<td style="text-align:center;"><table id="list_history" width="100%"></table></td>
<td style="width:2%"></td>
</tr>
</table>
<div id="pager_history" style=""></div>
<div id="filter_history" style="margin-left:30%;display:none">Buscar nada</div>
</div>
</div>
<div id="message" style="text-align:center; font-weight:bold; color:red; padding:3px; "></div>
<div style="text-align:center;"><button type="button" id="cancelButton" style="width:100px;">Cerrar</button></div>
</form>
controlies/trunk/applications/controlies/views/laptops/index.html
deleteRecord();
}
});
jQuery("#list").jqGrid('navButtonAdd','#pager',{
caption: "Historial",
buttonicon :'ui-icon-clock',
onClickButton : function (){
history();
}
});
jQuery("#list").jqGrid('filterToolbar');
......
getAllLaptopTypes();
jQuery("#form_data #action").val("modify");
jQuery("#form_data #user").attr("readonly","true");
jQuery("#form_data #user").css("background-color","#DDD");
jQuery("#form_data #messageForm").html("Todos los campos son obligatorios");
jQuery.post('call/json/getLaptopData',{ id_laptop: id }, function(result) {
......
}).dialog('open');
}
function history(){
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_history.html", function() {
jQuery("#form_data_history #id_laptop").val(id);
print_grid_historical();
jQuery("#form_data_history #action").val("modify");
jQuery.post('call/json/getLaptopData',{ id_laptop: id }, function(result) {
jQuery("#form_data_history #id_laptop").val(result.response['id_laptop']);
jQuery("#form_data_history #serial_number").html(result.response['serial_number']);
jQuery("#form_data_history #id_trademark").html(result.response['id_trademark']);
x = (jQuery(window).width()-850)/2;
y = (jQuery(window).height()-500)/2;
jQuery("#messageLoading").hide();
jQuery("#dialog-form").dialog({
resizable: false,
modal: true,
width: 850,
title: "Historial Portátil"
}).dialog('option', 'position', [x, y]);
});
});
}
function getAllLaptopTypes(){
$.post("/controlies/laptops/call/json/getAllLaptopTypes", function(result) {
$.each( result.response, function(i, l){
......
</script>
<script type="text/javascript">
jQuery(document).ready(function(){ print_grid();});
jQuery(document).ready(function(){ print_grid();});
</script>
controlies/trunk/applications/controlies/controllers/laptops.py
response = l.process(request.vars["action"])
return dict(response = response)
@service.json
@auth.requires_login()
def listHistorical():
my = SQLiteConnection()
l = Laptops(my,"","","")
response = l.listHistorical(request.vars)
return response
def laptops():
return dict()
def form_history():
return dict()
def form():
return dict()
controlies/trunk/applications/controlies/modules/Laptops.py
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']
print sql
result = db.executesql(sql)
print result[0]
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+"')"
......
db = self.SQLite.getDB()
result = db.executesql(sql)
print result
dataLaptop = {
"id_laptop":str(result[0][0]),
"serial_number":result[0][1],

Exportar a: Unified diff