DocCaTreeGrid.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /**
  2. * ERP项目gridpanel样式5:documentCatalog专用treegrid
  3. */
  4. Ext.define('erp.view.core.grid.DocCaTreeGrid',{
  5. extend: 'Ext.tree.Panel',
  6. alias: 'widget.erpDocCaTreeGrid',
  7. BaseUtil: Ext.create('erp.util.BaseUtil'),
  8. FormUtil: Ext.create('erp.util.FormUtil'),
  9. region: 'south',
  10. layout : 'fit',
  11. id: 'treegrid',
  12. emptyText : $I18N.common.grid.emptyText,
  13. useArrows: true,
  14. rootVisible: false,
  15. singleExpand: true,
  16. saveNodes: [],
  17. updateNodes: [],
  18. deleteNodes: [],
  19. expandedNodes: [],
  20. store: Ext.create('Ext.data.TreeStore', {
  21. fields: fields,
  22. root : {
  23. text: 'root',
  24. id: 'root',
  25. expanded: true
  26. }
  27. }),
  28. columns: columns,
  29. plugins: Ext.create('Ext.grid.plugin.CellEditing', {
  30. clicksToEdit: 1
  31. }),
  32. tbar: [{
  33. iconCls: 'tree-add',
  34. text: $I18N.common.button.erpAddButton,
  35. handler: function(){
  36. // var treegrid = Ext.getCmp('treegrid');
  37. // var items = treegrid.selModel.selected.items;
  38. // var bool = false;
  39. // Ext.Ajax.request({//拿到tree数据
  40. // url : basePath + 'oa/document/queryDocPower.action',
  41. // params:{
  42. // id : items[0].data["dc_id"],
  43. // field : "add"
  44. // },
  45. // async: false,
  46. // callback : function(options,success,response){
  47. // var res = new Ext.decode(response.responseText);
  48. //// alert(res.error);
  49. // if(res.error){
  50. // showError(res.error);
  51. // } else {
  52. // bool = true;
  53. // }
  54. // }
  55. // });
  56. //// alert(bool);
  57. // if(bool){
  58. // if(items.length > 0 && items[0].isLeaf() == false){
  59. // if(items[0].data['dc_id'] == null || items[0].data['dc_id'] == ''){
  60. // warnMsg('如果在该文件夹下添加子文件夹,需先保存该文件夹,是否保存?', function(btn){
  61. // if(btn == 'yes'){
  62. // if(items[0].data['dc_displayname'] == null || items[0].data['dc_displayname'] == ''){
  63. // showError('请先描述该节点');
  64. // return;
  65. // } else {
  66. // treegrid.saveNodes.push(items[0]);
  67. // treegrid.saveNode();
  68. // }
  69. // } else if(btn == 'no'){
  70. // return;
  71. // }
  72. // });
  73. // } else {
  74. // items[0].data['leaf'] = false;
  75. // items[0].data['cls'] = 'x-tree-cls-parent';
  76. // items[0].data['dc_isfile'] = 'F';
  77. // items[0].dirty = true;
  78. // var o = {
  79. // dc_parentid: items[0].data['dc_id'],
  80. // dc_isfile: 'T',
  81. // cls: "x-tree-cls-parent",
  82. // parentId: items[0].data['dc_id'],
  83. // leaf: false,
  84. //// dc_deleteable: 'T',
  85. //// deleteable: true,
  86. // allowDrag: true
  87. // };
  88. // items[0].appendChild(o);
  89. // items[0].expand(true);
  90. // }
  91. // } else {
  92. // var record = treegrid.getExpandItem();
  93. // if(record){
  94. // var o = {
  95. // dc_parentid: record.data['dc_id'],
  96. // dc_isfile: 'F',
  97. // cls: "x-tree-cls-parent",
  98. // parentId: record.data['dc_id'],
  99. //// dc_deleteable: 'T',
  100. //// deleteable: true,
  101. // leaf: false,
  102. // allowDrag: true
  103. // };
  104. // record.appendChild(o);
  105. // }
  106. // }
  107. // }
  108. }
  109. },{
  110. iconCls: 'tree-delete',
  111. text: $I18N.common.button.erpDeleteButton,
  112. handler: function(){
  113. // var treegrid = Ext.getCmp('treegrid');
  114. // var items = treegrid.selModel.selected.items;
  115. // var bool = false;
  116. // Ext.Ajax.request({//拿到tree数据
  117. // url : basePath + 'oa/document/queryDocPower.action',
  118. // params:{
  119. // id : items[0].data["dc_id"],
  120. // field : "delete"
  121. // },
  122. // async: false,
  123. // callback : function(options,success,response){
  124. // var res = new Ext.decode(response.responseText);
  125. // if(res.error){
  126. // showError(res.error);
  127. // } else {
  128. // bool = true;
  129. // }
  130. // }
  131. // });
  132. //// alert(bool);
  133. // if(bool){
  134. // if(items.length > 0){
  135. // if(items[0].isLeaf() == true){
  136. // if(items[0].data['dc_id'] != null && items[0].data['dc_id'] != ''){
  137. // if(items[0].data['dc_deleteable'] == 'T'){
  138. // warnMsg('确定删除文件 [' + items[0].data['dc_displayname'] + "]?", function(btn){
  139. // if(btn == 'yes'){
  140. // treegrid.deleteNode(items[0]);
  141. // } else if(btn == 'no'){
  142. // return;
  143. // }
  144. // });
  145. // } else {
  146. // showError('该文件不允许删除!');
  147. // }
  148. // } else {
  149. // items[0].remove(true);
  150. // }
  151. // } else {
  152. // if(items[0].data['dc_id'] != null || items[0].data['dc_id'] != ''){
  153. // if(items[0].data['dc_deleteable'] == 'T'){
  154. // Ext.each(items[0].childNodes, function(){
  155. // if(this.data['dc_deleteable'] == 'F'){
  156. // showError('该文件夹有不可删除子节点,无法删除该文件夹!');
  157. // return;
  158. // }
  159. // });
  160. // warnMsg('确定删除文件夹[' + items[0].data['dc_displayname'] + ']及其所有子文件?', function(btn){
  161. // if(btn == 'yes'){
  162. // treegrid.deleteNode(items[0]);
  163. // } else if(btn == 'no'){
  164. // return;
  165. // }
  166. // });
  167. // } else {
  168. // showError('该文件夹不允许删除!');
  169. // }
  170. // } else {
  171. // items[0].remove(true);
  172. // }
  173. // }
  174. // } else {
  175. // var record = treegrid.getExpandItem();
  176. // if(record){
  177. // if(record.childNodes.length == 0){
  178. // if(record.data['dc_id'] != null && record.data['dc_id'] != ''){
  179. // if(record.data['dc_deleteable'] == 'T'){
  180. // warnMsg('确定删除文件夹[' + record.data['dc_displayname'] + ']?', function(btn){
  181. // if(btn == 'yes'){
  182. // treegrid.deleteNode(record);
  183. // } else if(btn == 'no'){
  184. // return;
  185. // }
  186. // });
  187. // } else {
  188. // showError('该文件夹不允许删除!');
  189. // }
  190. // } else {
  191. // record.remove(true);
  192. // }
  193. // }
  194. // }
  195. // }
  196. // }
  197. }
  198. },{
  199. iconCls: 'tree-save',
  200. text: $I18N.common.button.erpSaveButton,
  201. handler: function(){
  202. // var treegrid = Ext.getCmp('treegrid'),
  203. // nodes = treegrid.store.tree.root.childNodes;
  204. // treegrid.saveNodes = [];
  205. // Ext.each(nodes, function(){
  206. // treegrid.checkChild(this);
  207. // });
  208. // treegrid.saveNode();
  209. }
  210. // },{
  211. // iconCls: 'x-button-icon-download',
  212. // text: '下载',
  213. // handler: function(){
  214. // var treegrid = Ext.getCmp('treegrid');
  215. // var items = treegrid.selModel.selected.items;
  216. // var bool = false;
  217. // Ext.Ajax.request({
  218. // url : basePath + 'oa/document/queryDocPower.action',
  219. // params:{
  220. // id : items[0].data["dc_id"],
  221. // field : "download"
  222. // },
  223. // async: false,
  224. // callback : function(options,success,response){
  225. // var res = new Ext.decode(response.responseText);
  226. // if(res.error){
  227. // showError(res.error);
  228. // } else {
  229. // bool = true;
  230. // }
  231. // }
  232. // });
  233. // if (bool) {
  234. // if (items[0].data['dc_isfile'] == 'T') {
  235. // window.location.href = basePath + 'oa/download.action?path=' + items[0].data["dc_url"];
  236. //// Ext.Ajax.request({
  237. //// url : basePath + 'oa/online.action',
  238. //// params : {
  239. //// filepath : items[0].data["dc_url"],
  240. //// isOnline : true
  241. //// },
  242. //// async : false,
  243. //// callback : function(options,success,response) {
  244. //// var res = new Ext.decode(response.responseText);
  245. //// if (res.error) {
  246. //// showError(res.error);
  247. //// }
  248. //// }
  249. //// });
  250. // } else {
  251. // Ext.Ajax.request({
  252. // url : basePath + 'oa/zip.action',
  253. // params : {
  254. // id : items[0].data["dc_id"]
  255. // },
  256. // async : false,
  257. // callback : function(options,success,response) {
  258. // var res = new Ext.decode(response.responseText);
  259. // if (res.error) {
  260. // showError(res.error);
  261. // } else {
  262. // if (res.warning) {
  263. // alert(res.warning);
  264. // }
  265. // alert(res.path);
  266. // window.location.href = basePath + 'oa/download.action?path=' + res.path;
  267. // }
  268. // }
  269. // });
  270. // }
  271. //// path = items[0].data['dc_id'];
  272. // }
  273. // }
  274. },{
  275. iconCls: 'x-button-icon-print',
  276. text: "查看",
  277. handler: function(){
  278. var me = Ext.getCmp('treegrid');
  279. var items = me.selModel.selected.items;
  280. if(items[0] != null && items[0].data.dc_isfile == 'T'){
  281. var id = items[0].data.dc_version.split(".")[1];
  282. if(id != null && id != ''){
  283. if(items[0].data.dc_creator_id == em_uu || Ext.getCmp('treegrid').getDocumentListPower(id).see == 1){
  284. var panel = Ext.getCmp("documentlist" + id);
  285. var main = parent.Ext.getCmp("content-panel");
  286. if(!panel){
  287. var title = items[0].data.dc_displayname;
  288. panel = {
  289. title : title,
  290. tag : 'iframe',
  291. tabConfig:{tooltip: items[0].data.dc_displayname},
  292. frame : true,
  293. border : false,
  294. layout : 'fit',
  295. iconCls : 'x-tree-icon-tab-tab1',
  296. html : '<iframe id="iframe_documentlist_' + id + '" src="' + basePath + "jsps/oa/document/documentDetail.jsp?id=" + id + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>',
  297. closable : true,
  298. listeners : {
  299. close : function(){
  300. main.setActiveTab(main.getActiveTab().id);
  301. }
  302. }
  303. };
  304. me.FormUtil.openTab(panel, "documentlist" + id);
  305. }else{
  306. main.setActiveTab(panel);
  307. }
  308. } else {
  309. showError("亲!你没有相关操作权限哦!");return;
  310. }
  311. }
  312. } else {
  313. showError("亲!请选择要查看的文档");return;
  314. }
  315. }
  316. },{
  317. iconCls: 'x-button-icon-scan',
  318. text: "刷新",
  319. handler: function(){
  320. Ext.getCmp('treegrid').getTreeGridNode({parentId: 0});
  321. }
  322. },{
  323. xtype: 'tbtext',
  324. id: 'path',
  325. style: 'background: #C6d1c5'
  326. }],
  327. bodyStyle:'background-color:#f1f1f1;',
  328. initComponent : function(){
  329. Ext.override(Ext.data.AbstractStore,{
  330. indexOf: Ext.emptyFn
  331. });
  332. this.callParent(arguments);
  333. this.getTreeGridNode({parentId: 0});
  334. },
  335. listeners: {//滚动条有时候没反应,添加此监听器
  336. scrollershow: function(scroller) {
  337. if (scroller && scroller.scrollEl) {
  338. scroller.clearManagedListeners();
  339. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  340. }
  341. }
  342. },
  343. getTreeGridNode: function(param){
  344. var me = this;
  345. var activeTab = me.getActiveTab();
  346. activeTab.setLoading(true);
  347. Ext.Ajax.request({//拿到tree数据
  348. url : basePath + 'common/lazyDocumentTree.action',
  349. params: param,
  350. callback : function(options,success,response){
  351. var res = new Ext.decode(response.responseText);
  352. activeTab.setLoading(false);
  353. if(res.tree){
  354. var tree = res.tree;
  355. Ext.each(tree, function(t){
  356. t.dc_id = t.id;
  357. t.dc_parentid = t.parentId;
  358. t.dc_displayname = t.text;
  359. t.dc_isfile = t.leaf ? 'T' : 'F';
  360. // t.dc_tabtitle = t.text;
  361. // t.dc_url = t.url;
  362. // t.dc_deleteable = t.deleteable ? 'T' : 'F';
  363. t.dc_updatetime = t.updatetime;
  364. // t.dc_filesize = t.filesize;
  365. t.dc_creator = t.creator;
  366. t.dc_creator_id = t.creator_id;
  367. t.dc_version = t.version;
  368. });
  369. me.store.setRootNode({
  370. text: 'root',
  371. id: 'root',
  372. expanded: true,
  373. children: tree
  374. });
  375. Ext.each(me.store.tree.root.childNodes, function(){
  376. this.dirty = false;
  377. });
  378. } else if(res.exceptionInfo){
  379. showError(res.exceptionInfo);
  380. }
  381. }
  382. });
  383. },
  384. checkChild: function(record){
  385. var me = this;
  386. if(!record.data['leaf']){
  387. if(record.childNodes.length > 0){
  388. if(record.data['dc_id'] == null || record.data['dc_id'] == ''){
  389. warnMsg('如果在节点' + record.data['dc_id'] + '下添加子节点,需先保存该节点,是否保存?', function(btn){
  390. if(btn == 'yes'){
  391. if(items[0].data['dc_displayname'] == null || items[0].data['dc_displayname'] == ''){
  392. showError('请先描述该节点');
  393. return;
  394. } else {
  395. me.saveNodes.push(items[0]);
  396. me.saveNode();
  397. }
  398. } else if(btn == 'no'){
  399. return;
  400. }
  401. });
  402. }
  403. Ext.each(record.childNodes, function(){
  404. me.checkChild(this);
  405. });
  406. } else if(record.childNodes.length == 0){
  407. if(record.data['dc_id'] == null || record.data['dc_id'] == '')
  408. if(record.data['dc_displayname'] == null || record.data['dc_displayname'] == ''){
  409. showError('请先描述该节点');
  410. return;
  411. } else {
  412. me.saveNodes.push(record);
  413. me.saveNode();
  414. }
  415. }
  416. } else {
  417. if(record.dirty){
  418. if(record.data['dc_id'] == null || record.data['dc_id'] == ''){
  419. me.saveNodes.push(record);
  420. } else {
  421. me.updateNodes.push(record);
  422. }
  423. }
  424. }
  425. },
  426. saveNode: function(){
  427. var me = this;
  428. me.getUpdateNodes();
  429. var save = new Array();
  430. var update = new Array();
  431. var index = 0;
  432. Ext.each(me.saveNodes, function(){
  433. if(this.data.dc_displayname != null && this.data.dc_displayname != ''){
  434. if(this.data.dc_tabtitle == null || this.data.dc_tabtitle == ''){
  435. this.data.dc_tabtitle == this.data.dc_displayname;
  436. }
  437. // if(this.data.dc_deleteable == null || this.data.dc_deleteable == ''){
  438. // this.data.dc_deleteable == 'T';
  439. // }
  440. var o = {
  441. dc_id: this.data.dc_id,
  442. dc_displayname: this.data.dc_displayname,
  443. // dc_url: this.data.dc_url,
  444. dc_isfile: this.data.dc_isfile,
  445. // dc_tabtitle: this.data.dc_tabtitle,
  446. dc_parentid: this.data.dc_parentid,
  447. // dc_deleteable: this.data.dc_deleteable
  448. };
  449. save[index++] = Ext.JSON.encode(o);
  450. }
  451. });
  452. index = 0;
  453. Ext.each(me.updateNodes, function(){
  454. if(this.data.dc_displayname != null && this.data.dc_displayname != ''){
  455. if(this.data.dc_tabtitle == null || this.data.dc_tabtitle == ''){
  456. this.data.dc_tabtitle == this.data.dc_displayname;
  457. }
  458. // if(this.data.dc_deleteable == null || this.data.dc_deleteable == ''){
  459. // this.data.dc_deleteable == 'T';
  460. // }
  461. var o = {
  462. dc_id: this.data.dc_id,
  463. dc_displayname: this.data.dc_displayname,
  464. // dc_url: this.data.dc_url,
  465. dc_isfile: this.data.dc_isfile,
  466. // dc_tabtitle: this.data.dc_tabtitle,
  467. dc_parentid: this.data.dc_parentid,
  468. // dc_deleteable: this.data.dc_deleteable
  469. };
  470. update[index++] = Ext.JSON.encode(o);
  471. }
  472. });
  473. if(save.length > 0 || update.length > 0){
  474. var activeTab = me.getActiveTab();
  475. activeTab.setLoading(true);
  476. Ext.Ajax.request({
  477. url : basePath + 'oa/saveDocumentCatalog.action',
  478. params: {
  479. save: unescape(save.toString().replace(/\\/g,"%")),
  480. update: unescape(update.toString().replace(/\\/g,"%"))
  481. },
  482. callback : function(options,success,response){
  483. var res = new Ext.decode(response.responseText);
  484. activeTab.setLoading(false);
  485. if(res.success){
  486. me.saveNodes = [];
  487. me.updateNodes = [];
  488. me.getTreeGridNode({parentId: 0});
  489. } else if(res.exceptionInfo){
  490. showError(res.exceptionInfo);
  491. }
  492. }
  493. });
  494. }
  495. },
  496. getExpandItem: function(root){
  497. var me = this;
  498. if(!root){
  499. root = this.store.tree.root;
  500. }
  501. var node = null;
  502. if(root.childNodes.length > 0){
  503. Ext.each(root.childNodes, function(){
  504. if(this.isExpanded()){
  505. node = this;
  506. if(this.childNodes.length > 0){
  507. var n = me.getExpandItem(this);
  508. node = n == null ? node : n;
  509. }
  510. }
  511. });
  512. }
  513. return node;
  514. },
  515. getExpandNode: function(root){
  516. var treegrid = Ext.getCmp('treegrid');
  517. var items = treegrid.selModel.selected.items;
  518. var road = '';
  519. Ext.each(items,function(){
  520. road += this.data['dc_id'];
  521. });
  522. return road;
  523. },
  524. deleteNode: function(record){
  525. var me = this;
  526. if(record){
  527. var activeTab = me.getActiveTab();
  528. activeTab.setLoading(true);
  529. Ext.Ajax.request({
  530. url : basePath + 'oa/deleteDocumentCatalog.action',
  531. params: {
  532. id: Number(record.data['dc_id'])
  533. },
  534. callback : function(options,success,response){
  535. var res = new Ext.decode(response.responseText);
  536. activeTab.setLoading(false);
  537. if(res.success){
  538. record.remove(true);
  539. } else if(res.exceptionInfo){
  540. showError(res.exceptionInfo);
  541. }
  542. }
  543. });
  544. }
  545. },
  546. getUpdateNodes: function(root){
  547. var me = this;
  548. if(!root){
  549. root = this.store.tree.root;
  550. me.updateNodes = [];
  551. }
  552. if(root.childNodes.length > 0){
  553. Ext.each(root.childNodes, function(){
  554. if(this.dirty){
  555. if(this.data['dc_id'] != null && this.data['dc_id'] != ''){
  556. me.updateNodes.push(this);
  557. }
  558. }
  559. if(this.data['leaf'] == false && this.childNodes.length > 0){
  560. me.getUpdateNodes(this);
  561. }
  562. });
  563. } else {
  564. if(root.dirty){
  565. if(root.data['dc_id'] != null && root.data['dc_id'] != ''){
  566. me.updateNodes.push(root);
  567. }
  568. }
  569. }
  570. },
  571. getActiveTab: function(){
  572. var tab = null;
  573. if(Ext.getCmp("content-panel")){
  574. tab = Ext.getCmp("content-panel").getActiveTab();
  575. }
  576. if(!tab){
  577. var win = parent.Ext.ComponentQuery.query('window');
  578. if(win.length > 0){
  579. tab = win[win.length-1];
  580. }
  581. }
  582. if(!tab && parent.Ext.getCmp("content-panel"))
  583. tab = parent.Ext.getCmp("content-panel").getActiveTab();
  584. if(!tab && parent.parent.Ext.getCmp("content-panel"))
  585. tab = parent.parent.Ext.getCmp("content-panel").getActiveTab();
  586. return tab;
  587. },
  588. getExpandedItems: function(record){
  589. var me = this;
  590. me.getRecordParents(record);
  591. if(record.isExpanded()){
  592. } else {
  593. me.expandedNodes.push(record);
  594. }
  595. },
  596. getRecordParents: function(record, parent){
  597. var me = this;
  598. if(!parent){
  599. parent = me.store.tree.root;
  600. me.expandedNodes = [];
  601. }
  602. if(parent.childNodes.length > 0){
  603. Ext.each(parent.childNodes, function(){
  604. if(this.isExpanded()){
  605. me.expandedNodes.push(this);
  606. if(this.childNodes.length > 0){
  607. me.getRecordParents(record, this);
  608. }
  609. }
  610. });
  611. }
  612. },
  613. getDocumentListPower: function(id){
  614. var o = new Object();
  615. Ext.Ajax.request({//拿到grid的columns
  616. url : basePath + 'hr/employee/getJobDocumentListPower.action',
  617. params: {
  618. dcl_id: id,
  619. em_id: em_uu
  620. },
  621. method : 'post',
  622. async: false,
  623. callback : function(options, success, response){
  624. parent.Ext.getCmp("content-panel").getActiveTab().setLoading(false);
  625. var res = new Ext.decode(response.responseText);
  626. if(res.exceptionInfo){
  627. showError(res.exceptionInfo);return;
  628. }
  629. if(!res.success){
  630. return;
  631. } else {
  632. // alert(o.DELETE);
  633. o.see = res.documentlistpower == null ? 0 : res.documentlistpower.dlp_see;
  634. o.edit = res.documentlistpower == null ? 0 : res.documentlistpower.dlp_edit;
  635. o.share = res.documentlistpower == null ? 0 : res.documentlistpower.dlp_share;
  636. o.del = res.documentlistpower == null ? 0 : res.documentlistpower.dlp_delete;
  637. o.download = res.documentlistpower == null ? 0 : res.documentlistpower.dlp_download;
  638. o.journal = res.documentlistpower == null ? 0 : res.documentlistpower.dlp_journal;
  639. }
  640. }
  641. });
  642. return o;
  643. }
  644. });