CheckBase.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.common.CheckBase', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil'],
  5. views: ['common.init.CheckBase'],
  6. init: function(){
  7. var me = this;
  8. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  9. this.control({
  10. 'button[name=prev]': {
  11. click: function(btn){
  12. var bt = parent.Ext.ComponentQuery.query('button[step=2]')[0];
  13. bt.fireEvent('click', bt);
  14. }
  15. },
  16. 'button[name=check]' : {
  17. click: function(b) {
  18. var c = 0, form = b.up('form'), bar = form.down('progressbar');
  19. var ds = form.query('displayfield');
  20. b.setDisabled(true);
  21. form.setLoading(true);
  22. bar.updateProgress(0);
  23. me.errtables = new Array();
  24. Ext.each(ds, function(d) {
  25. if(d.table) {
  26. d.setFieldStyle('');
  27. bar.updateText(d.value);
  28. Ext.Ajax.request({
  29. url: basePath + 'ma/guide/checktab.action',
  30. params: {
  31. t: d.table
  32. },
  33. async: false,
  34. callback: function (o, s, r) {
  35. bar.updateProgress((bar.value*ds.length + 1)/ds.length);
  36. if('success' == r.responseText) {
  37. d.setFieldStyle('color: blue');
  38. c += 1;
  39. } else {
  40. d.setFieldStyle('color: red');
  41. me.errtables.push(d.table);
  42. }
  43. }
  44. });
  45. }
  46. });
  47. form.setLoading(false);
  48. b.setDisabled(false);
  49. bar.updateText('检测完成 检测项:' + ds.length + ' 通过:' + c + ' 失败:' + (ds.length - c));
  50. if(c == ds.length) {
  51. form.down('button[name=next]').setDisabled(false);
  52. form.down('button[name=repair]').setDisabled(true);
  53. } else {
  54. form.down('button[name=repair]').setDisabled(false);
  55. }
  56. }
  57. },
  58. 'button[name=repair]' : {
  59. click: function(b) {
  60. var form = b.up('form'), tbs = me.errtables.join(',');
  61. form.setLoading(true);
  62. Ext.Ajax.request({
  63. url: basePath + 'ma/guide/repair.action',
  64. params: {
  65. tbs: tbs
  66. },
  67. callback: function(o, s, r) {
  68. form.setLoading(false);
  69. if ('success' == r.responseText) {
  70. alert('修复成功');
  71. var b = form.down('button[name=check]');
  72. b.fireEvent('click', b);
  73. } else {
  74. alert(r.responseText);
  75. }
  76. }
  77. });
  78. }
  79. },
  80. 'button[name=next]': {
  81. click: function(btn){
  82. var bt = parent.Ext.ComponentQuery.query('button[step=4]')[0];
  83. bt.fireEvent('click', bt);
  84. }
  85. }
  86. });
  87. }
  88. });