显示在适当的按钮

时间:2017-04-20 09:02:57

标签: javascript jquery kendo-ui kendo-grid

面临Kendo Grid的问题, 我有4个自定义按钮 1.submit 2.approve 3.reject 4.cancel 和2是默认功能 1.edit 2.更新

这里隐藏和显示基于状态的按钮

function HideEditButton()
    {
    var TravelPlanid = window.parent.Xrm.Page.data.entity.getId();
     TravelPlanid = TravelPlanid.replace(/\{|\}/gi, '');
     var CreatedBy = null;
     if ( window.parent.Xrm.Page.getAttribute("createdby")!=null && window.parent.Xrm.Page.getAttribute("createdby")!=undefined)
     {
         CreatedBy = window.parent.Xrm.Page.getAttribute("createdby").getValue()[0].id;
         CreatedBy = CreatedBy.replace(/\{|\}/gi, '');
     }

     var userId = Xrm.Page.context.getUserId();
    var userId = userId.replace(/\{|\}/gi, '');


     var grid = jQuery("#subdiv1").data("kendoGrid");
    var gridData = grid.dataSource.view();

        for (var i = 0; i < gridData.length; i++) {
            var currentUid = gridData[i].uid;
            console.log(i + ' ' + gridData[i].RecordType);

            if (gridData[i].pcl_travelplanactivitystatus.value == 798330003)
            {
                console.log("Model: " + i + ' ' + gridData[i].RecordType + " UID:" + currentUid);
                 var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                var submitButton = jQuery(currenRow).find(".k-grid-Submit");
                var editButton = jQuery(currenRow).find(".k-grid-edit");
                var deleteButton = jQuery(currenRow).find(".k-grid-delete");
                console.log(submitButton);
                console.log(editButton);
                console.log(deleteButton);
                deleteButton.hide();
                submitButton.hide();
                editButton.hide();
            }
            if (gridData[i].pcl_travelplanactivitystatus.value == 798330003 && CreatedBy == userId)
            {
                console.log("Model: " + i + ' ' + gridData[i].RecordType + " UID:" + currentUid);
                 var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                var approveButton = jQuery(currenRow).find(".k-grid-Approve");
                var rejectButton = jQuery(currenRow).find(".k-grid-Reject");
                console.log(approveButton);
                console.log(rejectButton);
                approveButton.hide();
                rejectButton.hide();
            }
            else if (gridData[i].pcl_travelplanactivitystatus.value == 798330000)
            {
                console.log("Model: " + i + ' ' + gridData[i].RecordType + " UID:" + currentUid);
                var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                var approveButton = jQuery(currenRow).find(".k-grid-Approve");
                var editButton = jQuery(currenRow).find(".k-grid-edit");
                var submitButton = jQuery(currenRow).find(".k-grid-Submit");
                var rejectButton = jQuery(currenRow).find(".k-grid-Reject");
                var deleteButton = jQuery(currenRow).find(".k-grid-delete");
                console.log(approveButton);
                console.log(deleteButton);
                console.log(editButton);
                console.log(rejectButton);
                approveButton.hide();
                editButton.hide();
                deleteButton.hide();
                submitButton.hide();
                rejectButton.hide();
            }

            else if (gridData[i].pcl_travelplanactivitystatus.value == 798330005 && CreatedBy != userId)
            {
                console.log("Model: " + i + ' ' + gridData[i].RecordType + " UID:" + currentUid);
                var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                var approveButton = jQuery(currenRow).find(".k-grid-Approve");
                var editButton = jQuery(currenRow).find(".k-grid-edit");
                var submitButton = jQuery(currenRow).find(".k-grid-Submit");
                var rejectButton = jQuery(currenRow).find(".k-grid-Reject");
                var deleteButton = jQuery(currenRow).find(".k-grid-delete");
                console.log(approveButton);
                console.log(deleteButton);
                console.log(editButton);
                console.log(rejectButton);
                approveButton.hide();
                editButton.hide();
                deleteButton.hide();
                submitButton.hide();
                rejectButton.hide();
            }
            else if (gridData[i].pcl_travelplanactivitystatus.value == 798330005 && CreatedBy == userId)
            {
                console.log("Model: " + i + ' ' + gridData[i].RecordType + " UID:" + currentUid);
                var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                var approveButton = jQuery(currenRow).find(".k-grid-Approve");
                var rejectButton = jQuery(currenRow).find(".k-grid-Reject");
                console.log(approveButton);
                console.log(rejectButton);
                approveButton.hide();
                rejectButton.hide();
            }
            else if (gridData[i].pcl_travelplanactivitystatus.value == 798330004)
            {
                console.log("Model: " + i + ' ' + gridData[i].RecordType + " UID:" + currentUid);
                var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                var approveButton = jQuery(currenRow).find(".k-grid-Approve");
                var editButton = jQuery(currenRow).find(".k-grid-edit");
                var submitButton = jQuery(currenRow).find(".k-grid-Submit");
                var rejectButton = jQuery(currenRow).find(".k-grid-Reject");
                var deleteButton = jQuery(currenRow).find(".k-grid-delete");
                console.log(approveButton);
                console.log(deleteButton);
                console.log(editButton);
                console.log(rejectButton);
                approveButton.hide();
                editButton.hide();
                deleteButton.hide();
                submitButton.hide();
                rejectButton.hide();
            }
            else if (gridData[i].pcl_travelplanactivitystatus.value == 1)
            {
                console.log("Model: " + i + ' ' + gridData[i].RecordType + " UID:" + currentUid);
                 var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                var submitButton = jQuery(currenRow).find(".k-grid-Submit");
                var editButton = jQuery(currenRow).find(".k-grid-edit");
                var deleteButton = jQuery(currenRow).find(".k-grid-delete");
                console.log(submitButton);
                console.log(editButton);
                console.log(deleteButton);
                deleteButton.hide();
                submitButton.hide();
                editButton.hide();
            }
            else if (gridData[i].pcl_travelplanactivitystatus.value == 798330002 && CreatedBy == userId)
            {
                console.log("Model: " + i + ' ' + gridData[i].RecordType + " UID:" + currentUid);
                var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                var approveButton = jQuery(currenRow).find(".k-grid-Approve");
                var editButton = jQuery(currenRow).find(".k-grid-edit");
                var submitButton = jQuery(currenRow).find(".k-grid-Submit");
                var rejectButton = jQuery(currenRow).find(".k-grid-Reject");
                var deleteButton = jQuery(currenRow).find(".k-grid-delete");
                console.log(approveButton);
                console.log(deleteButton);
                console.log(editButton);
                console.log(rejectButton);
                approveButton.hide();
                editButton.hide();
                deleteButton.hide();
                submitButton.hide();
                rejectButton.hide();
            }
             else  if (gridData[i].pcl_travelplanactivitystatus.value == 798330002 && CreatedBy != userId)
            {
            debugger;
                console.log("Model: " + i + ' ' + gridData[i].RecordType + " UID:" + currentUid);
                var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                var approveButton = jQuery(currenRow).find(".k-grid-Approve");
                var submitButton = jQuery(currenRow).find(".k-grid-Submit");
                var rejectButton = jQuery(currenRow).find(".k-grid-Reject");
                var deleteButton = jQuery(currenRow).find(".k-grid-Delete");
                console.log(approveButton);
                console.log(submitButton);
                console.log(rejectButton);
                console.log(deleteButton);
                deleteButton.hide();
                approveButton.hide();
                submitButton.hide();
                rejectButton.hide();
             }
             else  if (gridData[i].pcl_travelplanactivitystatus.value == 798330002 && CreatedBy != userId && gridData[i].pcl_managerremarks.value != null)
            {
            console.log("Model: " + i + ' ' + gridData[i].RecordType + " UID:" + currentUid);
                var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
                var editButton = jQuery(currenRow).find(".k-grid-edit");
                console.log(editButton);
                editButton.hide();
             }



        }

    }

这里我的问题是,如果我点击编辑按钮,我可以编辑行记录,但如果我没有更改记录值,我点击更新按钮,然后所有按钮显示

0 个答案:

没有答案