Gef.ns('Gef.org'); Gef.org.CheckboxTreeNodeUI = Ext.extend(Ext.tree.CheckboxNodeUI, { checkParent: Ext.emptyFn, checkChild: Ext.emptyFn }); Gef.org.OrgField = Ext.extend(Ext.form.TriggerField, { triggerClass : "x-form-search-trigger", initComponent: function() { this.readOnly = false; Gef.org.OrgField.superclass.initComponent.call(this); this.addEvents('select'); }, onTriggerClick: function() { this.showWindow(); }, /* getStore:function(){ // 此方法 似乎没有用…… Ext.Ajax.request({//拿到tree数据 url:basePath+'common/getOrgAssignees.action', method:'post', success: function(response){ res = new Ext.decode(response.responseText); if(res.tree){ store = new Ext.decode(res.tree); Ext.getCmp('orgfield').showWindow(store); } } }); },*/ showWindow: function(store) { var me = this; var requestUrl = ''; if(me.name=='assignee'||me.name=='notifyPeople'){ console.log(basePath); requestUrl = basePath+'common/getOrgAssignees.action'; }else{ requestUrl = basePath+'common/getJobOfOrg.action'; } Ext.Ajax.request({//拿到tree数据 url:requestUrl, method:'post', success: function(response){ res = new Ext.decode(response.responseText); if(res.tree){ store = new Ext.decode(res.tree); var window=me.getWindow(store); window.show(); var value =window.field.value; var array = value.split(','); me.orgTree.cleanCheck(); me.orgTree.setChecked(array); window.items.items[0].form.items.items[3].setValue(me.orgTree.getChecked()); } } }); Gef.activeEditor.disable(); }, hideWindow: function() { this.getWindow().hide(); Gef.activeEditor.enable(); }, getWindow: function(store) { if (!this.orgWindow) { this.orgWindow = this.createWindow(store); } return this.orgWindow; }, createWindow: function(store) { var me = this; var selectedValues = []; if(this.value.indexOf(',')>0){ selectedValues = this.value.split(','); } var tree = new Ext.tree.TreePanel({ autoScroll: true, loader: new Ext.tree.CustomUITreeLoader({ baseAttr: { uiProvider: Gef.org.CheckboxTreeNodeUI } }), width:300, region:'center', enableDD: false, containerScroll: true, rootUIProvider: Gef.org.CheckboxTreeNodeUI, selModel: new Ext.tree.CheckNodeMultiSelectionModel(), rootVisible: false, count:1, // 这一行 是为了联合控制 click事件 加上去的,不属于树本身的属性: listeners:{ 'dbclick':function(){ root = this.getRootNode(); var childrens = root.childNodes; for(var i=0;i= 0; i--) { var n = this.getNodeById(array[i]); if (n && !n.getUI().checked()) { n.getUI().check(); } } }; this.orgTree = tree; //加筛选 根据 所属组织 人员名称 以及编号 做筛选 var formpanel=new Ext.form.FormPanel({ height:100, region:'west', width:'30%', labelWidth: 70, labelAlign: 'right', border: false, defaultType: 'textfield', defaults: { anchor: '90%' }, bodyStyle: { padding: '6px 0 0' }, items:[{ xtype:'textfield', name:'orname', fieldLabel:'所属组织', },{ xtype:'textfield', name:'name', fieldLabel:'员工名称' },{ xtype:'textfield', name:'code', fieldLabel:'员工编号' },{ xtype: 'textarea', name:'selected', fieldLabel:'已选择' }], buttonAlign:'center', buttons:[{ text:'筛选', iconCls:'x-form-search-trigger', style:'padding-bottom:150px', handler:function(){ var condition=me.getCondition(win); if(condition){ var requestUrl = ''; if(me.name=='assignee'||me.name=='notifyPeople'){ requestUrl = basePath+'common/getOrgAssignees.action'; }else{ requestUrl = basePath+'common/getJobOfOrg.action'; } Ext.Ajax.request({//拿到tree数据 url:requestUrl, params:{ condition:condition }, method:'post', success: function(response){ res = new Ext.decode(response.responseText); if(res.tree){ var cstore = new Ext.decode(res.tree); var hisroot=tree.getRootNode(); var cn = hisroot.childNodes, n; while ((n = cn[0])) { hisroot.removeChild(n); } var fn = function(node, ch) { for(var i in ch) { var n = ch[i]; if(n.text){ node.appendChild(new Ext.tree.AsyncTreeNode({ text: n.text, draggable: false, leaf:false, children:n.children })); } } }; fn(hisroot, cstore); tree.expandAll(); var value =win.field.value; var array = value.split(','); tree.cleanCheck(); tree.setChecked(array); } } }); } } }] }); var win = new Ext.Window({ title: '人事', layout: 'border', height:window.innerHeight*0.9, width: 600, closeAction: 'hide', modal: true, items: [formpanel,tree], buttons: [ { text: '确定', handler: this.submit, scope: this }, { text: '取消', handler: this.hideWindow, scope: this }, { text: '刷新', handler: function() { tree.root.reload(); }, scope: this }], listeners:{ 'beforehide':function(c){ Gef.activeEditor.existWin=false; Gef.activeEditor.enable(); }, 'beforeshow':function(c){ Gef.activeEditor.existWin=true; Gef.activeEditor.disable(); } } }); win.field = this; return win; }, submit: function() { /* var value =this.orgWindow.items.items[0].form.items.items[3].getValue(); var arr=null; if(!value){ value=''; }else { arr=value.split(","); } */ var value=''; var array = this.orgTree.getChecked(); for (var i = 0; i < array.length; i++) { value +=array[i]+','; } value=value.substring(0,value.length-1); this.setValue(value); this.hideWindow(); this.fireEvent('select', this); }, selectOwner: function() { this.setValue("项目发起人"); this.hideWindow(); this.fireEvent('select', this); }, refreshTree: function() { }, getCondition:function(win){ var form=win.items.items[0].form; var values=form.getValues(); var orname=values.orname; var name=values.name; var code=values.code; var condition=""; if((!orname && !name && !code)|| (orname=="" && name=="" && code=="")){ return null; }else { condition+=(orname==null || orname=="")?"1=1 #" :" or_name like '%"+orname+"%' #"; condition+=(name==null || name=="")?"1=1 " :" em_name like '%"+name+"%'"; condition+=(code==null || code=="")?" " :" and em_code like '%"+code+"%'"; return condition; } } }); Ext.reg('orgfield', Gef.org.OrgField);