Power.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.ma.Power', {
  3. extend : 'Ext.app.Controller',
  4. views : [ 'ma.Power', 'core.button.Distribute', 'core.grid.GroupPower', 'core.trigger.DbfindTrigger',
  5. 'core.trigger.EmpTrigger', 'core.button.Sync', 'core.trigger.MultiDbfindTrigger' ],
  6. init : function() {
  7. var me = this;
  8. this.control({
  9. 'treepanel[id=powertree]' : {
  10. afterrender : function(tree) {
  11. me.loadTree(tree);
  12. },
  13. itemmousedown : function(selModel, record) {
  14. var tree = selModel.ownerCt;
  15. me.loadTree(tree, record);
  16. },
  17. scrollershow: function(scroller) {
  18. if (scroller && scroller.scrollEl) {
  19. scroller.clearManagedListeners();
  20. scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
  21. }
  22. }
  23. },
  24. 'button[id=personal_set]' : {// 个人权限设置
  25. click : function(btn) {
  26. var grid = btn.ownerCt.ownerCt;
  27. if (grid.pp_caller) {
  28. me.showPersonal(grid);
  29. }
  30. }
  31. },
  32. 'button[id=special_set]': {// 设置特殊权限
  33. click: function(btn) {
  34. var grid = btn.ownerCt.ownerCt;
  35. if (grid.pp_caller) {
  36. me.showSpecial(grid);
  37. }
  38. }
  39. },
  40. 'button[id=power_copy]': {// 复制权限
  41. click: function(btn) {
  42. me.showCopyPane();
  43. }
  44. },
  45. 'button[id=power_sync]': {// 同步权限
  46. click: function(btn) {
  47. this.showSyncWin();
  48. }
  49. },
  50. 'multidbfindtrigger[name=em_position]': {
  51. aftertrigger: function(t, rs) {
  52. if(rs.length > 0) {
  53. var m = t.ownerCt;
  54. Ext.Array.each(rs, function(r, i){
  55. if(i == 0) {
  56. t.jo_id = r.get('jo_id');
  57. t.setValue(r.get('jo_name'));
  58. } else {
  59. m.insert(m.items.length - 2, {
  60. xtype: 'multidbfindtrigger',
  61. name: 'em_position',
  62. fieldLabel: '复制到',
  63. jo_id: r.get('jo_id'),
  64. value: r.get('jo_name'),
  65. p: 2,
  66. editable: false,
  67. autoDbfind: false,
  68. clearable: true
  69. });
  70. }
  71. });
  72. } else {
  73. f.setValue(null);
  74. f.jo_id = null;
  75. }
  76. }
  77. }
  78. });
  79. },
  80. loadTree : function(tree, record) {
  81. var pid = 0, me = this;
  82. if (record) {
  83. if (record.get('leaf')) {
  84. me.loadPower(record);
  85. return;
  86. } else {
  87. if (record.isExpanded() && record.childNodes.length > 0) {
  88. record.collapse(true, true);// 收拢
  89. return;
  90. } else {
  91. if (record.childNodes.length != 0) {
  92. record.expand(false, true);// 展开
  93. return;
  94. }
  95. }
  96. }
  97. pid = record.get('id');
  98. }
  99. tree.setLoading(true);
  100. Ext.Ajax.request({
  101. url : basePath + 'ma/lazyTree.action',
  102. params : {
  103. parentId : pid,
  104. condition : 'sn_limit=1'
  105. },
  106. callback : function(options, success, response) {
  107. tree.setLoading(false);
  108. var res = new Ext.decode(response.responseText);
  109. if (res.tree) {
  110. if (record) {
  111. record.appendChild(res.tree);
  112. record.expand(false, true);// 展开
  113. } else {
  114. tree.store.setRootNode({
  115. text : 'root',
  116. id : 'root',
  117. expanded : true,
  118. children : res.tree
  119. });
  120. }
  121. } else if (res.exceptionInfo) {
  122. showError(res.exceptionInfo);
  123. }
  124. }
  125. });
  126. },
  127. loadPower : function(record) {
  128. var caller = record.get('caller'), set = Ext.getCmp('grid');
  129. set.pp_caller = caller;
  130. set.down('tbtext').setText('<font color=gray>权限名:</font>' + record.get('text'));
  131. if (!Ext.isEmpty(caller)) {
  132. set.getGroupData(this.getUrlType(record.get('url')));
  133. } else {
  134. set.store.removeAll();
  135. }
  136. },
  137. getUrlType : function(url) {
  138. if (contains(url, 'datalist.jsp') || contains(url, 'editDatalist.jsp') || contains(url, 'vastDatalist.jsp')
  139. || contains(url, 'turnGoodsSend.jsp') || contains(url, 'turnEstimate.jsp')) {
  140. return 'list';
  141. } else if (contains(url, 'batchDeal.jsp') || contains(url, 'query.jsp') || contains(url, 'print.jsp')
  142. || contains(url, 'batchPrint.jsp') || contains(url, 'gridPage.jsp')) {
  143. return 'deal';
  144. }
  145. return null;
  146. },
  147. showPersonal : function(grid) {
  148. var me = this;
  149. var win = Ext.getCmp('emp-win');
  150. if (!win) {
  151. win = Ext.create('Ext.Window', {
  152. id : 'emp-win',
  153. width : 500,
  154. height : 360,
  155. title : '员工',
  156. modal : true,
  157. layout: 'anchor',
  158. items : [ {
  159. xtype : 'gridpanel',
  160. anchor: '100% 100%',
  161. columnLines : true,
  162. columns : [ {
  163. text : 'ID',
  164. dataIndex : 'em_id',
  165. hidden : true
  166. }, {
  167. text : '编号',
  168. dataIndex : 'em_code',
  169. flex : 1,
  170. editor : {
  171. xtype : 'emptrigger'
  172. },
  173. dbfind : 'Employee|em_code'
  174. }, {
  175. text : '姓名',
  176. dataIndex : 'em_name',
  177. flex : 1
  178. }, {
  179. text : '部门',
  180. dataIndex : 'em_depart',
  181. flex : 1
  182. }, {
  183. text : '岗位',
  184. dataIndex : 'em_position',
  185. flex : 1
  186. } ],
  187. store : new Ext.data.Store({
  188. fields : [ {
  189. name : 'em_id',
  190. type : 'number'
  191. }, 'em_code', 'em_depart', 'em_defaulthsname' ],
  192. data : [ {}, {}, {}, {}, {}, {}, {}, {}, {}, {} ]
  193. }),
  194. plugins : [ Ext.create('Ext.grid.plugin.CellEditing', {
  195. clicksToEdit : 1
  196. }) ],
  197. dbfinds : [ {
  198. field : 'em_id',
  199. dbGridField : 'em_id'
  200. }, {
  201. field : 'em_code',
  202. dbGridField : 'em_code'
  203. }, {
  204. field : 'em_name',
  205. dbGridField : 'em_name'
  206. }, {
  207. field : 'em_depart',
  208. dbGridField : 'em_depart'
  209. }, {
  210. field : 'em_position',
  211. dbGridField : 'em_position'
  212. } ],
  213. listeners : {
  214. itemclick : function(selModel, record) {
  215. var grid = selModel.ownerCt, store = grid.store, idx = store.indexOf(record), len = store
  216. .getCount();
  217. if (idx == len - 1) {
  218. store.add([ {}, {}, {}, {}, {} ]);
  219. }
  220. }
  221. }
  222. } ],
  223. buttonAlign: 'center',
  224. buttons: [{
  225. text: $I18N.common.button.erpConfirmButton,
  226. iconCls: 'x-btn-confirm',
  227. handler: function(btn) {
  228. me.getPersonalPower(grid, btn.ownerCt.ownerCt.down('gridpanel'));
  229. btn.ownerCt.ownerCt.hide();
  230. }
  231. },{
  232. text: $I18N.common.button.erpCloseButton,
  233. iconCls: 'x-btn-close',
  234. handler: function(btn) {
  235. btn.ownerCt.ownerCt.hide();
  236. }
  237. }]
  238. });
  239. }
  240. win.show();
  241. },
  242. getPersonalPower: function(grid, gl) {
  243. var em = new Array();
  244. gl.store.each(function(r){
  245. if(!Ext.isEmpty(r.get('em_id')) && r.get('em_id') > 0) {
  246. em.push({em_id: r.get('em_id'), em_name: r.get('em_name')});
  247. }
  248. });
  249. grid.getPersonalData(grid.urlType, em);
  250. },
  251. showSpecial: function(grid) {
  252. var me = this, cal = grid.pp_caller;
  253. var win = Ext.getCmp('special-win-' + cal);
  254. if (!win) {
  255. win = Ext.create('Ext.Window', {
  256. id : 'special-win-' + cal,
  257. width : 500,
  258. height : 360,
  259. title : '特殊权限',
  260. modal : true,
  261. layout: 'anchor',
  262. items: [{
  263. xtype: 'gridpanel',
  264. anchor: '100% 100%',
  265. columnLines : true,
  266. columns : [ {
  267. text : 'ID',
  268. dataIndex : 'ssp_id',
  269. hidden : true
  270. }, {
  271. text : 'caller',
  272. dataIndex : 'ssp_caller',
  273. hidden : true
  274. }, {
  275. text : '描述',
  276. dataIndex : 'ssp_desc',
  277. flex : 1,
  278. editor: {
  279. xtype: 'textfield'
  280. }
  281. }, {
  282. text : '链接',
  283. dataIndex : 'ssp_action',
  284. flex : 1,
  285. editor: {
  286. xtype: 'textfield'
  287. }
  288. } ],
  289. store : new Ext.data.Store({
  290. fields : [ {
  291. name : 'ssp_id',
  292. type : 'number'
  293. }, 'ssp_caller', 'ssp_desc', 'ssp_action' ],
  294. data : [ {}, {}, {}, {}, {}, {}, {}, {}, {}, {} ]
  295. }),
  296. plugins : [ Ext.create('Ext.grid.plugin.CellEditing', {
  297. clicksToEdit : 1
  298. }) ],
  299. listeners : {
  300. itemclick : function(selModel, record) {
  301. var grid = selModel.ownerCt, store = grid.store, idx = store.indexOf(record), len = store
  302. .getCount();
  303. if (idx == len - 1) {
  304. store.add([ {}, {}, {}, {}, {} ]);
  305. }
  306. }
  307. }
  308. }],
  309. buttonAlign: 'center',
  310. buttons: [{
  311. text: $I18N.common.button.erpSaveButton,
  312. iconCls: 'x-btn-save',
  313. handler: function(btn) {
  314. me.saveSysSpecials(cal, btn.ownerCt.ownerCt.down('gridpanel'));
  315. btn.ownerCt.ownerCt.hide();
  316. }
  317. },{
  318. text: $I18N.common.button.erpCloseButton,
  319. iconCls: 'x-btn-close',
  320. handler: function(btn) {
  321. btn.ownerCt.ownerCt.hide();
  322. }
  323. }]
  324. });
  325. }
  326. win.show();
  327. this.getSysSpecialPowers(cal, win.down('grid'));
  328. },
  329. getSysSpecialPowers: function(cal, grid) {
  330. Ext.Ajax.request({
  331. url: basePath + 'ma/power/getSysSpecialPowers.action',
  332. params: {
  333. caller: cal
  334. },
  335. callback: function(opt, s, r) {
  336. var rs = Ext.decode(r.responseText);
  337. if(rs.exceptionInfo) {
  338. showError(rs.exceptionInfo);
  339. } else if(rs.data){
  340. grid.store.loadData(rs.data);
  341. }
  342. }
  343. });
  344. },
  345. saveSysSpecials: function(cal, grid) {
  346. var data = new Array();
  347. grid.store.each(function(item){
  348. if(item.dirty) {
  349. if((!Ext.isEmpty(item.get('ssp_desc')) && !Ext.isEmpty(item.get('ssp_action'))) ||
  350. (item.get('ssp_id') > 0)) {
  351. item.data.ssp_caller = cal;
  352. data.push(item.data);
  353. }
  354. }
  355. });
  356. if(data.length > 0) {
  357. Ext.Ajax.request({
  358. url: basePath + 'ma/power/saveSysSpecialPowers.action',
  359. params: {
  360. caller: cal,
  361. data: unescape(Ext.encode(data).replace(/\\/g,"%"))
  362. },
  363. callback: function(opt, s, r) {
  364. var rs = Ext.decode(r.responseText);
  365. if(rs.exceptionInfo) {
  366. showError(rs.exceptionInfo);
  367. } else if(rs.data){
  368. grid.store.loadData(rs.data);
  369. }
  370. }
  371. });
  372. }
  373. },
  374. showCopyPane: function(grid) {
  375. var me = this, win = Ext.create('Ext.Window', {
  376. width : 500,
  377. height: 300,
  378. title : '复制权限',
  379. modal : true,
  380. layout: 'anchor',
  381. items: [{
  382. xtype: 'container',
  383. anchor: '100% 100%',
  384. autoScroll: true,
  385. layout: 'column',
  386. padding: '10',
  387. defaults: {
  388. labelWidth: 60,
  389. columnWidth: 1,
  390. margin: '3 10 3 10'
  391. },
  392. items: [{
  393. xtype: 'dbfindtrigger',
  394. fieldLabel: '从',
  395. name: 'em_position',
  396. p: 1,
  397. editable: false,
  398. autoDbfind: false,
  399. clearable: true,
  400. listeners: {
  401. aftertrigger: function(f, r) {
  402. f.jo_id = r.get('jo_id');
  403. f.setValue(r.get('jo_name'));
  404. }
  405. }
  406. },{
  407. xtype: 'multidbfindtrigger',
  408. name: 'em_position',
  409. fieldLabel: '复制到',
  410. p: 2,
  411. editable: false,
  412. autoDbfind: false,
  413. clearable: true
  414. },{
  415. xtype: 'displayfield',
  416. columnWidth: .75
  417. },{
  418. xtype: 'button',
  419. text: '添加',
  420. columnWidth: .25,
  421. cls: 'x-dd-drop-ok-add',
  422. iconCls: 'x-dd-drop-icon',
  423. iconAlign: 'right',
  424. handler: function(btn) {
  425. var f = btn.ownerCt;
  426. f.insert(f.items.length - 2, {
  427. xtype: 'multidbfindtrigger',
  428. name: 'em_position',
  429. fieldLabel: '复制到',
  430. p: 2,
  431. editable: false,
  432. autoDbfind: false,
  433. clearable: true
  434. });
  435. }
  436. }]
  437. }],
  438. buttonAlign: 'center',
  439. buttons: [{
  440. text: $I18N.common.button.erpSaveButton,
  441. cls: 'x-btn-blue',
  442. handler: function(btn) {
  443. Ext.MessageBox.show({
  444. title: $I18N.common.msg.title_prompt,
  445. msg: '目标岗位的权限将会被指定岗位覆盖,确定复制?',
  446. buttons: Ext.Msg.YESNO,
  447. icon: Ext.Msg.WARNING,
  448. fn: function(b){
  449. if(b == 'ok' || b == 'yes') {
  450. var w = btn.ownerCt.ownerCt,
  451. from = w.down('dbfindtrigger[p=1]'),
  452. to = w.query('multidbfindtrigger[p=2]'), tos = [];
  453. Ext.Array.each(to, function(t){
  454. if(!Ext.isEmpty(t.getValue()))
  455. tos.push(t.jo_id);
  456. });
  457. if(tos.length > 0)
  458. me.copyPower(from.jo_id, tos.join(','));
  459. w.hide();
  460. }
  461. }
  462. });
  463. }
  464. },{
  465. text: $I18N.common.button.erpCloseButton,
  466. cls: 'x-btn-blue',
  467. handler: function(btn) {
  468. btn.ownerCt.ownerCt.hide();
  469. }
  470. }]
  471. });
  472. win.show();
  473. },
  474. showSyncWin: function() {
  475. var me = this, win = Ext.create('Ext.Window', {
  476. title: '权限同步',
  477. width: 300,
  478. height: 300,
  479. defaults: {
  480. margin: '3 10 10 5'
  481. },
  482. items: [{
  483. xtype: 'radio',
  484. name: 'synctype',
  485. boxLabel: '按岗位同步',
  486. checked: true,
  487. listeners: {
  488. change: function(f) {
  489. f.ownerCt.down('dbfindtrigger[name=em_position]').setDisabled(!f.value);
  490. }
  491. }
  492. },{
  493. xtype: 'multidbfindtrigger',
  494. name: 'em_position',
  495. editable: false,
  496. fieldLabel: '岗位名称',
  497. listeners: {
  498. aftertrigger: function(f, rs) {
  499. var jo_id = null, name = null;
  500. var p = f.ownerCt.down('field[name=positions]'),
  501. j = p.jobs || new Array(), d = p.descs || new Array();
  502. if(rs && rs.length > 0) {
  503. Ext.each(rs, function(){
  504. jo_id = this.get('jo_id');
  505. name = this.get('jo_name');
  506. if(!Ext.Array.contains(j, jo_id)) {
  507. j.push(jo_id);
  508. d.push(name);
  509. }
  510. });
  511. }
  512. p.jobs = j;
  513. p.descs = d;
  514. p.setValue(d.join('\t'));
  515. f.setValue(null);
  516. f.up('window').down('erpSyncButton[itemId=sync]').syncdatas = j.join(',');
  517. }
  518. }
  519. },{
  520. xtype : 'displayfield',
  521. name: 'positions',
  522. width: 280
  523. },{
  524. xtype: 'radio',
  525. name: 'synctype',
  526. boxLabel: '按个人同步',
  527. listeners: {
  528. change: function(f) {
  529. f.ownerCt.down('dbfindtrigger[name=em_code]').setDisabled(!f.value);
  530. }
  531. }
  532. },{
  533. xtype: 'dbfindtrigger',
  534. name: 'em_code',
  535. fieldLabel: '员工编号',
  536. disabled: true,
  537. listeners: {
  538. aftertrigger: function(f, r) {
  539. f.setValue(r.get('em_code'));
  540. }
  541. }
  542. }],
  543. buttonAlign: 'center',
  544. buttons: [{
  545. cls: 'x-btn-blue',
  546. xtype: 'erpSyncButton',
  547. itemId : 'sync',
  548. autoClearCache: true
  549. }, {
  550. text: $I18N.common.button.erpCloseButton,
  551. cls: 'x-btn-blue',
  552. handler: function(b) {
  553. b.up('window').hide();
  554. }
  555. }]
  556. });
  557. win.show();
  558. },
  559. getAllJobs : function(b) {
  560. Ext.Ajax.request({
  561. url : basePath + 'common/getFieldData.action',
  562. async: false,
  563. params: {
  564. caller: 'Job',
  565. field: 'wmsys.wm_concat(jo_id)',
  566. condition: '1=1'
  567. },
  568. method : 'post',
  569. callback : function(opt, s, res){
  570. var r = new Ext.decode(res.responseText);
  571. if(r.exceptionInfo){
  572. showError(r.exceptionInfo);
  573. } else if(r.success && r.data){
  574. b.syncdatas = r.data;
  575. }
  576. }
  577. });
  578. },
  579. copyPower : function(fid, tid) {
  580. if(fid != tid) {
  581. Ext.Ajax.request({
  582. url: basePath + 'ma/power/copypower.action',
  583. params: {
  584. f : fid,
  585. t : tid
  586. },
  587. callback : function(o, s, r) {
  588. if( s ) {
  589. var e = r.responseText;
  590. if(e == 'success') {
  591. alert('复制成功!');
  592. } else {
  593. alert(e);
  594. }
  595. }
  596. }
  597. });
  598. }
  599. }
  600. });