可编辑树extjs

Ext.ns("htsoft.ux");
/**
 * @company 宏天软件有限公司
 * @createtime 2010-01-02
 * @author csx
 * @class TreePanelEditor
 * @extends Ext.tree.TreePanel
 * @description 树菜单编辑器,可带右键操作菜单,使用方式示例见ArchiveTypeTempView.js
 */
htsoft.ux.TreePanelEditor=Ext.extend(Ext.tree.TreePanel,{
	showContextMenu:true,
	url:null,
	/**
	 * 右键菜单
	 * @type 
	 */
	contextMenu:null,
	/**
	 * 右键菜单项
	 * @type 
	 */
	contextMenuItems:null,
	/**
	 * 选择树节点
	 * @type 
	 */
	selectedNode:null,
	/**
	 * 构造函数
	 */
	constructor:function(_cfg){
		if(_cfg==null){
			_cfg={};
		}
		Ext.apply(this,_cfg);
		//从父类中拷贝构造
		htsoft.ux.TreePanelEditor.superclass.constructor.call(this,{
			tbar:new Ext.Toolbar({items:[
								{
									xtype : 'button',
									iconCls : 'btn-refresh',
									text : '刷新',
									handler : function() {
										Ext.getCmp(_cfg.id).root.reload();
									}
								},{
									xtype : 'button',
									text : '展开',
									iconCls : 'btn-expand',
									handler : function() {
										Ext.getCmp(_cfg.id).expandAll();
									}
								}, {
									xtype : 'button',
									text : '收起',
									iconCls : 'btn-collapse',
									handler : function() {
										Ext.getCmp(_cfg.id).collapseAll();
									}
								}
			]}),
			loader : new Ext.tree.TreeLoader({
					url:this.url
			}),
			root : new Ext.tree.AsyncTreeNode({
				    expanded : true
			}),
			rootVisible : false
		});
		
		//初始化右键的菜单
		this.initContextMenu();
		
	},//end of constructor
	
//	initComponent: function(){
//		htsoft.ux.TreePanelEditor.superclass.initComponent.call(this);		
//	},

	/**
	 * 右键菜单
	 */
	initContextMenu:function(){
		if(this.showContextMenu){
			this.contextMenu= new Ext.menu.Menu({});
			if(this.contextMenuItems!=null){
				this.contextMenu.add(this.contextMenuItems);
			}
			//树的右键菜单的
			this.on('contextmenu', this.contextHandler, this);
		}
	},
	contextHandler:function contextmenu(node, e) {
		this.selectedNode = new Ext.tree.TreeNode({
					id : node.id,
					text : node.text
		});
		this.contextMenu.showAt(e.getXY());
	}
});
Ext.reg("treePanelEditor",htsoft.ux.TreePanelEditor);
{
			xtype:'treePanelEditor',
			id:'archivesTypeTree',
			region : 'west',
			title:'公文分类',
			collapsible : true,
			split : true,
			width:200,
			url:__ctxPath+'/archive/treeArchivesType.do',
			contextMenuItems:[
						{
							text : '新建分类',
							scope : this,
							iconCls:'btn-add',
							handler : function(){
								new ArchivesTypeForm().show();
							}
						}, {
							text : '修改分类',
							scope : this,
							iconCls:'btn-edit',
							handler: function(){
								new ArchivesTypeForm({typeId:Ext.getCmp('archivesTypeTree').selectedNode.id}).show();
							}
						},{
							text : '删除分类',
							scope : this,
							iconCls:'btn-delete',
							handler : function(){
								var typeId=Ext.getCmp('archivesTypeTree').selectedNode.id;
								Ext.Ajax.request({
									url:__ctxPath+'/archive/multiDelArchivesType.do',
									params:{ids:typeId},
									method:'POST',
									success:function(response,options){
										Ext.ux.Toast.msg('操作信息','成功删除该公文分类!');
										Ext.getCmp('archivesTypeTree').root.reload();
									},
									failure:function(response,options){
										Ext.ux.Toast.msg('操作信息','操作出错,请联系管理员!');
									}
								});
							}
						}
			]
	}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值