123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- 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'){
- requestUrl = basePath+'common/getOrgAssignees.action';
- }else{
- requestUrl = basePath+'common/getJobOfOrg.action';
- }
- Ext.Ajax.request({//拿到tree数据
- url:requestUrl,
- method:'post',
- timeout:60000,
- 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<childrens.length;i++){
- for(var j=0;j<childrens[i].childNodes.length;j++){
- if(childrens[i][j].attributes.qtip==me.value){
- childrens[i][j].ui.checkboxImg.className = 'x-tree-node-checkbox-all';
- childrens[i][j].attributes.checked = true;
- }
- }
- }
- },
- 'expandnode':function(node){
- if(!node.isLeaf()){
- var childrens = node.childNodes;
- for(var i=0;i<childrens.length;i++){
- if(childrens[i].isLeaf()){ // 传过来的 model.value(即之前保存过的值一定是 叶子节点额。)
- if(selectedValues.length<2){ // model.value 只选择了一个值
- if(childrens[i].attributes.qtip==me.value){
- childrens[i].ui.checkboxImg.className = 'x-tree-node-checkbox-all';
- childrens[i].attributes.checked = true;
- }
- }else{
- for(var j=0;j<selectedValues.length;j++){ //model.value 选择了多个值!
- if(childrens[i].attributes.qtip==selectedValues[j]){
- childrens[i].ui.checkboxImg.className = 'x-tree-node-checkbox-all';
- childrens[i].attributes.checked = true;
- }
-
- }
-
- }
-
- }
- }
- }
-
-
- }
-
- }
- });
- tree.getLoader().on('load', function(o, node) {
- if (node.isRoot) {
- tree.expandAll();
- }
- });
- var root = new Ext.tree.AsyncTreeNode({
- text: 'root',
- draggable: false,
- leaf:false,
- children:store,
- expanded:true
- });
- tree.setRootNode(root);
- tree.cleanCheck = function(node) {
- if (typeof node == 'undefined') {
- node = this.rootVisible ? this.getRootNode() : this.getRootNode().firstChild;
- }
- if (node) {
- if (!node.isLeaf()) {
- node.ui.checkboxImg.className = 'x-tree-node-checkbox-none';
- node.attributes.checked = false;
- for(var i = 0; i < node.childNodes.length; i++) {
- this.cleanCheck(node.childNodes[i]);
- }
- }
- }
- };
- tree.getChecked = function(node) {
- var checked = [], i;
- if (typeof node == 'undefined') {
- node = this.getRootNode();
- } else if (node.ui.checkboxImg && node.ui.checkboxImg.className == 'x-tree-node-checkbox-all' ) {
- if(node.isLeaf()){
- checked.push(node.text);
- } else {
- node.ui.checkboxImg.className = 'x-tree-node-checkbox-none';
- }
- }
- if (!node.isLeaf()) {
- for(var i = 0; i < node.childNodes.length; i++) {
- checked = checked.concat(this.getChecked(node.childNodes[i]));
- }
- }
- return checked;
- };
- tree.setChecked = function(array) {
- for (var i = array.length - 1; 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,
- timeout:60000,
- 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);
|