<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("DisableExpenseType", "
function Disable(id, status){
    var r = confirm((status == 'Y') ? 'Are you sure to disable this?' : 'Are you sure to enable this?');
    if(r==true)
    {
        jQuery.ajax({
          type  : 'post',
          datatype : 'json',
          data  : 'id=' + id + '&status=' + status,
          url  : $('#liveSite').val()+'index.php?r=projects/Disable',
          cache: false,
          success:function(data){
            if(data.status=='fail'){
                t8.error('Error while Disable');
            } else {
                reloadTable('#tbl_projects');
                t8.success('Success!');
            }
           }
        });
    }
};
", CClientScript::POS_HEAD);
?>

<script>
$(document).ready(function () {

    var table_id = "#tbl_projects";

    var table = $(table_id).DataTable({

        scrollY: "645px",
        pageLength: 50,
        processing: true,
        serverSide: true,
        fixedColumns: true,

        ajax: {
            url: "<?php echo Yii::app()->createUrl('/projects/GetList') ?>",
            type: "POST",
            cache: false
        },

        fnCreatedRow: function (nRow) {
            $(nRow).addClass("context-menu");
        },

        fnRowCallback: function (nRow, aData) {

            $(nRow).removeClass('bg-success bg-danger');

            if (aData[5].status === "N") { 
                $(nRow).addClass('bg-danger'); 
            }

            AddContextMenu(nRow, aData);
        }
    });
});

/* Context Menu */
function AddContextMenu(row, datas) {

    $(row).contextMenu({
        selector: 'td',

        items: {

            "edit": {
                name: "Edit",
                icon: "edit",
                callback: function () {
                    loadPopupModal(
                        "projects/create&id=" + datas[5].id,
                        datas[5].code,
                        "lg"
                    );
                }
            },

            "Disable_Enable": {
                name: (datas[5].status == "Y") ? "Disable" : "Enable",
                icon: "edit",
                callback: function () {
                    Disable(datas[5].id, datas[5].status);
                }
            }
        }
    });
}
</script>

<section class="panel">
    <header class="panel-heading clearfix panel-theame">
        <i class="fa fa-list"></i> Projects

        <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('projects/create','Add Projects','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('masexpensetype/create', 'Add New Expense Type', '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_projects" style="font-size:13px;">
                <thead>
                    <tr>
                        <th>SI No</th>
                        <th>Project Name</th>
                        <th>Ftp Address</th>
						<th>Ftp Username</th>
						<th>Ftp Port</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</section>
