<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("deleteDistributer",  "function deleteDistributer(id){
    var r = confirm('Are you sure to delete this?');
        if(r==true)
        {
            jQuery.ajax({
              'type'  : 'post',
              'data'  : 'id=' + id,
              'url'  : $('#liveSite').val()+'index.php?r=Distributer/delete',
              'cache': false,
              'success':function(data){
                if(data=='fail'){
                    t8.error('Error while Delete');
                }else {
                    reloadTable('#tbl_distributer_details');
                   t8.success('Distributer Deleted SuccessFully');
                }
               }
            });
        }

   
};", CClientScript::POS_HEAD);
$cs = Yii::app()->getClientScript();
$baseUrl = Yii::app()->baseUrl;

    $cs->registerScript("load", '

        $(document).ready(function() {



        var table_id ="#tbl_distributer_details";

        var table = $(table_id).on("preXhr.dt", function (e, settings, data) {

        data.distributer_id = $("#distributer_id").val();

        return data;

        }).DataTable({

            scrollY         : "380px",

           // scrollX         : "true",

           // scrollCollapse  : true,

            pageLength      : 50,

			processing: true,

            order:  [["1", "desc"]],
            ajax: {

                url: "' . Yii::app()->createUrl('Distributer/GetList') . '",

                type: "POST",

                cache : false,

                "data": function ( params ) {

                    params.YII_CSRF_TOKEN = "'.Yii::app()->request->csrfToken.'";

                }

            },

            serverSide:     true,

            fixedColumns:   true,

			processing: true,

            fixedHeader: {

                headerOffset: $("header.main").outerHeight()

            }

        } );

        $(".dataTables_scrollFoot").hide();

    });', CClientScript::POS_HEAD);
    ?>
    <section class="panel">
        <header class="panel-heading clearfix panel-theame">
            <i class="fa fa-tasks"></i> Distributor   
            <div class="pull-right">
                <?php  if (isset(Yii::app()->user->havePermissionOn['master_distributer_add']) ||  Yii::app()->user->authorised_user == 1) {?>

                <button class="btn btn-sm btn-theme" onclick="loadPopupModal('distributer/create','Add New Distributor','lg')"><i class="fa fa-plus"></i> ADD</button>
                <?php } ?>
            </div>
              <div class=" col-sm-2 pull-right">
            <?php echo CHtml::dropdownList('distributer_id', '', Distributers::getDistributers(), array('data-label' => 'Distributor Type', 'class' => 'form-control', 'onChange' => 'reloadTable("#tbl_distributer_details")', 'empty' => 'Distributor', 'data-search' => true)); ?>    
        </div>
        </header>
        <div class="panel-body">
            <div class="custom-data-table">
                <table class="table table-hover table-bordered personal-task" id="tbl_distributer_details">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th class="nw">Type</th>
                            <th class="nw">Name</th>
                            <th>Alias1</th>
                            <th>Alias2</th>
                            <th>Alias3</th>
                            <th>Area Price</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>No</th>
                            <th>Type</th>
                            <th>Name</th>
                            <th>Alias1</th>
                            <th>Alias2</th>
                            <th>Alias3</th>
                            <th>Area Price</th>
                            <th>Actions</th>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </section>
