JCTreeGrid.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /**
  2. * ERP项目gridpanel样式5:sysNavigation专用treegrid
  3. */
  4. Ext.define('erp.view.oa.myProcess.jprocessDeploy.JCTreeGrid',{
  5. extend: 'Ext.tree.Panel',
  6. alias: 'widget.erpJCTreeGrid',
  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. saveNodes: [],
  15. updateNodes: [],
  16. deleteNodes: [],
  17. store: Ext.create('Ext.data.TreeStore', {
  18. fields: [{"name":"jd_selfId","type":"string"},
  19. {"name":"jd_classifiedName","type":"string"},
  20. {"name":"jd_parentId","type":"string"},
  21. {"name":"jd_formUrl","type":"string"},
  22. {"name":"jd_caller","type":"string"},
  23. {"name":"jd_processDefinitionId","type":"string"},
  24. {"name":"jd_processDefinitionName","type":"string"},
  25. {"name":"jd_processDescription","type":"string",},
  26. {"name":"jd_enabled","type":"boolean"}],
  27. root : {
  28. text: 'root',
  29. id: 'root',
  30. expanded: true
  31. }
  32. }),
  33. columns : [ {
  34. "header" : "ID",
  35. "dbfind" : "",
  36. "cls" : "x-grid-header-1",
  37. "summaryType" : "",
  38. "dataIndex" : "jd_selfId",
  39. "align" : "left",
  40. "xtype" : "treecolumn",
  41. "readOnly" : false,
  42. "hidden" : true,
  43. "text" : "ID"
  44. }, {
  45. "header" : "流程类别",
  46. "dbfind" : "",
  47. "cls" : "x-grid-header-1",
  48. "summaryType" : "",
  49. "dataIndex" : "jd_classifiedName",
  50. "align" : "left",
  51. "xtype" : "treecolumn",
  52. "readOnly" : false,
  53. "hidden" : false,
  54. "width" : 280.0,
  55. "text" : "流程类别",
  56. "editor" : {
  57. "xtype" : "textfield"
  58. }
  59. }, {
  60. "header" : "父节点ID",
  61. "dbfind" : "",
  62. "cls" : "x-grid-header-1",
  63. "summaryType" : "",
  64. "dataIndex" : "jd_parentId",
  65. "align" : "left",
  66. "xtype" : "treecolumn",
  67. "readOnly" : false,
  68. "hidden" : true,
  69. "width" : 0.0,
  70. "text" : "父节点ID"
  71. }, {
  72. "header" : "表单路径",
  73. "dbfind" : "",
  74. "cls" : "x-grid-header-1",
  75. "summaryType" : "",
  76. "dataIndex" : "jd_formUrl",
  77. "align" : "left",
  78. "readOnly" : false,
  79. "hidden" : true,
  80. "width" : 280.0,
  81. "text" : "表单路径",
  82. "editor" : {
  83. "xtype" : "textfield"
  84. }
  85. }, {
  86. "header" : "对应Caller",
  87. "dbfind" : "",
  88. "cls" : "x-grid-header-1",
  89. "summaryType" : "",
  90. "dataIndex" : "jd_caller",
  91. "align" : "left",
  92. "readOnly" : false,
  93. "hidden" : true,
  94. "width" : 150.0,
  95. "text" : "对应Caller",
  96. "editor" : {
  97. "xtype" : "textfield"
  98. }
  99. }, {
  100. "header" : "流程定义ID",
  101. "dbfind" : "",
  102. "cls" : "x-grid-header-1",
  103. "summaryType" : "",
  104. "dataIndex" : "jd_processDefinitionId",
  105. "align" : "left",
  106. //"xtype" : "checkcolumn",
  107. "readOnly" : false,
  108. "hidden" : true,
  109. "width" : 80.0,
  110. "text" : "流程定义ID",
  111. "editor" : {
  112. ///"cls" : "x-grid-checkheader-editor",
  113. //"xtype" : "checkbox"
  114. "xtype" : "textfield"
  115. }
  116. }, {
  117. "header" : "流程名称",
  118. "dbfind" : "",
  119. "cls" : "x-grid-header-1",
  120. "summaryType" : "",
  121. "dataIndex" : "jd_processDefinitionName",
  122. "align" : "right",
  123. "readOnly" : false,
  124. "hidden" : true,
  125. "width" : 80.0,
  126. "text" : "流程名称",
  127. "editor" : {
  128. "xtype" : "textfield"
  129. /*"cls" : "x-grid-checkheader-editor",
  130. "xtype" : "combo",
  131. "store" : Ext.create('Ext.data.Store', {
  132. fields : [ 'display', 'value' ],
  133. data : [ {
  134. "display" : "选项卡模式",
  135. "value" : 0
  136. }, {
  137. "display" : "弹出框式",
  138. "value" : 1
  139. }, {
  140. "display" : "空白页",
  141. "value" : 2
  142. }, {
  143. "display" : "窗口模式",
  144. "value" : 3
  145. } ]
  146. }),
  147. "displayField" : 'display',
  148. "valueField" : 'value',
  149. "queryMode" : 'local',
  150. "value" : 0*/
  151. }/*,*/
  152. /*"renderer" : function(val){
  153. var rVal = "选项卡模式";
  154. val = val || 0;
  155. switch (Number(val)) {
  156. case 0:
  157. rVal = "选项卡模式";break;
  158. case 1:
  159. rVal = "弹出框式";break;
  160. case 2:
  161. rVal = "空白页";break;
  162. case 3:
  163. rVal = "窗口模式";break;
  164. }
  165. return rVal;
  166. }*/
  167. }, {
  168. "header" : "流程描述",
  169. "dbfind" : "",
  170. "cls" : "x-grid-header-1",
  171. "summaryType" : "",
  172. "dataIndex" : "jd_processDescription",
  173. "align" : "left",
  174. //"xtype" : "checkcolumn",
  175. "readOnly" : false,
  176. "hidden" : true,
  177. "width" : 90.0,
  178. "text" : "流程描述",
  179. "editor" : {
  180. "xtype":"textfield"
  181. //"cls" : "x-grid-checkheader-editor",
  182. //"xtype" : "checkbox"
  183. }
  184. }, {
  185. "header" : "是否启用",
  186. "dbfind" : "",
  187. "cls" : "x-grid-header-1",
  188. "summaryType" : "",
  189. "dataIndex" : "jd_enabled",
  190. "align" : "left",
  191. "xtype" : "checkcolumn",
  192. "readOnly" : false,
  193. "hidden" : true,
  194. "width" : 70.0,
  195. "text" : "是否启用",
  196. "editor" : {
  197. "cls" : "x-grid-checkheader-editor",
  198. "xtype" : "checkbox"
  199. }
  200. } ],
  201. bodyStyle:'background-color:#f1f1f1;',
  202. initComponent : function(){
  203. Ext.override(Ext.data.AbstractStore,{
  204. indexOf: Ext.emptyFn
  205. });
  206. this.callParent(arguments);
  207. this.getTreeGridNode({parentId: 0});
  208. },
  209. listeners: {//滚动条有时候没反应,添加此监听器
  210. scrollershow: function(scroller) {
  211. if (scroller && scroller.scrollEl) {
  212. scroller.clearManagedListeners();
  213. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  214. }
  215. }
  216. },
  217. getTreeGridNode: function(param){
  218. var me = this;
  219. var activeTab = me.getActiveTab();
  220. activeTab.setLoading(true);
  221. Ext.Ajax.request({//拿到tree数据
  222. url : basePath + 'common/getLazyJProcessDeploy.action',
  223. params: param,
  224. callback : function(options,success,response){
  225. var res = new Ext.decode(response.responseText);
  226. activeTab.setLoading(false);
  227. if(res.tree){
  228. var tree = res.tree;
  229. Ext.each(tree, function(t){
  230. t.jd_selfId = t.id;
  231. t.jd_parentId = t.parentId;
  232. t.jd_classifiedName = t.text;
  233. // t.sn_isleaf = t.leaf;
  234. t.jd_caller = t.creator;
  235. t.jd_formUrl = t.url;
  236. t.jd_processDefinitionId = t.qtitle;
  237. t.jd_enabled = t.using;
  238. t.jd_processDefinitionName = t.version;
  239. });
  240. me.store.setRootNode({
  241. text: 'root',
  242. id: 'root',
  243. expanded: true,
  244. children: tree
  245. });
  246. Ext.each(me.store.tree.root.childNodes, function(){
  247. this.dirty = false;
  248. });
  249. } else if(res.exceptionInfo){
  250. showError(res.exceptionInfo);
  251. }
  252. }
  253. });
  254. },
  255. checkChild: function(record){
  256. var me = this;
  257. if(!record.data['leaf']){
  258. if(record.childNodes.length > 0){
  259. if(record.data['sn_id'] == null || record.data['sn_id'] == ''){
  260. warnMsg('如果在节点' + record.data['sn_id'] + '下添加子节点,需先保存该节点,是否保存?', function(btn){
  261. if(btn == 'yes'){
  262. if(items[0].data['sn_displayname'] == null || items[0].data['sn_displayname'] == ''){
  263. showError('请先描述该节点');
  264. return;
  265. } else {
  266. me.saveNodes.push(items[0]);
  267. me.saveNode();
  268. }
  269. } else if(btn == 'no'){
  270. return;
  271. }
  272. });
  273. }
  274. Ext.each(record.childNodes, function(){
  275. me.checkChild(this);
  276. });
  277. }
  278. } else {
  279. if(record.dirty){
  280. if(record.data['sn_id'] == null || record.data['sn_id'] == ''){
  281. me.saveNodes.push(record);
  282. } else {
  283. me.updateNodes.push(record);
  284. }
  285. }
  286. }
  287. },
  288. saveNode: function(){
  289. var me = this;
  290. me.getUpdateNodes();
  291. var save = new Array();
  292. var update = new Array();
  293. var index = 0;
  294. Ext.each(me.saveNodes, function(){
  295. if(this.data.sn_displayname != null && this.data.sn_displayname != ''){
  296. if(this.data.sn_tabtitle == null || this.data.sn_tabtitle == ''){
  297. this.data.sn_tabtitle == this.data.sn_displayname;
  298. }
  299. if(this.data.sn_deleteable == null || this.data.sn_deleteable == ''){
  300. this.data.sn_deleteable == 'T';
  301. }
  302. var o = {
  303. sn_id: this.data.sn_id,
  304. sn_displayname: this.data.sn_displayname,
  305. sn_url: this.data.sn_url,
  306. sn_isleaf: this.data.sn_isleaf ? 'T' : 'F',
  307. sn_tabtitle: this.data.sn_tabtitle,
  308. sn_parentid: this.data.sn_parentid,
  309. sn_deleteable: this.data.sn_deleteable ? 'T' : 'F',
  310. sn_using: this.data.sn_using ? 1 : 0,
  311. sn_showmode: this.data.sn_showmode
  312. };
  313. save[index++] = Ext.JSON.encode(o);
  314. }
  315. });
  316. index = 0;
  317. Ext.each(me.updateNodes, function(){
  318. if(this.data.sn_displayname != null && this.data.sn_displayname != ''){
  319. if(this.data.sn_tabtitle == null || this.data.sn_tabtitle == ''){
  320. this.data.sn_tabtitle == this.data.sn_displayname;
  321. }
  322. if(this.data.sn_deleteable == null || this.data.sn_deleteable == ''){
  323. this.data.sn_deleteable == 'T';
  324. }
  325. var o = {
  326. sn_id: this.data.sn_id,
  327. sn_displayname: this.data.sn_displayname,
  328. sn_url: this.data.sn_url,
  329. sn_isleaf: this.data.sn_isleaf ? 'T' : 'F',
  330. sn_tabtitle: this.data.sn_tabtitle,
  331. sn_parentid: this.data.sn_parentid,
  332. sn_deleteable: this.data.sn_deleteable ? 'T' : 'F',
  333. sn_using: this.data.sn_using ? 1 : 0,
  334. sn_showmode: this.data.sn_showmode
  335. };
  336. update[index++] = Ext.JSON.encode(o);
  337. }
  338. });
  339. if(save.length > 0 || update.length > 0){
  340. var activeTab = me.getActiveTab();
  341. activeTab.setLoading(true);
  342. Ext.Ajax.request({
  343. url : basePath + 'ma/saveSysNavigation.action',
  344. params: {
  345. save: unescape(save.toString().replace(/\\/g,"%")),
  346. update: unescape(update.toString().replace(/\\/g,"%"))
  347. },
  348. callback : function(options,success,response){
  349. var res = new Ext.decode(response.responseText);
  350. activeTab.setLoading(false);
  351. if(res.success){
  352. me.saveNodes = [];
  353. me.updateNodes = [];
  354. me.getTreeGridNode({parentId: 0});
  355. } else if(res.exceptionInfo){
  356. showError(res.exceptionInfo);
  357. }
  358. }
  359. });
  360. }
  361. },
  362. getExpandItem: function(root){
  363. var me = this;
  364. if(!root){
  365. root = this.store.tree.root;
  366. }
  367. var node = null;
  368. if(root.childNodes.length > 0){
  369. Ext.each(root.childNodes, function(){
  370. if(this.isExpanded()){
  371. node = this;
  372. if(this.childNodes.length > 0){
  373. var n = me.getExpandItem(this);
  374. node = n == null ? node : n;
  375. }
  376. }
  377. });
  378. }
  379. return node;
  380. },
  381. deleteNode: function(record){
  382. var me = this;
  383. if(record){
  384. var activeTab = me.getActiveTab();
  385. activeTab.setLoading(true);
  386. Ext.Ajax.request({
  387. url : basePath + 'ma/deleteSysNavigation.action',
  388. params: {
  389. id: Number(record.data['sn_id'])
  390. },
  391. callback : function(options,success,response){
  392. var res = new Ext.decode(response.responseText);
  393. activeTab.setLoading(false);
  394. if(res.success){
  395. record.remove(true);
  396. } else if(res.exceptionInfo){
  397. showError(res.exceptionInfo);
  398. }
  399. }
  400. });
  401. }
  402. },
  403. getUpdateNodes: function(root){
  404. var me = this;
  405. if(!root){
  406. root = this.store.tree.root;
  407. me.updateNodes = [];
  408. }
  409. if(root.childNodes.length > 0){
  410. Ext.each(root.childNodes, function(){
  411. if(this.dirty){
  412. if(this.data['sn_id'] != null && this.data['sn_id'] != ''){
  413. me.updateNodes.push(this);
  414. }
  415. }
  416. if(this.data['leaf'] == false && this.childNodes.length > 0){
  417. me.getUpdateNodes(this);
  418. }
  419. });
  420. } else {
  421. if(root.dirty){
  422. if(root.data['sn_id'] != null && root.data['sn_id'] != ''){
  423. me.updateNodes.push(root);
  424. }
  425. }
  426. }
  427. },
  428. getActiveTab: function(){
  429. var tab = null;
  430. if(Ext.getCmp("content-panel")){
  431. tab = Ext.getCmp("content-panel").getActiveTab();
  432. }
  433. if(!tab){
  434. var win = parent.Ext.ComponentQuery.query('window');
  435. if(win.length > 0){
  436. tab = win[win.length-1];
  437. }
  438. }
  439. if(!tab && parent.Ext.getCmp("content-panel"))
  440. tab = parent.Ext.getCmp("content-panel").getActiveTab();
  441. if(!tab && parent.parent.Ext.getCmp("content-panel"))
  442. tab = parent.parent.Ext.getCmp("content-panel").getActiveTab();
  443. return tab;
  444. },
  445. /**
  446. * treegrid用到了checkcolumn时,由于其store的差异,根据recordIndex不能直接得到record,
  447. * 采用下面的方法可以在点击checkbox时,得到当前的record,再进而就可以修改checkbox的check属性等...
  448. */
  449. getRecordByRecordIndex: function(recordIndex, node){
  450. var me = this;
  451. if(!node){
  452. node = this.store.tree.root;
  453. me.findIndex = 0;
  454. me.findRecord = null;
  455. }
  456. if(me.findRecord == null){
  457. if(node.childNodes.length > 0 && node.isExpanded()){
  458. Ext.each(node.childNodes, function(){
  459. if(me.findIndex == recordIndex){
  460. me.findRecord = this;
  461. me.findIndex++;
  462. } else {
  463. me.findIndex++;
  464. me.getRecordByRecordIndex(recordIndex, this);
  465. }
  466. });
  467. } else {
  468. if(me.findIndex == recordIndex){
  469. me.findRecord = node;
  470. }
  471. }
  472. }
  473. },
  474. checkRecord: function(record, dataIndex, checked){
  475. var me = this;
  476. if(record.childNodes.length > 0){
  477. Ext.each(record.childNodes, function(){
  478. this.set(dataIndex, checked);
  479. me.checkRecord(this, dataIndex, checked);
  480. });
  481. }
  482. }
  483. });