EmployeeSync.js 4.5 KB

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