<table id="jqGrid"></table>
<div id="jqGridPager"></div>

<script>
buscarRutaAsignada = function()
{
	findControl();
}
findControl = function ()
{
    strFormSerialize = $( 'form' ).serialize();
    relaodGrid( strFormSerialize );
}

relaodGrid = function( s_url_param )
{
    jQuery( '#jqGrid' ).jqGrid( 'clearGridData' );
    jQuery( '#jqGrid' ).jqGrid( 'setGridParam', { url: '<?=buildUrl( 'transporte/grid' )?>?' + s_url_param } );
    jQuery( '#jqGrid' ).trigger( 'reloadGrid' );
}

showView = function( IdRuta, IdRutaLinea, Tipo )
{
	var s_param_ajax = "IdRuta/" + IdRuta + "/IdRutaLinea/" + IdRutaLinea +"/Tipo/" + Tipo;
	$( '#myIframe3' ).attr( 'src', '<?=buildUrl( 'transporte/regAttention' )?>' + s_param_ajax );
    $( '#dialog3' ).dialog( 'open' );
}

closeWindow = function()
{
    $( '#dialog3' ).dialog( 'close' );
}
</script>

<script>
    var jqGridContent = $( "#jqGrid" );
    jqGridContent.jqGrid
    (
        {
            url         : 'nothing',
            mtype       : "POST",
            datatype    : "json",
            //editurl     : 'edicionData.php',                        
            colNames    : [ 'IdConcat', 'Doc No', 'Ruta No', 'Destino', 'Turno', 'Placa', 'Chofer', 'Guia', 'Estado', '' ],
            colModel    : 
                          [
                            { name: 'IdConcat',                 width: 0, align: 'center', hidden: true, hidedlg: false, editrules : { required: true }, key: true },
                            { name: 'RutaDocumento',            width: 90, align: 'center', editable: true, sortable:  false },
                            { name: 'RutaDocDespacho',          width: 90, align: 'center', editable: true, sortable:  false },
                              /*
                            {
                                name: 'RutaDocDespacho',          width: 90, align: 'center', editable: true, sortable: false,
                                formatter: function( cellvalue, options, rowObject )
                                {
                                    return  "<span style='color:blue;text-decoration: underline;cursor:pointer;' originalValue='" + cellvalue + "'>" + cellvalue + "</span>";
                                }
                            },
                              */
                            { name: 'RutaDetDir1',              width: 90, align: 'center', editable: true, sortable:  false },
                            { name: 'FechaHoraProgramada', width: 90, align: 'center', editable: true, sortable:  false },
                            { name: 'VehiculoDesc',             width: 90, align: 'center', editable: true, sortable:  false },
                            { name: 'ChoferDesc',               width: 90, align: 'center', editable: true, sortable: false },
                            { name: 'SerieNumeroGuia',          width: 90, align: 'center', editable: true, sortable: false },
                            { name: 'EstadoDesc',               width: 90, align: 'center', editable: true, sortable: false },
                            
                            { name: 'details', width: 25, sortable: false, search: false, align: 'center',
                                formatter:function()
                                {
                                	var o_Data = arguments[2];
                                    if( o_Data.RutaDetEstado == "<?=TR_RutaDetalleBN::ESTADO_ARRIBO?>" ) {
                                        return "<span style='cursor:pointer; margin: 0 auto;' class='ui-icon ui-icon-pencil' title='' onclick='showView( \"" + o_Data.IdRuta + "\", \"" + o_Data.IdRutaLinea + "\", \"2\" );'></span>"
                                    }
                                    return "";
                                }
                            }
                          ],
			viewrecords : true,
			height      : $( window ).height()-220, 
			width       : $( window ).width() - 17,
            //width       : 600,
            //autowidth   : true,
            sortable    : true,
            multiSort   : true,
            //width: null,
            shrinkToFit: false,
            emptyrecords: "No se Encontro registros",
            //height      : 480,
            rowNum      : 100,
            rownumbers  : true, // show row numbers
            //multiselect : true,//SELECCION MULTIPLE
            pager       : "#jqGridPager",
            //caption     : "Products / Category Primary Grid View"
            onCellSelect: function( rowid, iCol, cellcontent )
            {
            	if( iCol == 2 ) //Codigo del Item
                {
                    var a_ids = explode( "_", rowid );
                    console.log( arguments );
                    console.log( a_ids[0] );
            		showView( a_ids[0], a_ids[1], '1' );
                }
            },
            beforeSelectRow: function ( rowid, e ) 
            {
            }
        }
    );

    $( "#jqGrid" ).jqGrid( 'bindKeys' );

    $( window ).on
    (
        "resize",
        function ()
        {
            var newWidth = $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() - 20;
            if( newWidth <= 705 )
            {
                jqGridContent.jqGrid( "setGridWidth", newWidth, false );
            }
            else
            {
                jqGridContent.jqGrid( "setGridWidth", newWidth, true);
            }
        }
    );
    if( $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() <= 705 )
    {
        jqGridContent.jqGrid( "setGridWidth", $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() - 5, false );
        //jqGridContent.jqGrid( "setGridWidth", $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().height() - 270, false );
    }
    else
    {
        jqGridContent.jqGrid( "setGridWidth", $( "#jqGrid" ).closest( ".ui-jqgrid" ).parent().width() - 5, true);
    }
    setTimeout( "findControl();", 500 );
</script>
<?=crearFuentePopupIframe( array( "div_id"=>"dialog3", "iframe_id"=>"myIframe3", "popup_title"=>"Registrar Atencion", "modal"=>true ) )?>