JobPowerTreeGrid.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /**
  2. * ERP项目gridpanel样式6:jobPower专用treegrid
  3. */
  4. Ext.define('erp.view.core.grid.JobPowerTreeGrid',{
  5. extend: 'Ext.tree.Panel',
  6. alias: 'widget.erpJobPowerTreeGrid',
  7. region: 'south',
  8. layout : 'fit',
  9. id: 'treegrid',
  10. emptyText : $I18N.common.grid.emptyText,
  11. useArrows: true,
  12. rootVisible: false,
  13. singleExpand: true,
  14. updateNodes: [],
  15. store: Ext.create('Ext.data.TreeStore', {
  16. fields: [{
  17. name: 'po_powername',
  18. type: 'string'
  19. },{
  20. name:'pp_see',
  21. type:'bool'
  22. },{
  23. name:'pp_seeall',
  24. type:'bool'
  25. },{
  26. name:'pp_add',
  27. type:'bool'
  28. },{
  29. name:'pp_delete',
  30. type:'bool'
  31. },{
  32. name:'pp_save',
  33. type:'bool'
  34. },{
  35. name:'pp_commit',
  36. type:'bool'
  37. },{
  38. name:'pp_uncommit',
  39. type:'bool'
  40. },{
  41. name:'pp_audit',
  42. type:'bool'
  43. },{
  44. name:'pp_unaudit',
  45. type:'bool'
  46. },{
  47. name:'pp_print',
  48. type:'bool'
  49. },{
  50. name:'pp_disable',
  51. type:'bool'
  52. },{
  53. name:'pp_undisable',
  54. type:'bool'
  55. },{
  56. name:'pp_closed',
  57. type:'bool'
  58. },{
  59. name:'pp_unclosed',
  60. type:'bool'
  61. },{
  62. name:'pp_posting',
  63. type:'bool'
  64. },{
  65. name:'pp_unposting',
  66. type:'bool'
  67. },{
  68. name: 'po_id',
  69. type: 'number'
  70. },{
  71. name: 'po_parentid',
  72. type: 'number'
  73. },{
  74. name: 'po_isleaf',
  75. type: 'string'
  76. },{
  77. name: 'pp_id',
  78. type: 'number'
  79. },{
  80. name: 'pp_joid',
  81. type: 'number'
  82. },{
  83. name: 'pp_poid',
  84. type: 'number'
  85. }],
  86. root : {
  87. text: 'root',
  88. id: 'root',
  89. expanded: true
  90. }
  91. }),
  92. columns: [{
  93. text: '权限名称',
  94. flex: 1,
  95. dataIndex: 'po_powername',
  96. xtype: 'treecolumn'
  97. },{
  98. text: '浏览',
  99. flex: 0.2,
  100. xtype: 'checkcolumn',
  101. editor: {
  102. xtype: 'checkbox',
  103. cls: 'x-grid-checkheader-editor'
  104. },
  105. dataIndex: 'pp_see'
  106. },{
  107. text: '浏览他人',
  108. flex: 0.3,
  109. xtype: 'checkcolumn',
  110. editor: {
  111. xtype: 'checkbox',
  112. cls: 'x-grid-checkheader-editor'
  113. },
  114. dataIndex: 'pp_seeall'
  115. },{
  116. text: '新增',
  117. flex: 0.2,
  118. xtype: 'checkcolumn',
  119. editor: {
  120. xtype: 'checkbox',
  121. cls: 'x-grid-checkheader-editor'
  122. },
  123. dataIndex: 'pp_add'
  124. },{
  125. text: '删除',
  126. flex: 0.2,
  127. xtype: 'checkcolumn',
  128. editor: {
  129. xtype: 'checkbox',
  130. cls: 'x-grid-checkheader-editor'
  131. },
  132. dataIndex: 'pp_delete'
  133. },{
  134. text: '保存',
  135. flex: 0.2,
  136. xtype: 'checkcolumn',
  137. editor: {
  138. xtype: 'checkbox',
  139. cls: 'x-grid-checkheader-editor'
  140. },
  141. dataIndex: 'pp_save'
  142. },{
  143. text: '提交',
  144. flex: 0.2,
  145. xtype: 'checkcolumn',
  146. editor: {
  147. xtype: 'checkbox',
  148. cls: 'x-grid-checkheader-editor'
  149. },
  150. dataIndex: 'pp_commit'
  151. },{
  152. text: '反提交',
  153. flex: 0.2,
  154. xtype: 'checkcolumn',
  155. editor: {
  156. xtype: 'checkbox',
  157. cls: 'x-grid-checkheader-editor'
  158. },
  159. dataIndex: 'pp_uncommit'
  160. },{
  161. text: '审核',
  162. flex: 0.2,
  163. xtype: 'checkcolumn',
  164. editor: {
  165. xtype: 'checkbox',
  166. cls: 'x-grid-checkheader-editor'
  167. },
  168. dataIndex: 'pp_audit'
  169. },{
  170. text: '反审核',
  171. flex: 0.2,
  172. xtype: 'checkcolumn',
  173. editor: {
  174. xtype: 'checkbox',
  175. cls: 'x-grid-checkheader-editor'
  176. },
  177. dataIndex: 'pp_unaudit'
  178. },{
  179. text: '打印',
  180. flex: 0.2,
  181. xtype: 'checkcolumn',
  182. editor: {
  183. xtype: 'checkbox',
  184. cls: 'x-grid-checkheader-editor'
  185. },
  186. dataIndex: 'pp_print'
  187. },{
  188. text: '禁用',
  189. flex: 0.2,
  190. xtype: 'checkcolumn',
  191. editor: {
  192. xtype: 'checkbox',
  193. cls: 'x-grid-checkheader-editor'
  194. },
  195. dataIndex: 'pp_disable'
  196. },{
  197. text: '反禁用',
  198. flex: 0.2,
  199. xtype: 'checkcolumn',
  200. editor: {
  201. xtype: 'checkbox',
  202. cls: 'x-grid-checkheader-editor'
  203. },
  204. dataIndex: 'pp_undisable'
  205. },{
  206. text: '结案',
  207. flex: 0.2,
  208. xtype: 'checkcolumn',
  209. editor: {
  210. xtype: 'checkbox',
  211. cls: 'x-grid-checkheader-editor'
  212. },
  213. dataIndex: 'pp_closed'
  214. },{
  215. text: '反结案',
  216. flex: 0.2,
  217. xtype: 'checkcolumn',
  218. editor: {
  219. xtype: 'checkbox',
  220. cls: 'x-grid-checkheader-editor'
  221. },
  222. dataIndex: 'pp_unclosed'
  223. },{
  224. text: '过账',
  225. flex: 0.2,
  226. xtype: 'checkcolumn',
  227. editor: {
  228. xtype: 'checkbox',
  229. cls: 'x-grid-checkheader-editor'
  230. },
  231. dataIndex: 'pp_posting'
  232. },{
  233. text: '反过账',
  234. flex: 0.2,
  235. xtype: 'checkcolumn',
  236. editor: {
  237. xtype: 'checkbox',
  238. cls: 'x-grid-checkheader-editor'
  239. },
  240. dataIndex: 'pp_unposting'
  241. },{
  242. dataIndex: 'po_id',
  243. hidden: true
  244. },{
  245. dataIndex: 'po_parentid',
  246. hidden: true
  247. },{
  248. dataIndex: 'po_isleaf',
  249. hidden: true
  250. },{
  251. dataIndex: 'pp_id',
  252. hidden: true
  253. },{
  254. dataIndex: 'pp_joid',
  255. hidden: true
  256. },{
  257. dataIndex: 'pp_poid',
  258. hidden: true
  259. }],
  260. bodyStyle:'background-color:#f1f1f1;',
  261. selType: 'rowmodel',
  262. initComponent : function(){
  263. Ext.override(Ext.data.AbstractStore,{
  264. indexOf: Ext.emptyFn
  265. });
  266. this.callParent(arguments);
  267. gridCondition = getUrlParam('gridCondition');
  268. gridCondition = (gridCondition == null) ? "" : gridCondition.replace(/IS/g,"=");
  269. this.getTreeGridNode(0);
  270. },
  271. selModel: Ext.create('Ext.selection.CheckboxModel',{
  272. listeners: {
  273. select: function(selModel, record){
  274. if(record.isLeaf()){
  275. var grid = Ext.getCmp('treegrid');
  276. grid.checkAll(record, true);
  277. }
  278. },
  279. deselect: function(selModel, record){
  280. if(record.isLeaf()){
  281. var grid = Ext.getCmp('treegrid');
  282. grid.checkAll(record, false);
  283. }
  284. }
  285. }
  286. }),
  287. listeners: {//滚动条有时候没反应,添加此监听器
  288. scrollershow: function(scroller) {
  289. if (scroller && scroller.scrollEl) {
  290. scroller.clearManagedListeners();
  291. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  292. }
  293. }
  294. },
  295. getTreeGridNode: function(id){
  296. var me = this;
  297. var activeTab = me.getActiveTab();
  298. var joid = Number(gridCondition.replace('pp_joid=', ''));
  299. activeTab.setLoading(true);
  300. Ext.Ajax.request({//拿到tree数据
  301. url : basePath + '/hr/employee/getJobPower.action',
  302. params: {
  303. parentid: id,
  304. joid: joid
  305. },
  306. callback : function(options,success,response){
  307. var res = new Ext.decode(response.responseText);
  308. activeTab.setLoading(false);
  309. if(res.powers){
  310. var tree = [];
  311. Ext.each(res.powers, function(d){
  312. d.id = d.po_id;
  313. d.parentId = d.po_parentid;
  314. d.cls = 'x-tree-cls-node';
  315. d.leaf = d.po_isleaf == 'T';
  316. d.pp_poid = d.id;
  317. d.pp_joid = joid;
  318. Ext.each(res.positionPowers, function(){
  319. if(d.po_id == this.pp_poid){
  320. d.pp_id = this.PP_id;
  321. d.pp_unposting = this.pp_unposting == 1;
  322. d.pp_posting = this.pp_posting == 1;
  323. d.pp_unclosed = this.pp_unclosed == 1;
  324. d.pp_closed = this.pp_closed == 1;
  325. d.pp_undisable = this.pp_undisable == 1;
  326. d.pp_disable = this.pp_disable == 1;
  327. d.pp_print = this.pp_print == 1;
  328. d.pp_unaudit = this.pp_unaudit == 1;
  329. d.pp_audit = this.pp_audit == 1;
  330. d.pp_uncommit = this.pp_uncommit ==1;
  331. d.pp_commit = this.pp_commit == 1;
  332. d.pp_save = this.pp_save == 1;
  333. d.pp_delete = this.pp_delete == 1;
  334. d.pp_add = this.pp_add == 1;
  335. d.pp_seeall = this.pp_seeall == 1;
  336. d.pp_see = this.pp_see == 1;
  337. }
  338. });
  339. if(!d.leaf){
  340. if(d.parentId == 0){
  341. d.cls = 'x-tree-cls-root';
  342. } else {
  343. d.cls = 'x-tree-cls-parent';
  344. }
  345. }
  346. tree.push(d);
  347. });
  348. var record = me.selModel.lastSelected;
  349. if(id == 0){
  350. me.store.setRootNode({
  351. text: 'root',
  352. id: 'root',
  353. expanded: true,
  354. children: tree
  355. });
  356. } else {
  357. record.appendChild(tree);
  358. record.expand(false, true);
  359. Ext.each(record.childNodes, function(){
  360. this.dirty = false;
  361. });
  362. }
  363. } else if(res.exceptionInfo){
  364. showError(res.exceptionInfo);
  365. }
  366. }
  367. });
  368. },
  369. getChildren: function(data, d){
  370. var o = [];
  371. Ext.each(data, function(){
  372. if(this.po_parentid == d.po_id){
  373. o.push(this);
  374. }
  375. });
  376. return o;
  377. },
  378. getActiveTab: function(){
  379. var tab = null;
  380. if(Ext.getCmp("content-panel")){
  381. tab = Ext.getCmp("content-panel").getActiveTab();
  382. }
  383. if(!tab){
  384. var win = parent.Ext.ComponentQuery.query('window');
  385. if(win.length > 0){
  386. tab = win[win.length-1];
  387. }
  388. }
  389. if(!tab && parent.Ext.getCmp("content-panel"))
  390. tab = parent.Ext.getCmp("content-panel").getActiveTab();
  391. if(!tab && parent.parent.Ext.getCmp("content-panel"))
  392. tab = parent.parent.Ext.getCmp("content-panel").getActiveTab();
  393. return tab;
  394. },
  395. getUpdateNodes: function(root){
  396. var me = this;
  397. if(!root){
  398. root = this.store.tree.root;
  399. me.updateNodes = new Array();
  400. }
  401. if(root.childNodes.length > 0){
  402. Ext.each(root.childNodes, function(){
  403. if(this.leaf){
  404. if(this.dirty){
  405. if(me.checkDirty(this.modified)){
  406. me.updateNodes.push(this);
  407. }
  408. }
  409. } else {
  410. me.getUpdateNodes(this);
  411. }
  412. });
  413. } else {
  414. if(root.dirty){
  415. if(me.checkDirty(root.modified)){
  416. me.updateNodes.push(root);
  417. }
  418. }
  419. }
  420. },
  421. /**
  422. * treegrid用到了checkcolumn时,由于其store的差异,根据recordIndex不能直接得到record,
  423. * 采用下面的方法可以在点击checkbox时,得到当前的record,再进而就可以修改checkbox的check属性等...
  424. */
  425. getRecordByRecordIndex: function(recordIndex, node){
  426. var me = this;
  427. if(!node){
  428. node = this.store.tree.root;
  429. me.findIndex = 0;
  430. me.findRecord = null;
  431. }
  432. if(me.findRecord == null){
  433. if(node.childNodes.length > 0 && node.isExpanded()){
  434. Ext.each(node.childNodes, function(){
  435. if(me.findIndex == recordIndex){
  436. me.findRecord = this;
  437. me.findIndex++;
  438. } else {
  439. me.findIndex++;
  440. me.getRecordByRecordIndex(recordIndex, this);
  441. }
  442. });
  443. } else {
  444. if(me.findIndex == recordIndex){
  445. me.findRecord = node;
  446. }
  447. }
  448. }
  449. },
  450. checkRecord: function(record, dataIndex, checked){
  451. var me = this;
  452. if(record.childNodes.length > 0){
  453. Ext.each(record.childNodes, function(){
  454. this.set(dataIndex, checked);
  455. me.checkRecord(this, dataIndex, checked);
  456. });
  457. }
  458. },
  459. checkAll: function(record, checked){
  460. record.set('pp_see', checked);
  461. record.set('pp_seeall', checked);
  462. record.set('pp_add', checked);
  463. record.set('pp_delete', checked);
  464. record.set('pp_save', checked);
  465. record.set('pp_commit', checked);
  466. record.set('pp_uncommit', checked);
  467. record.set('pp_audit', checked);
  468. record.set('pp_unaudit', checked);
  469. record.set('pp_print', checked);
  470. record.set('pp_disable', checked);
  471. record.set('pp_undisable', checked);
  472. record.set('pp_closed', checked);
  473. record.set('pp_unclosed', checked);
  474. record.set('pp_posting', checked);
  475. record.set('pp_unposting', checked);
  476. },
  477. checkDirty: function(modfied){
  478. var change = Ext.Object.getKeys(modfied);
  479. var bool = false;
  480. Ext.each(change, function(){
  481. if(this == 'pp_see' || this == 'pp_seeall' || this == 'pp_add' || this == 'pp_delete' ||
  482. this == 'pp_save' || this == 'pp_commit' || this == 'pp_uncommit' || this == 'pp_audit' || this == 'pp_unaudit' ||
  483. this == 'pp_print' || this == 'pp_disable' || this == 'pp_undisable' || this == 'pp_closed' || this == 'pp_unclosed' ||
  484. this == 'pp_posting' || this == 'pp_unposting'){
  485. bool = true;
  486. }
  487. });
  488. return bool;
  489. }
  490. });