<?php require_once(APPPATH.'/views/header.php'); ?>
<body>
    <div id="wrapper">
    <?php require_once(APPPATH.'/views/menu_user.php'); ?>
        <div id="page-wrapper">
            <div class="container-fluid">
                <fieldset class="admin-border">
                    <fieldset class="scheduler-border">
                    <legend class="scheduler-border"><?php echo $title;?></legend>
                        <div class="row">
                            <div class="col-lg-3 col-md-6 col-sm-8 col-xs-12">
                                <label>Scaneaza codul (*)</label><br />
                                <input class="form-control" type="number" id="cod"  name="cod" placeholder="Cod">
                            </div>
                            <div class="clearfix"></div><br/>
                            <div class="col-lg-3 col-md-6 col-sm-8 col-xs-12">
                                <div id="info_doc"></div>
                            </div>
                            </div>
                            <br/>
                            <div>
                                <table class="table table-condensed" id="list"></table>
                                <div id="gridpager"></div> 
                                <div id="filterToolbar"></div>     
                            </div>
                        </div>
                    <br/>
                    </fieldset>
                </fieldset>
            </div>
        </div>
        <!-- /#page-wrapper -->
    </div>
    <div id="gif" class="modal fade loading-gif">
        <div class="modal-dialog">
            <div>
                <img src="<?=base_url()?>img/loading.gif">
            </div>
        </div>
    </div>
    <!-- /#wrapper -->
<?php require_once(APPPATH.'/views/footer.php'); ?> 
<script>
            
        $(document).ready(function(){

            jQuery("#list").jqGrid({
                  url:'<?=base_url()."adm/scan/loadData"?>',      //another controller function for generating data
                  mtype : "post",             //Ajax request type. It also could be GET
                  datatype: "json",            //supported formats XML, JSON or Arrray
                  colNames:<?=(isset($colNames) && $colNames)? $colNames : '';?>,       //Grid column headings
                  colModel:<?=(isset($colModel) && $colModel)? $colModel : '';?>,
                  rowNum:30,
                  width: null,
                  shrinkToFit: true,
                  autowidth: true,
                  height: null,
                  rowList:[5,10,20,30],
                  pager: '#gridpager',
                  sortname: 'id_client_document',
                  viewrecords: true,
                  sortorder: 'DESC',
                  rownumbers: true,
                  gridview: true
              }).navGrid('#gridpager',{edit:false,add:false,del:false,excel:true})
              .navButtonAdd('#gridpager',{
                caption:"",
                title:"Search", 
                buttonicon:"ui-icon-search", 
                onClickButton: function(){ 
                    jQuery("#list").jqGrid('searchGrid', 
                        {sopt:['cn','eq','ne'],
                        multipleSearch:true}
                    );
                }, 
                
                position:"center"
             });

             jQuery("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn"});  
             $("#search_list").css('display','none');

            $("#cod").focus();

            $("#cod").change(function() {
                var cod = $("#cod").val();
                var c_data  =   {ajax:'1', cod:cod};
                            $.ajax({
                                url : "<?php echo base_url();?>adm/scan/check",
                                type:"POST",
                                data: c_data,
                                success: function(data, textStatus, jqXHR)
                                {
                                    $("#info_doc").html(data);
                                    jQuery("#list").setGridParam({url:'<?=base_url()."adm/scan/loadData/"?>'+cod});
                                    jQuery("#list").trigger("reloadGrid");
                                },
                                error: function (jqXHR, textStatus, errorThrown)
                                {  
                                }
                            });
            });


        });

</script>     
</body>
</html>