Config.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.ma.logic.Config', {
  3. extend: 'Ext.app.Controller',
  4. stores: ['TreeStore'],
  5. views: ['common.main.TreePanel','ma.logic.Config', 'core.form.ColorField',
  6. 'common.main.Toolbar','core.trigger.SearchField', 'core.trigger.DbfindTrigger'],
  7. refs: [{
  8. ref: 'tree',
  9. selector: '#tree-panel'
  10. },{
  11. ref: 'configPanel',
  12. selector: '#configPanel'
  13. },{
  14. ref: 'tabPanel',
  15. selector: '#tabpanel'
  16. }],
  17. init: function(){
  18. var me = this;
  19. me.FormUtil = Ext.create('erp.util.FormUtil');
  20. me.Toast = Ext.create('erp.view.core.window.Toast');
  21. this.control({
  22. 'erpTreePanel': {
  23. itemmousedown: function(selModel, record){
  24. Ext.defer(function(){
  25. me.onNodeClick(selModel, record);
  26. }, 20);
  27. },
  28. beforerender: function(tree) {
  29. if(window.whoami)
  30. tree.hide();
  31. }
  32. },
  33. '#configPanel': {
  34. boxready: function() {
  35. var caller = window.whoami || 'sys';
  36. me.getSetting(caller);
  37. }
  38. },
  39. 'button[id=btn-close]': {
  40. click: function(){
  41. var p = parent.Ext.getCmp('content-panel');
  42. if(p){
  43. p.getActiveTab().close();
  44. } else {
  45. window.close();
  46. }
  47. }
  48. },
  49. 'button[id=btn-save]': {
  50. click: function(btn){
  51. me.onSaveClick();
  52. }
  53. },
  54. 'dbfindtrigger': {
  55. aftertrigger: function(field, record, dbfinds) {
  56. Ext.Array.each(dbfinds, function(d){
  57. if(d.field == field.name) {
  58. field.setValue(record.get(d.dbGridField));
  59. }
  60. });
  61. }
  62. },
  63. 'button[cls=x-dd-drop-ok-add]': {
  64. click: function(btn) {
  65. var f = btn.ownerCt, c = btn.config;
  66. f.insert(f.items.length - 1, {
  67. xtype: (c.dbfind ? 'dbfindtrigger' : 'textfield'),
  68. name: c.dbfind || c.code,
  69. readOnly: !c.dbfind && c.editable == 0,
  70. editable: c.editable == 1,
  71. clearable: true
  72. });
  73. }
  74. }
  75. });
  76. },
  77. onNodeClick: function(selModel, record){
  78. var me = this;
  79. if (record.get('leaf')) {
  80. me.getSetting(record.raw.caller, record.get('text'));
  81. } else {
  82. if(record.isExpanded() && record.childNodes.length > 0){
  83. record.collapse(true, true);// 已展开则收拢
  84. } else {
  85. //未展开看是否加载了children
  86. if(record.childNodes.length == 0){
  87. me.getChildren(record);
  88. } else {
  89. record.expand(false, true);//展开
  90. }
  91. }
  92. }
  93. },
  94. /**
  95. * 从后台加载树节点
  96. */
  97. getChildren: function(record) {
  98. var tree = this.getTree();
  99. tree.setLoading(true, tree.body);
  100. Ext.Ajax.request({//拿到tree数据
  101. url : basePath + 'common/lazyTree.action',
  102. params: {
  103. parentId: record.get('id')
  104. },
  105. callback : function(opt, s, r){
  106. tree.setLoading(false);
  107. var res = new Ext.decode(r.responseText);
  108. if(res.tree && record.childNodes.length == 0){
  109. record.appendChild(res.tree);
  110. record.expand(false, true);//展开
  111. } else if(res.exceptionInfo){
  112. showError(res.exceptionInfo);
  113. }
  114. }
  115. });
  116. },
  117. getSetting: function(caller, title){
  118. var me = this;
  119. if(caller) {
  120. if(caller != me.currCaller) {
  121. me.loadConfigs(caller, function(configs){
  122. me.currCaller = caller;
  123. me.setConfigs(configs);
  124. title && me.getConfigPanel().setTitle(title);
  125. });
  126. me.loadInterceptors(caller, function(interceptors){
  127. me.setInterceptors(interceptors);
  128. var tab = me.getTabPanel();
  129. if(interceptors.length == 0 && !tab.collapsed)
  130. tab.collapse();
  131. else if(interceptors.length > 0 && tab.collapsed)
  132. tab.expand();
  133. });
  134. }
  135. } else {
  136. me.currCaller = null;
  137. }
  138. },
  139. /**
  140. * 配置参数
  141. */
  142. loadConfigs: function(caller, callback) {
  143. if(em_type!='admin'){
  144. showError('ERR_POWER_025:您没有修改业务配置的权限!');return;
  145. }
  146. Ext.Ajax.request({
  147. url: basePath + 'ma/setting/configs.action?caller=' + caller,
  148. method: 'GET',
  149. callback: function(opt, s, r) {
  150. if(r && r.status == 200) {
  151. var res = Ext.JSON.decode(r.responseText);
  152. callback.call(null, res);
  153. }
  154. }
  155. });
  156. },
  157. /**
  158. * 配置逻辑
  159. */
  160. loadInterceptors: function(caller, callback) {
  161. Ext.Ajax.request({
  162. url: basePath + 'ma/setting/interceptors.action?caller=' + caller,
  163. method: 'GET',
  164. callback: function(opt, s, r) {
  165. if(r && r.status == 200) {
  166. var res = Ext.JSON.decode(r.responseText);
  167. callback.call(null, res);
  168. }
  169. }
  170. });
  171. },
  172. setConfigs: function(configs) {
  173. var me = this, pane = me.getConfigPanel(), items = [];
  174. Ext.Array.each(configs, function(c, i){
  175. switch(c.data_type) {
  176. case 'YN':
  177. items.push({
  178. xtype: 'checkbox',
  179. boxLabel: c.title,
  180. name: c.code,
  181. id: c.id,
  182. checked: c.data == 1,
  183. columnWidth: 1,
  184. margin: c.help ? '4 8 0 8' : '4 8 4 8'
  185. });
  186. break;
  187. case 'RADIO':
  188. var s = [];
  189. Ext.Array.each(c.properties, function(p){
  190. s.push({
  191. name: c.code,
  192. boxLabel: p.display,
  193. inputValue: p.value,
  194. checked: p.value == c.data
  195. });
  196. });
  197. items.push({
  198. xtype: 'radiogroup',
  199. id: c.id,
  200. fieldLabel: c.title,
  201. columnWidth: 1,
  202. columns: 2,
  203. vertical: true,
  204. items: s
  205. });
  206. break;
  207. case 'COLOR':
  208. items.push({
  209. xtype: 'colorfield',
  210. fieldLabel: c.title,
  211. id: c.id,
  212. name: c.code,
  213. value: c.data,
  214. readOnly: c.editable == 0,
  215. editable: c.editable == 1,
  216. labelWidth: 150
  217. });
  218. break;
  219. case 'NUMBER':
  220. items.push({
  221. xtype: 'numberfield',
  222. fieldLabel: c.title,
  223. id: c.id,
  224. name: c.code,
  225. value: c.data,
  226. readOnly: c.editable == 0,
  227. labelWidth: 150
  228. });
  229. break;
  230. default :
  231. if(c.multi == 1) {
  232. var data = c.data ? c.data.split('\n') : [null], s = [];
  233. Ext.Array.each(data, function(d){
  234. s.push({
  235. xtype: (c.dbfind ? 'dbfindtrigger' : 'textfield'),
  236. name: c.dbfind || c.code,
  237. value: d,
  238. readOnly: !c.dbfind && c.editable == 0,
  239. editable: c.editable == 1,
  240. clearable: true
  241. });
  242. });
  243. s.push({
  244. xtype: 'button',
  245. text: '添加',
  246. width: 22,
  247. cls: 'x-dd-drop-ok-add',
  248. iconCls: 'x-dd-drop-icon',
  249. iconAlign: 'right',
  250. config: c
  251. });
  252. items.push({
  253. xtype: 'fieldset',
  254. title: c.title,
  255. id: c.id,
  256. name: c.code,
  257. columnWidth: 1,
  258. layout: 'column',
  259. defaults: {
  260. columnWidth: .25,
  261. margin: '4 8 4 8'
  262. },
  263. items: s
  264. });
  265. } else {
  266. items.push({
  267. xtype: (c.dbfind ? 'dbfindtrigger' : 'textfield'),
  268. fieldLabel: c.title,
  269. id: c.id,
  270. name: c.dbfind || c.code,
  271. value: c.data,
  272. readOnly: !c.dbfind && c.editable == 0,
  273. editable: c.editable == 1,
  274. clearable: true,
  275. columnWidth: .5,
  276. labelWidth: 150
  277. });
  278. }
  279. break;
  280. }
  281. if(c.help) {
  282. items.push({
  283. xtype: 'displayfield',
  284. value: c.help,
  285. columnWidth: ['NUMBER', 'VARCHAR2'].indexOf(c.data_type) > -1 ? .5 : 1,
  286. cls: 'help-block',
  287. margin: '4 8 8 8'
  288. });
  289. } else {
  290. if(['NUMBER', 'VARCHAR2'].indexOf(c.data_type) > -1) {
  291. items.push({
  292. xtype: 'displayfield'
  293. });
  294. }
  295. }
  296. });
  297. pane.removeAll();
  298. if(items.length == 0)
  299. items.push({
  300. html: '没有参数配置',
  301. cls: 'x-form-empty'
  302. });
  303. pane.add(items);
  304. },
  305. /**
  306. * 字符长度
  307. */
  308. getCharLength: function(str) {
  309. if(str) {
  310. for (var len = str.length, c = 0, i = 0; i < len; i++)
  311. str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126 ? c += 2 : c++;
  312. return c;
  313. }
  314. return 0;
  315. },
  316. setInterceptors: function(interceptors) {
  317. var me = this, pane = me.getTabPanel(), panels = [];
  318. var types = Ext.Array.unique(Ext.Array.pluck(interceptors, 'type'));
  319. types = Ext.Array.sort(types, function(a, b){
  320. return me.getMethodTypes(a).weight > me.getMethodTypes(b).weight;
  321. });
  322. Ext.Array.each(types, function(type){
  323. var data = Ext.Array.filter(interceptors, function(i){
  324. return i.type == type;
  325. });
  326. Ext.Array.each(data, function(d){
  327. d.enable = d.enable == 1;
  328. });
  329. panels.push({
  330. title: me.getMethodTypes(type).text,
  331. xtype: 'grid',
  332. columns: [{
  333. text: '顺序',
  334. dataIndex: 'detno',
  335. xtype: 'numbercolumn',
  336. align: 'center',
  337. format: '0',
  338. width: 40
  339. },{
  340. text: '描述',
  341. dataIndex: 'title',
  342. flex: 10
  343. },{
  344. text: '启用',
  345. xtype: 'checkcolumn',
  346. dataIndex: 'enable',
  347. width: 60
  348. }],
  349. columnLines: true,
  350. store: new Ext.data.Store({
  351. fields: ['id', 'title', 'type', 'turn', 'detno', 'enable', 'class_', 'method'],
  352. data: data,
  353. groupField: 'turn',
  354. sorters: [{
  355. property: 'detno'
  356. }]
  357. }),
  358. features : [{
  359. ftype: 'grouping',
  360. groupHeaderTpl: '<tpl if="name == 0">前<tpl else>后</tpl> (共 {rows.length} 项)',
  361. startCollapsed: false
  362. }],
  363. viewConfig: {
  364. listeners: {
  365. render: function(view) {
  366. if (!view.tip) {
  367. view.tip = Ext.create('Ext.tip.ToolTip', {
  368. target : view.el,
  369. delegate : view.itemSelector,
  370. trackMouse : true,
  371. renderTo : Ext.getBody(),
  372. tpl: new Ext.XTemplate('<dl class="dl-horizontal">' +
  373. '<dt>类:</dt><dd>{class_}</dd>' +
  374. '<dt>方法:</dt><dd>{method}</dd>' +
  375. '</dl>'),
  376. listeners: {
  377. beforeshow: function (tip) {
  378. var record = view.getRecord(tip.triggerElement);
  379. if(record){
  380. tip.update(record.data);
  381. } else {
  382. tip.on('show', function(){
  383. Ext.defer(tip.hide, 10, tip);
  384. }, tip, {single: true});
  385. }
  386. }
  387. }
  388. });
  389. }
  390. }
  391. }
  392. }
  393. });
  394. });
  395. pane.removeAll();
  396. pane.add(panels);
  397. },
  398. getMethodTypes: function(type) {
  399. var types = {
  400. 'save': {
  401. text: '保存',
  402. weight: 1
  403. },
  404. 'update': {
  405. text: '更新',
  406. weight: 2
  407. },
  408. 'commit': {
  409. text: '提交',
  410. weight: 3
  411. },
  412. 'resCommit': {
  413. text: '反提交',
  414. weight: 4
  415. },
  416. 'audit': {
  417. text: '审核',
  418. weight: 5
  419. },
  420. 'resAudit': {
  421. text: '反审核',
  422. weight: 6
  423. },
  424. 'post': {
  425. text: '过账',
  426. weight: 7
  427. },
  428. 'resPost': {
  429. text: '反过账',
  430. weight: 8
  431. },
  432. 'print': {
  433. text: '打印',
  434. weight: 9
  435. },
  436. 'turnout': {
  437. text: '转出货',
  438. weight: 10
  439. },
  440. 'turn': {
  441. text: '转单',
  442. weight: 11
  443. },
  444. 'delete': {
  445. text: '删除',
  446. weight: 12
  447. },
  448. 'deletedetail': {
  449. text: '删除明细',
  450. weight: 13
  451. },
  452. 'finish': {
  453. text: '结案',
  454. weight: 14
  455. }
  456. };
  457. return types[type] || {text: type, weight: 99};
  458. },
  459. onSaveClick: function() {
  460. var me = this, pane = me.getConfigPanel(), tab = me.getTabPanel(),
  461. updatedConfigs = [], updatedInters = [];
  462. Ext.Array.each(pane.items.items, function(field){
  463. if(field.xtype == 'fieldset') {
  464. var vals = [];
  465. Ext.Array.each(field.items.items, function(i){
  466. if(i.name && typeof i.getValue === 'function' && !Ext.isEmpty(i.getValue())) {
  467. vals.push(i.getValue());
  468. }
  469. });
  470. updatedConfigs.push({
  471. id: field.id,
  472. data: vals.length > 0 ? vals.join('\n') : null
  473. });
  474. } else if(typeof field.isDirty === 'function' && field.isDirty()) {
  475. var value = field.getValue();
  476. updatedConfigs.push({
  477. id: field.id,
  478. data: typeof value === 'boolean' ? (value ? 1 : 0) : (field.xtype == 'radiogroup' ?
  479. Ext.Object.getValues(value)[0] : value)
  480. });
  481. }
  482. });
  483. Ext.Array.each(tab.items.items, function(grid){
  484. var modified = grid.store.getModifiedRecords();
  485. Ext.Array.each(modified, function(m){
  486. updatedInters.push({
  487. id: m.get('id'),
  488. enable: m.get('enable') ? 1 : 0,
  489. detno: m.get('detno'),
  490. turn: m.get('turn')
  491. });
  492. });
  493. });
  494. if(updatedConfigs.length > 0) {
  495. me.saveConfigs(updatedConfigs, function(){
  496. me.loadConfigs(me.currCaller, function(configs){
  497. me.setConfigs(configs);
  498. });
  499. });
  500. }
  501. if(updatedInters.length > 0) {
  502. me.saveInterceptors(updatedInters, function(){
  503. me.loadInterceptors(me.currCaller, function(interceptors){
  504. me.setInterceptors(interceptors);
  505. });
  506. });
  507. }
  508. },
  509. /**
  510. * 修改参数配置
  511. */
  512. saveConfigs: function(updated, callback) {
  513. var me = this;
  514. Ext.Ajax.request({
  515. url: basePath + 'ma/setting/configs.action',
  516. params: {
  517. updated: Ext.JSON.encode(updated)
  518. },
  519. method: 'POST',
  520. callback: function(opt, s, r) {
  521. if(r && r.status == 200) {
  522. me.Toast.info('提示', '参数修改成功');
  523. callback.call();
  524. }
  525. }
  526. });
  527. },
  528. /**
  529. * 修改逻辑配置
  530. */
  531. saveInterceptors: function(updated, callback) {
  532. var me = this;
  533. Ext.Ajax.request({
  534. url: basePath + 'ma/setting/interceptors.action',
  535. params: {
  536. updated: Ext.JSON.encode(updated)
  537. },
  538. method: 'POST',
  539. callback: function(opt, s, r) {
  540. if(r && r.status == 200) {
  541. me.Toast.info('提示', '逻辑修改成功');
  542. callback.call();
  543. }
  544. }
  545. });
  546. }
  547. });