Resource column - deselect of resource not working in 'onDeselect ' event

Discuss issues related to v5.x
Post Reply
User avatar
siddhd
Posts: 171
Joined: Fri Oct 21, 2016 3:29 pm
Location: Pune, INDIA

Resource column - deselect of resource not working in 'onDeselect ' event

Post by siddhd »

Hi,

I want to validate the assignment/resource deselection 'deselect' event of a checkbox, and if a certain condition occurs it should get deselect.

for that, I have overridden an 'onDeselect' function and on an Ajax callback response, we are deciding whether to deselect the resource or not.
but even the deselect event has fired, the resource is not getting unselected from Resource column.

will you please help with this.

File Name -Gnt.widget.AssignmentGrid

Code: Select all

  onDeselect : function (sm, rec) 
    {
    	var me =this;
    	var args=arguments;
    	 //me.callParent(args);
    	 
        var myHash = new Array();
        myHash['projectId'] =  rec.data.TaskId;
		myHash['assignTo']= rec.data.ResourceId;
		var url=ResourceUtil.fnBuildRequestString(null,myHash,null);
		
  		 Ext.Ajax.request
  		 ({
	            url: './gantt/services/load.do?URL=//gantt/htmlGanttChartTab.jsp?&action=isResourceDeletable&'+url,
	            success: function(response, opts)
	            {
	            	var data=Ext.decode(response.responseText).data;
	            	var message=data.msg;
	            	var result=data.result;
	            	var isAdmin=data.isAdmin;
	            	var wbsDeleteMsgTypeForUser=data.wbsDeleteMsgTypeForUser;
	            	var wbsDeleteMsgTypeForSuperUser=data.wbsDeleteMsgTypeForSuperUser;
	            	
	            	if(isAdmin)
	            	{
	            		if(wbsDeleteMsgTypeForSuperUser=="warning")
	            		{
	            			 Ext.Msg.confirm("Confirmation",message, function(btnText){
	    	                     if(btnText === "no")
	    	                     {
	    	                    	 return false;
	    	                     }
	    	                     else if(btnText === "yes")
	    	                     {
	    	                    	 rec.setUnits(0);	    	                    	    	                    	 
	    	                    	 me.fireEvent('deselect', me,  rec);
	    	                    	 me.callParent(args);
	    	                     }
	    	                 }, this);
	            		}
	            		else if(wbsDeleteMsgTypeForSuperUser=="error")
	            		{
	            			alert(message);
	            			 return false;
	            		}
	            	}
	            	else
	            	{
	            		if(wbsDeleteMsgTypeForUser=="warning")
	            		{
	            			 Ext.Msg.confirm("Confirmation",message, function(btnText){
	    	                     if(btnText === "no")
	    	                     {
	    	                    	 return false;
	    	                     }
	    	                     else if(btnText === "yes")
	    	                     {
	    	                    	 rec.setUnits(0);
	    	                    	 me.fireEvent('deselect', me,  rec);
                                         me.callParent(args);
	    	                     }
	    	                 }, this);
	            		}
	            		else if(wbsDeleteMsgTypeForUser=="error")
	            		{
	            			alert(message);
	            			 return false;
	            		}
	            	}
	            	
	            },
	            failure: function(response, opts) 
	            {
	            	console.log('server-side failure to validateResourceLoad' + response.status);
	            }
  		 });
  		 
  		// this.callParent(arguments);
        
    },
Attachments
Resource-deselection.png
Resource-deselection.png (49.94 KiB) Viewed 2262 times
Regards,
Siddh

User avatar
pmiklashevich
Core Developer
Core Developer
Posts: 2847
Joined: Fri Apr 01, 2016 11:08 am

Re: Resource column - deselect of resource not working in 'onDeselect ' event

Post by pmiklashevich »

Hello,

Gnt.widget.AssignmentGrid uses checkbox selection model. "deselect" fires when deselection has already happened. You need beforedeselect event. Return "false" tp prevent deselection. Here is a small sample code for you to start:

Code: Select all

Ext.define(null, {
    override : 'Gnt.widget.AssignmentGrid',

    initComponent : function (config) {
        this.callParent(arguments);

        this.getSelectionModel().on({
            beforedeselect : this.onBeforeDeselect,
            scope          : this
        });
    },

    onBeforeDeselect : function (selModel, record, index) {
        var me = this;

        if (!record.deselectionApproved) {

            me.mask('Process confirmation...');

            // Ajax request simulation...
            setTimeout(function(){
                me.unmask();
                var approved = true; // result from backend

                if (approved) {
                    Ext.toast('Deselection approved');
                    record.deselectionApproved = true;
                    selModel.deselect([record]);
                }
                else {
                    Ext.toast('Deselection forbidden');
                }
            }, 3000);

            return false;
        }

        delete record.deselectionApproved;
    }
});
Best,
Pavel
Pavel Miklashevich - Core Developer

Post Reply