Ext.grid.ContextGroupingView = function(config){
    this.addEvents(
        /**
         * @event rowcheck
         * Fires when the checkbox is checked
         * @param {SelectionModel} this
         * @param {Number} rowIndex  The checked row index
         * @param {Ext.data.Record} r  The checked record
         */
        "groupcontextmenu"
    );
    Ext.grid.ContextGroupingView.superclass.constructor.call(this, config);
};

Ext.grid.ContextGroupingView = Ext.extend(Ext.grid.GroupingView, {

    // private
    renderUI : function(){
        Ext.grid.ContextGroupingView.superclass.renderUI.call(this);
        this.mainBody.on('contextmenu', this.groupContextMenu, this);
    },
    
    // private
    interceptMouse : function(e){
	    var hd = e.getTarget('.x-grid-group-hd', this.mainBody);
	    if (hd){
	        e.stopEvent();
	    	if (e.button === 0) {
		        this.toggleGroup(hd.parentNode);
	    	}
	    }
    },
    
    // private
    groupContextMenu : function(e){
	    var hd = e.getTarget('.x-grid-group-hd', this.mainBody);
	    if (hd){
        	var parts    = hd.parentNode.id.split("-");
        	var group_id = parts[parts.length-1];            	
        	this.fireEvent("groupcontextmenu", this.grid, group_id, e);
	    }
    }
}); 
