<?php
$cs = Yii::app()->getClientScript();
    ?>
<script>
    $(document).ready(function () {
        var table_id = "#tbl_user_details";
        var table = $(table_id).on("preXhr.dt", function (e, settings, data) {
            return data;
        }).DataTable({
            scrollY: "645px",
            pageLength: 50,
            processing: true,
            ajax: {
                url: "<?php echo Yii::app()->createUrl('users/GetList') ?>",
                type: "POST",
                cache: false,
            },
            serverSide: true,
            fixedColumns: true,
            processing: true,
            "fnCreatedRow": function (nRow, aData, iDataIndex) {
                $(nRow).addClass("context-menu");
            },
            "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                AddContextMenu(nRow, aData);
            }
        });
    });
    function AddContextMenu(row, datas) {
        
        $(row).contextMenu({
            selector: 'td',

            items: {
                "edit": {
                    name: "Edit",
                    icon: "edit",
                    accesskey: "e",
                    callback: function () {
                        loadPopupModal("users/create&id=" + datas[4].id, datas[4].code, "lg");
                    }
                }
                

            }
        });
    }
</script>
    <section class="panel">
        <header class="panel-heading clearfix panel-theame">
            <i class="fa fa-users"></i> Users 
            <div class="pull-right"> 
                <?php
                  $user_id   = (int) Yii::app()->user->id;
                  $modeluser = User::model()->findByPk($user_id);
                  if ($modeluser->user_group_id == 1) {
                    ?>
                      <a class="ad-btn" onclick="loadPopupModal('users/create','Add New User','lg')">
                <svg width="30" height="30" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="pluss-ad">
                    <circle cx="12" cy="12" r="11" stroke="white" stroke-width="2" fill="none"></circle>
                    <line x1="12" y1="7" x2="12" y2="17" stroke="#5db5a4" stroke-width="2" stroke-linecap="round"></line>
                    <line x1="7" y1="12" x2="17" y2="12" stroke="#5db5a4" stroke-width="2" stroke-linecap="round"></line>
                </svg>
              </a>
          <!--      <button class="btn btn-sm btn-theme" 
                    onclick="loadPopupModal('users/create', 'Add New User', 'lg')">
                <i class="fa fa-plus"></i> ADD
            </button> -->
            <?php
            }
            ?>
             </div>
        </header>
        <div class="panel-body">
            <div class="custom-data-table">
                <table class="table table-hover table-bordered personal-task" id="tbl_user_details" style="font-size:13px;">
                    <thead>
                        <tr>
                            <th>SI No</th>
                            <th>Name</th>
                            <th>Username</th>
                            <th>Email</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </section>
