SysEnabled.js 12 KB

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