RefreshSync.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * 刷新同步状态
  3. */
  4. Ext.define('erp.view.core.button.RefreshSync', {
  5. extend : 'Ext.Button',
  6. alias : 'widget.erpRefreshSyncButton',
  7. text : $I18N.common.button.erpRefreshSyncButton,
  8. iconCls : 'x-button-icon-reset',
  9. cls : 'x-btn-gray',
  10. width : 110,
  11. style : {
  12. marginLeft : '10px'
  13. },
  14. initComponent : function() {
  15. this.callParent(arguments);
  16. },
  17. handler: function(btn) {
  18. var win = btn.win;
  19. if (!win) {
  20. this.win = win = this.createMasterWin();
  21. this.getMasters();
  22. }
  23. win.show();
  24. },
  25. createMasterWin : function() {
  26. var me = this;
  27. return Ext.create('Ext.Window', {
  28. title: '指定需要检测的账套',
  29. width: 700,
  30. height: 400,
  31. layout: 'fit',
  32. items: [{
  33. xtype: 'form',
  34. autoScroll: true,
  35. bodyStyle: 'background: #f1f1f1;',
  36. layout: 'column',
  37. defaults: {
  38. xtype: 'checkbox',
  39. margin: '2 10 2 10',
  40. columnWidth: .5
  41. },
  42. items: [{
  43. boxLabel: '全选',
  44. columnWidth: 1,
  45. listeners: {
  46. change: function(f) {
  47. var form = f.up('form');
  48. form.getForm().getFields().each(function(a){
  49. if(a.id != f.id) {
  50. a.setValue(f.value);
  51. }
  52. });
  53. }
  54. }
  55. }]
  56. }],
  57. buttonAlign: 'center',
  58. buttons: [{
  59. text: $I18N.common.button.erpConfirmButton,
  60. cls: 'x-btn-blue',
  61. handler: function(b) {
  62. me.refreshSync();
  63. }
  64. }, {
  65. text: $I18N.common.button.erpCloseButton,
  66. cls: 'x-btn-blue',
  67. handler: function(b) {
  68. b.up('window').hide();
  69. }
  70. }]
  71. });
  72. },
  73. getMasters: function() {
  74. if (this.win) {
  75. var form = this.win.down('form');
  76. Ext.Ajax.request({
  77. url: basePath + 'common/getMasters.action',
  78. method: 'GET',
  79. callback: function(opt, s, r) {
  80. if (s) {
  81. var rs = Ext.decode(r.responseText),
  82. c = rs.currentMaster,
  83. g = rs.group,
  84. t = rs._type,
  85. m = rs._master,
  86. ms = new Array(),
  87. items = new Array();
  88. if(t != 'admin' && m != null) {
  89. ms = m.split(',');
  90. }
  91. for(var i in rs.masters) {
  92. var s = rs.masters[i];
  93. if (s.ma_name != c) {
  94. if("true" === g && "admin" !== t && !Ext.Array.contains(ms, s.ma_name))
  95. continue;
  96. if(s.ma_name == 'DataCenter' && "admin" !== t) {
  97. continue;
  98. }
  99. var o = {
  100. boxLabel: s.ma_name + '(' + s.ma_function + ')',
  101. ma_id: s.ma_id,
  102. ma_pid: s.ma_pid,
  103. ma_user: s.ma_user,
  104. ma_soncode: s.ma_soncode,
  105. ma_type: s.ma_type,
  106. listeners: {
  107. change: function(c) {
  108. if(c.ma_type == 2 && !Ext.isEmpty(c.ma_soncode) && c.value) {
  109. var ff = c.up('form').query('checkbox[ma_pid=' + c.ma_id + ']');
  110. Ext.each(ff, function(i){
  111. i.setValue(true);
  112. });
  113. }
  114. }
  115. }
  116. };
  117. items.push(o);
  118. }
  119. }
  120. form.add(items);
  121. }
  122. }
  123. });
  124. }
  125. },
  126. getCheckData: function() {
  127. if (this.win) {
  128. var form = this.win.down('form'),
  129. items = form.query('checkbox[checked=true]'),
  130. data = new Array();
  131. Ext.each(items, function(item){
  132. if(item.ma_type != 2 && item.ma_user)
  133. data.push(item.ma_user);
  134. });
  135. return data.join(',');
  136. }
  137. return null;
  138. },
  139. refreshSync: function() {
  140. var masters = this.getCheckData(), form = Ext.getCmp('form'), w = this.win,
  141. datas = this.syncdatas, cal = this.caller;
  142. if(!datas && form && form.keyField && Ext.getCmp(form.keyField)
  143. && Ext.getCmp(form.keyField).value > 0) {
  144. datas = Ext.getCmp(form.keyField).value;
  145. }
  146. if(cal == null)
  147. cal = caller + '!Reset';
  148. if (!Ext.isEmpty(masters)) {
  149. w.setLoading(true);
  150. Ext.Ajax.request({
  151. url: basePath + 'common/form/refreshsync.action',
  152. params: {
  153. caller: cal,
  154. data: datas,
  155. to: masters
  156. },
  157. callback: function(opt, s, r) {
  158. w.setLoading(false);
  159. if(s) {
  160. var rs = Ext.decode(r.responseText);
  161. if(rs.data) {
  162. showMessage('提示', rs.data);
  163. } else {
  164. alert('刷新成功!');
  165. }
  166. w.hide();
  167. }
  168. }
  169. });
  170. }
  171. }
  172. });