/*****************右键按钮定义*********************/
var treeRightMenu = new Ext.menu.Menu({
id: 'theContextMenu',
items:[{
id:'policy_apply',
text:'策略应用',
iconCls:'connected_user'
},'-',
{
id:'veiw-all',
text:'查看',
iconCls:'bogus',
menu:[
{
id:'veiwNode',
text:'详情',
iconCls:'view'
},'-',{
id:'veiwUser',
text:'用户组',
iconCls:'un_connected_user'
}
]
},
{
id:'addNode',
text:'添加',
iconCls:'add',
menu:[
{
id:'addPerson',
text:'添加成员',
iconCls:'user-add'
},
{
id:'addGroup',
text:'添加部门',
iconCls:'add-group'
}
]
},'-',{
id:'delNode',
text:'删除',
iconCls:'remove'
},{
id:'modifNode',
text:'修改',
iconCls:'edit'
}
]
});
//树形菜单面板
var westPanel = new Ext.tree.TreePanel({
title:'组织结构图',
id:'tree-menu',
treeRightMenu:treeRightMenu, //声明右键菜单
animate:true,
region:'west',
width:300,
split: true,//添加分割线是否可以改变该panel的大小
minSize: 160,//设置拖动的最小拖动值
maxSize: 300,//设置拖动的最大拖动值
collapsible:true,//是否让panel能自动缩放
collapseMode:'mini',//在分割线处出现按钮
//contentEl:'tree-menu-div',
autoScroll:true,
enableDD:true,//是否支持拖拽效果
containerScroll: true,//是否支持滚动条
rootVisible:true,//是否显示跟节点
loader:new Ext.tree.TreeLoader({
dataUrl:'tree/tree_json.php'
}),
tools:[{
id:'refresh',
handler:function(){
var tree = Ext.getCmp('tree-menu');
tree.root.reload();
tree.expandAll();
}
}]
});
//菜单根节点
var root = new Ext.tree.AsyncTreeNode({
text:'根节点',
icon:'images/icon/org.gif',
draggable:false,
id:'tree-menu-root'
});
//给tree添加鼠标右键事件
westPanel.on('contextmenu',treeRightKeyAction,this);
//****开始绑定右键菜单事件*************
Ext.getCmp('addPerson').on('click',addPersonAction,this);
Ext.getCmp('addGroup').on('click',addGroupAction,this);
Ext.getCmp('delNode').on('click',delNodeAction,this);
Ext.getCmp('modifNode').on('click',modifNodeAction,this);
Ext.getCmp('veiwNode').on('click',veiwNodeAction,this);
Ext.getCmp('veiwUser').on('click',veiwUserAction,this);
Ext.getCmp('policy_apply').on('click',policyApplyAction,this);
;
/*************** 鼠标右键按钮事件 *************************************/
function treeRightKeyAction(node,e){
e.preventDefault();//阻止浏览器默认行为处理事件
node.select(); //节点选中
treeRightMenu.showAt(e.getXY()); //确定菜单显示位置
var selectedNode = westPanel.getSelectionModel().getSelectedNode();//得到选中的节点
//根据当前选中的节点判断是否屏蔽按钮。
var str_type = selectedNode.attributes.str_type;
//如果为根节点,则策略按钮不可用。
if(selectedNode.attributes.id=='tree-menu-root'){
Ext.getCmp('policy_apply').disable();
}else{
Ext.getCmp('policy_apply').enable();
}
//如果为用户,则用户组按钮不可用。
if(str_type=='person'){
Ext.getCmp('veiwUser').disable();
}else{
Ext.getCmp('veiwUser').enable();
dept_id = selectedNode.attributes.id;
}
}