/*
	Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dojox.grid.enhanced.plugins.Menu"]){
dojo._hasResource["dojox.grid.enhanced.plugins.Menu"]=true;
dojo.provide("dojox.grid.enhanced.plugins.Menu");
dojo.require("dojox.grid.enhanced.plugins._Mixin");
dojo.declare("dojox.grid.enhanced.plugins.Menu",dojox.grid.enhanced.plugins._Mixin,{constructor:function(_1){
_1.mixin(_1,this);
},_initMenus:function(){
var _2=this.menuContainer;
!this.headerMenu&&(this.headerMenu=this._getMenuWidget(this.menus["headerMenu"]));
!this.rowMenu&&(this.rowMenu=this._getMenuWidget(this.menus["rowMenu"]));
!this.cellMenu&&(this.cellMenu=this._getMenuWidget(this.menus["cellMenu"]));
!this.selectedRegionMenu&&(this.selectedRegionMenu=this._getMenuWidget(this.menus["selectedRegionMenu"]));
this.headerMenu&&this.set("headerMenu",this.headerMenu)&&this.setupHeaderMenu();
this.rowMenu&&this.set("rowMenu",this.rowMenu);
this.cellMenu&&this.set("cellMenu",this.cellMenu);
this.isDndSelectEnable&&this.selectedRegionMenu&&this.connect(this.select,"setDrugCoverDivs",this._bindDnDSelectEvent);
},_getMenuWidget:function(_3){
if(!_3){
return;
}
var _4=dijit.byId(_3);
if(!_4){
console.warn("Menu '"+_3+"' not existed");
}
return _4;
},_bindDnDSelectEvent:function(){
dojo.forEach(this.select.coverDIVs,dojo.hitch(this,function(_5){
this.selectedRegionMenu.bindDomNode(_5);
this.connect(_5,"contextmenu",function(e){
dojo.mixin(e,this.select.getSelectedRegionInfo());
this.onSelectedRegionContextMenu(e);
});
}));
},_setRowMenuAttr:function(_6){
this._setRowCellMenuAttr(_6,"rowMenu");
},_setCellMenuAttr:function(_7){
this._setRowCellMenuAttr(_7,"cellMenu");
},_setRowCellMenuAttr:function(_8,_9){
if(!_8){
return;
}
if(this[_9]){
this[_9].unBindDomNode(this.domNode);
}
this[_9]=_8;
this[_9].bindDomNode(this.domNode);
},showRowCellMenu:function(e){
var _a=e.sourceView.declaredClass=="dojox.grid._RowSelector";
if(this.rowMenu&&(!e.cell||this.selection.isSelected(e.rowIndex))){
this.rowMenu._openMyself({target:e.target,coords:"pageX" in e?{x:e.pageX,y:e.pageY}:null});
dojo.stopEvent(e);
return;
}
if(_a||e.cell&&e.cell.isRowSelector){
dojo.stopEvent(e);
return;
}
if(this.isDndSelectEnable){
this.select.cellClick(e.cellIndex,e.rowIndex);
this.focus.setFocusCell(e.cell,e.rowIndex);
}
if(this.cellMenu){
this.cellMenu._openMyself({target:e.target,coords:"pageX" in e?{x:e.pageX,y:e.pageY}:null});
}
},destroy:function(){
this.rowMenu&&this.rowMenu.unBindDomNode(this.domNode);
this.cellMenu&&this.cellMenu.unBindDomNode(this.domNode);
this.selectedRegionMenu&&this.selectedRegionMenu.destroy();
this.inherited(arguments);
}});
}
