Sync.js 4.5 KB

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