AutoSync.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.ma.group.AutoSync', {
  3. extend: 'Ext.app.Controller',
  4. views: ['ma.group.AutoSync'],
  5. requires: ['erp.util.BaseUtil'],
  6. refs : [ {
  7. ref : 'grid',
  8. selector : 'grid'
  9. }],
  10. init:function(){
  11. this.BaseUtil = Ext.create('erp.util.BaseUtil');
  12. this.control({
  13. 'grid': {
  14. afterrender: function() {
  15. this.getPostStyleSet();
  16. }
  17. },
  18. '#confirm': {
  19. click: function() {
  20. this.savePostStyleSet();
  21. }
  22. },
  23. '#close': {
  24. click: function() {
  25. this.BaseUtil.getActiveTab().close();
  26. }
  27. }
  28. });
  29. },
  30. getMasters: function() {
  31. var columns = new Array(), fields = new Array();
  32. columns.push({dataIndex: 'ps_caller', hidden: true});
  33. columns.push({dataIndex: 'ps_table', hidden: true});
  34. columns.push({dataIndex: 'ps_keyfield', hidden: true});
  35. columns.push({text: '待同步资料', dataIndex: 'ps_desc', width: 120, cls: 'x-grid-header-1', align: 'center', tdCls: 'x-grid-cell-special'});
  36. fields.push({name: 'ps_caller', type: 'string'});
  37. fields.push({name: 'ps_desc', type: 'string'});
  38. fields.push({name: 'ps_table', type: 'string'});
  39. fields.push({name: 'ps_keyfield', type: 'string'});
  40. Ext.Ajax.request({
  41. url: basePath + 'common/getMasters.action',
  42. method: 'GET',
  43. async: false,
  44. callback: function(opt, s, r) {
  45. if (s) {
  46. var rs = Ext.decode(r.responseText),
  47. c = rs.currentMaster;
  48. for(var i in rs.masters) {
  49. var s = rs.masters[i];
  50. if(s.ma_name != c && s.ma_type == 3) {
  51. columns.push({text: s.ma_name, dataIndex: s.ma_user, cls: 'x-grid-header-1', xtype: 'checkcolumn', width: 90, editor: {
  52. xtype: 'checkbox',
  53. cls: 'x-grid-checkheader-editor'
  54. }});
  55. fields.push({name: s.ma_user, type: 'bool'});
  56. }
  57. }
  58. }
  59. }
  60. });
  61. return {columns: columns, fields: fields};
  62. },
  63. getPostStyleSet: function() {
  64. var grid = this.getGrid(), tab = this.BaseUtil.getActiveTab(),
  65. args = this.getMasters(), columns = args.columns, fields = args.fields;
  66. tab.setLoading(true);
  67. Ext.Ajax.request({
  68. url : basePath + 'common/getFieldsDatas.action',
  69. params: {
  70. caller: 'PostStyle',
  71. fields: 'ps_caller,ps_desc,ps_autosync,ps_table,ps_keyfield',
  72. condition: '1=1 order by ps_id'
  73. },
  74. method : 'post',
  75. callback : function(opt, s, res){
  76. tab.setLoading(false);
  77. var r = new Ext.decode(res.responseText);
  78. if(r.exceptionInfo){
  79. showError(r.exceptionInfo);return;
  80. }
  81. if(r.success){
  82. var data = Ext.decode(r.data), datas = new Array();
  83. for(var i in data) {
  84. var d = data[i], o = {ps_caller: d.PS_CALLER, ps_desc: d.PS_DESC, ps_table: d.PS_TABLE, ps_keyfield: d.PS_KEYFIELD};
  85. if(!Ext.isEmpty(d.PS_AUTOSYNC)) {
  86. var as = d.PS_AUTOSYNC.split(',');
  87. for (var j in as) {
  88. o[as[j]] = true;
  89. }
  90. }
  91. datas.push(o);
  92. }
  93. grid.reconfigure(Ext.create('Ext.data.Store', {
  94. fields: fields,
  95. data: datas
  96. }), columns);
  97. }
  98. }
  99. });
  100. },
  101. savePostStyleSet: function() {
  102. var me = this, grid = this.getGrid(), datas = new Array();
  103. grid.store.each(function(){
  104. if(this.dirty) {
  105. var d = this.data, keys = Ext.Object.getKeys(d), dd = new Array();
  106. for(var i in keys) {
  107. var k = keys[i];
  108. if(k != 'ps_caller' && k != 'ps_desc' && k != 'ps_table'
  109. && k != 'ps_keyfield' && d[k]) {
  110. dd.push(k);
  111. }
  112. }
  113. datas.push({ps_caller: d.ps_caller, ps_autosync: dd.join(','), ps_table: d.ps_table, ps_keyfield: d.ps_keyfield});
  114. }
  115. });
  116. if(datas.length == 0) {
  117. showError('未修改数据!');return;
  118. }
  119. Ext.Ajax.request({
  120. url: basePath + 'ma/group/updatePostStyleSet.action?caller=' + caller,
  121. params: {
  122. data: Ext.encode(datas)
  123. },
  124. callback: function(opt, s, res) {
  125. var r = new Ext.decode(res.responseText);
  126. if(r.exceptionInfo){
  127. showError(r.exceptionInfo);return;
  128. }
  129. if(r.success){
  130. alert('设置成功!');
  131. me.getPostStyleSet();
  132. }
  133. }
  134. });
  135. }
  136. });