<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("DisableItem", "
function Disable(id){
    var r = confirm('Are you sure?');
    if(r==true)
    {
        jQuery.ajax({
          type  : 'post',
          data  : 'id=' + id,
          url  : $('#liveSite').val()+'index.php?r=masitem/disable',
          success:function(){
                reloadTable('#tbl_Masitem');
           }
        });
    }
};
", CClientScript::POS_HEAD);
?>

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

    var table = $("#tbl_Masitem").DataTable({

        processing: true,
        serverSide: true,

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

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

        fnRowCallback: function (nRow, aData) {
            AddContextMenu(nRow, aData);
        }
    });
});

function AddContextMenu(row, datas) {

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

        items: {

            "edit": {
                name: "Edit",
                callback: function () {
                    loadPopupModal(
                        "masitem/create&id=" + datas[2].id,
                        "Edit Item",
                        "lg"
                    );
                }
            },

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

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

        <div class="pull-right">
             <a class="ad-btn" onclick="loadPopupModal('masitem/create','Add New Item','lg')">
                <i class="fa fa-plus"></i>
              </a>
        </div>
    </header>

    <div class="panel-body">
        <table class="table table-hover table-bordered"
               id="tbl_Masitem">
            <thead>
                <tr>
                    <th>SI No</th>
                    <th>Item Name</th>
                </tr>
            </thead>
        </table>
    </div>
</section>