<script type="text/javascript">
    $(function(){
        jQuery("#lines").jqGrid({
            url:'<?= site_url() ?>partner/supplierpricelist/getsupplierpricelist',
            datatype: "json",
            mtype : "post",
            colNames:['ID','PRICELISTNAME','SUPPLIER','VALIDFROM','ACTIVE'],
            colModel:[
                {name:'ID',index:'ID', hidden:true,width:100,editable:true,editoptions:{readonly:true,size:10}},
                {name:'PRICELISTNAME',index:'PRICELISTNAME', width:100,editable:true,editoptions:{size:10}},
                {name:'SUPPLIER',index:'SUPPLIER', width:100,editable:true,editoptions:{size:10}},
                {name:'VALIDFROM',index:'VALIDFROM', width:100,align:'center',editable:true,editoptions:{size:10}},
                {name:'ACTIVE',index:'ACTIVE', width:100,align:'center', editable:true,editoptions:{size:10}}
            ],
            rowNum:15,
            rowList:[15,30,45],
            rownumbers: true,
            key: true,
            rownumWidth: 40,
            height: 'auto',
            width: 700,
            pager: '#pgtoolbar1',
            sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            multiselect: true,
            reloadAfterEdit: true,
            reloadAfterSubmit: true,
            beforeSelectRow: function(rowid, e)
            {
                jQuery("#lines").jqGrid('resetSelection');
                return(true);
            }
        });
        $("#add").click(function(){

            document.location.href="<?= site_url() ?>partner/supplierpricelist/addsupplierprice";
        });

        jQuery("#bedata").click( function() {

            var rowid = jQuery("#lines").jqGrid('getGridParam','selarrrow');
            if(rowid != 0){
                var selid = jQuery("#lines").jqGrid('getCell', rowid, 'ID');
                if(selid!=false){
                    document.location.href="<?= site_url() ?>partner/supplierpricelist/editsupplierprice/"+selid;
                }
            }
            else {

                $( "#dialog" ).dialog( "open" );
            }
        });
        $("#dedata").click(function(){
            var gr = jQuery("#lines").jqGrid('getGridParam','selarrrow');
            if( gr != 0){
                doIt=confirm('do you want to delete the selected tariff?');
                if(doIt){
                    var selid = jQuery("#lines").jqGrid('getCell', gr, 'ID');
                    document.location.href="<?= site_url() ?>partner/supplierpricelist/deletepricelist/"+selid;
                }
            }
            else {

                $( "#dialog" ).dialog( "open" );
            }
        });
    });

    $(document).ready(function() {
        $("button").button();
    });

</script>
<script>
    // increase the default animation speed to exaggerate the effect
    $.fx.speeds._default = 1000;
    $(function() {
        $( "#dialog" ).dialog({
            autoOpen: false,
            show: "blind",
            hide: "explode",buttons: {
                Ok: function() {
                    $( this ).dialog( "close" );
                }
            }

        });

    });
</script>



<div class="demo">

    <div id="dialog" title="Message">
        <p>Please select a row !</p>
    </div>

</div><!-- End demo -->
<div class="main content clearfix">
    <div class="page-heading">
        <h2>Supplier Price List</h2>
    </div>
    <!-- end page-heading -->

    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
        <tr>
            <th rowspan="3" class="sized"><img src="<?= site_url() ?>images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
            <th class="topleft"></th>
            <td id="tbl-border-top">&nbsp;</td>
            <th class="topright"></th>
            <th rowspan="3" class="sized"><img src="<?= site_url() ?>images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
        </tr>
        <tr>
            <td id="tbl-border-left"></td>
            <td>
                <!--  start content-table-inner ...................................................................... START -->
                <div id="content-table-inner">

                    <!--  start table-content  -->
                    <div id="table-content">
                        <?php
                        if ($this->session->flashdata('msgt') == 'E') {
                            echo '
				<div id="message-red">
				<table border="0" width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td class="red-left">' . $this->session->flashdata('msg') . '</td>
					<td class="red-right"><a class="close-red"><img src="' . site_url() . 'images/table/icon_close_red.gif"   alt="" /></a></td>
				</tr>
				</table>
				</div>
						';
                        }
                        if ($this->session->flashdata('msgt') == 'S') {
                            echo '
					<div id="message-green">
					<table border="0" width="100%" cellpadding="0" cellspacing="0">
					<tr>
						<td class="green-left">' . $this->session->flashdata('msg') . '</a></td>
						<td class="green-right"><a class="close-green"><img src="' . site_url() . 'images/table/icon_close_green.gif"   alt="" /></a></td>
					</tr>
					</table>
					</div>
					';
                        }
                        ?>
                        <!--  start product-table ..................................................................................... -->
                        <div id="toolbartop">
                            <span class="button-strip">
                                <button id="add" name="addtariff">New</button>
                                <button id="bedata" name="edittariff">Edit</button>
                                <button id="dedata" name="remtariff">Delete</button></span></div>

                        <table id="lines"></table>
                        <div id="pgtoolbar1"></div>
                        <!--  end content-table  -->

                        <div class="clear"></div>

                    </div>
                </div>
                <!--  end content-table-inner ............................................END  -->
            </td>
            <td id="tbl-border-right"></td>
        </tr>
        <tr>
            <th class="sized bottomleft"></th>
            <td id="tbl-border-bottom">&nbsp;</td>
            <th class="sized bottomright"></th>
        </tr>
    </table>
</div>

