OrgField.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. Gef.ns('Gef.org');
  2. Gef.org.CheckboxTreeNodeUI = Ext.extend(Ext.tree.CheckboxNodeUI, {
  3. checkParent: Ext.emptyFn,
  4. checkChild: Ext.emptyFn
  5. });
  6. Gef.org.OrgField = Ext.extend(Ext.form.TriggerField, {
  7. triggerClass : "x-form-search-trigger",
  8. initComponent: function() {
  9. this.readOnly = false;
  10. Gef.org.OrgField.superclass.initComponent.call(this);
  11. this.addEvents('select');
  12. },
  13. onTriggerClick: function() {
  14. this.showWindow();
  15. },
  16. /* getStore:function(){ // 此方法 似乎没有用……
  17. Ext.Ajax.request({//拿到tree数据
  18. url:basePath+'common/getOrgAssignees.action',
  19. method:'post',
  20. success: function(response){
  21. res = new Ext.decode(response.responseText);
  22. if(res.tree){
  23. store = new Ext.decode(res.tree);
  24. Ext.getCmp('orgfield').showWindow(store);
  25. }
  26. }
  27. });
  28. },*/
  29. showWindow: function(store) {
  30. var me = this;
  31. var requestUrl = '';
  32. if(me.name=='assignee'||me.name=='notifyPeople'){
  33. requestUrl = basePath+'common/getOrgAssignees.action';
  34. }else{
  35. requestUrl = basePath+'common/getJobOfOrg.action';
  36. }
  37. Ext.Ajax.request({//拿到tree数据
  38. url:requestUrl,
  39. method:'post',
  40. timeout:60000,
  41. success: function(response){
  42. res = new Ext.decode(response.responseText);
  43. if(res.tree){
  44. store = new Ext.decode(res.tree);
  45. var window=me.getWindow(store);
  46. window.show();
  47. var value =window.field.value;
  48. var array = value.split(',');
  49. me.orgTree.cleanCheck();
  50. me.orgTree.setChecked(array);
  51. window.items.items[0].form.items.items[3].setValue(me.orgTree.getChecked());
  52. }
  53. }
  54. });
  55. Gef.activeEditor.disable();
  56. },
  57. hideWindow: function() {
  58. this.getWindow().hide();
  59. Gef.activeEditor.enable();
  60. },
  61. getWindow: function(store) {
  62. if (!this.orgWindow) {
  63. this.orgWindow = this.createWindow(store);
  64. }
  65. return this.orgWindow;
  66. },
  67. createWindow: function(store) {
  68. var me = this;
  69. var selectedValues = [];
  70. if(this.value.indexOf(',')>0){
  71. selectedValues = this.value.split(',');
  72. }
  73. var tree = new Ext.tree.TreePanel({
  74. autoScroll: true,
  75. loader: new Ext.tree.CustomUITreeLoader({
  76. baseAttr: {
  77. uiProvider: Gef.org.CheckboxTreeNodeUI
  78. }
  79. }),
  80. width:300,
  81. region:'center',
  82. enableDD: false,
  83. containerScroll: true,
  84. rootUIProvider: Gef.org.CheckboxTreeNodeUI,
  85. selModel: new Ext.tree.CheckNodeMultiSelectionModel(),
  86. rootVisible: false,
  87. count:1, // 这一行 是为了联合控制 click事件 加上去的,不属于树本身的属性:
  88. listeners:{
  89. 'dbclick':function(){
  90. root = this.getRootNode();
  91. var childrens = root.childNodes;
  92. for(var i=0;i<childrens.length;i++){
  93. for(var j=0;j<childrens[i].childNodes.length;j++){
  94. if(childrens[i][j].attributes.qtip==me.value){
  95. childrens[i][j].ui.checkboxImg.className = 'x-tree-node-checkbox-all';
  96. childrens[i][j].attributes.checked = true;
  97. }
  98. }
  99. }
  100. },
  101. 'expandnode':function(node){
  102. if(!node.isLeaf()){
  103. var childrens = node.childNodes;
  104. for(var i=0;i<childrens.length;i++){
  105. if(childrens[i].isLeaf()){ // 传过来的 model.value(即之前保存过的值一定是 叶子节点额。)
  106. if(selectedValues.length<2){ // model.value 只选择了一个值
  107. if(childrens[i].attributes.qtip==me.value){
  108. childrens[i].ui.checkboxImg.className = 'x-tree-node-checkbox-all';
  109. childrens[i].attributes.checked = true;
  110. }
  111. }else{
  112. for(var j=0;j<selectedValues.length;j++){ //model.value 选择了多个值!
  113. if(childrens[i].attributes.qtip==selectedValues[j]){
  114. childrens[i].ui.checkboxImg.className = 'x-tree-node-checkbox-all';
  115. childrens[i].attributes.checked = true;
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }
  123. }
  124. });
  125. tree.getLoader().on('load', function(o, node) {
  126. if (node.isRoot) {
  127. tree.expandAll();
  128. }
  129. });
  130. var root = new Ext.tree.AsyncTreeNode({
  131. text: 'root',
  132. draggable: false,
  133. leaf:false,
  134. children:store,
  135. expanded:true
  136. });
  137. tree.setRootNode(root);
  138. tree.cleanCheck = function(node) {
  139. if (typeof node == 'undefined') {
  140. node = this.rootVisible ? this.getRootNode() : this.getRootNode().firstChild;
  141. }
  142. if (node) {
  143. if (!node.isLeaf()) {
  144. node.ui.checkboxImg.className = 'x-tree-node-checkbox-none';
  145. node.attributes.checked = false;
  146. for(var i = 0; i < node.childNodes.length; i++) {
  147. this.cleanCheck(node.childNodes[i]);
  148. }
  149. }
  150. }
  151. };
  152. tree.getChecked = function(node) {
  153. var checked = [], i;
  154. if (typeof node == 'undefined') {
  155. node = this.getRootNode();
  156. } else if (node.ui.checkboxImg && node.ui.checkboxImg.className == 'x-tree-node-checkbox-all' ) {
  157. if(node.isLeaf()){
  158. checked.push(node.text);
  159. } else {
  160. node.ui.checkboxImg.className = 'x-tree-node-checkbox-none';
  161. }
  162. }
  163. if (!node.isLeaf()) {
  164. for(var i = 0; i < node.childNodes.length; i++) {
  165. checked = checked.concat(this.getChecked(node.childNodes[i]));
  166. }
  167. }
  168. return checked;
  169. };
  170. tree.setChecked = function(array) {
  171. for (var i = array.length - 1; i >= 0; i--) {
  172. var n = this.getNodeById(array[i]);
  173. if (n && !n.getUI().checked()) {
  174. n.getUI().check();
  175. }
  176. }
  177. };
  178. this.orgTree = tree;
  179. //加筛选 根据 所属组织 人员名称 以及编号 做筛选
  180. var formpanel=new Ext.form.FormPanel({
  181. height:100,
  182. region:'west',
  183. width:'30%',
  184. labelWidth: 70,
  185. labelAlign: 'right',
  186. border: false,
  187. defaultType: 'textfield',
  188. defaults: {
  189. anchor: '90%'
  190. },
  191. bodyStyle: {
  192. padding: '6px 0 0'
  193. },
  194. items:[{
  195. xtype:'textfield',
  196. name:'orname',
  197. fieldLabel:'所属组织',
  198. },{
  199. xtype:'textfield',
  200. name:'name',
  201. fieldLabel:'员工名称'
  202. },{
  203. xtype:'textfield',
  204. name:'code',
  205. fieldLabel:'员工编号'
  206. },{
  207. xtype: 'textarea',
  208. name:'selected',
  209. fieldLabel:'已选择'
  210. }],
  211. buttonAlign:'center',
  212. buttons:[{
  213. text:'筛选',
  214. iconCls:'x-form-search-trigger',
  215. style:'padding-bottom:150px',
  216. handler:function(){
  217. var condition=me.getCondition(win);
  218. if(condition){
  219. var requestUrl = '';
  220. if(me.name=='assignee'||me.name=='notifyPeople'){
  221. requestUrl = basePath+'common/getOrgAssignees.action';
  222. }else{
  223. requestUrl = basePath+'common/getJobOfOrg.action';
  224. }
  225. Ext.Ajax.request({//拿到tree数据
  226. url:requestUrl,
  227. timeout:60000,
  228. params:{
  229. condition:condition
  230. },
  231. method:'post',
  232. success: function(response){
  233. res = new Ext.decode(response.responseText);
  234. if(res.tree){
  235. var cstore = new Ext.decode(res.tree);
  236. var hisroot=tree.getRootNode();
  237. var cn = hisroot.childNodes,
  238. n;
  239. while ((n = cn[0])) {
  240. hisroot.removeChild(n);
  241. }
  242. var fn = function(node, ch) {
  243. for(var i in ch) {
  244. var n = ch[i];
  245. if(n.text){
  246. node.appendChild(new Ext.tree.AsyncTreeNode({
  247. text: n.text,
  248. draggable: false,
  249. leaf:false,
  250. children:n.children
  251. }));
  252. }
  253. }
  254. };
  255. fn(hisroot, cstore);
  256. tree.expandAll();
  257. var value =win.field.value;
  258. var array = value.split(',');
  259. tree.cleanCheck();
  260. tree.setChecked(array);
  261. }
  262. }
  263. });
  264. }
  265. }
  266. }]
  267. });
  268. var win = new Ext.Window({
  269. title: '人事',
  270. layout: 'border',
  271. height:window.innerHeight*0.9,
  272. width: 600,
  273. closeAction: 'hide',
  274. modal: true,
  275. items: [formpanel,tree],
  276. buttons: [ {
  277. text: '确定',
  278. handler: this.submit,
  279. scope: this
  280. }, {
  281. text: '取消',
  282. handler: this.hideWindow,
  283. scope: this
  284. }, {
  285. text: '刷新',
  286. handler: function() {
  287. tree.root.reload();
  288. },
  289. scope: this
  290. }],
  291. listeners:{
  292. 'beforehide':function(c){
  293. Gef.activeEditor.existWin=false;
  294. Gef.activeEditor.enable();
  295. },
  296. 'beforeshow':function(c){
  297. Gef.activeEditor.existWin=true;
  298. Gef.activeEditor.disable();
  299. }
  300. }
  301. });
  302. win.field = this;
  303. return win;
  304. },
  305. submit: function() {
  306. /* var value =this.orgWindow.items.items[0].form.items.items[3].getValue();
  307. var arr=null;
  308. if(!value){
  309. value='';
  310. }else {
  311. arr=value.split(",");
  312. } */
  313. var value='';
  314. var array = this.orgTree.getChecked();
  315. for (var i = 0; i < array.length; i++) {
  316. value +=array[i]+',';
  317. }
  318. value=value.substring(0,value.length-1);
  319. this.setValue(value);
  320. this.hideWindow();
  321. this.fireEvent('select', this);
  322. },
  323. selectOwner: function() {
  324. this.setValue("项目发起人");
  325. this.hideWindow();
  326. this.fireEvent('select', this);
  327. },
  328. refreshTree: function() {
  329. },
  330. getCondition:function(win){
  331. var form=win.items.items[0].form;
  332. var values=form.getValues();
  333. var orname=values.orname;
  334. var name=values.name;
  335. var code=values.code;
  336. var condition="";
  337. if((!orname && !name && !code)|| (orname=="" && name=="" && code=="")){
  338. return null;
  339. }else {
  340. condition+=(orname==null || orname=="")?"1=1 #" :" or_name like '%"+orname+"%' #";
  341. condition+=(name==null || name=="")?"1=1 " :" em_name like '%"+name+"%'";
  342. condition+=(code==null || code=="")?" " :" and em_code like '%"+code+"%'";
  343. return condition;
  344. }
  345. }
  346. });
  347. Ext.reg('orgfield', Gef.org.OrgField);