Optimize.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.ma.Optimize', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil'],
  5. views: ['ma.Optimize'],
  6. init:function(){
  7. var me = this;
  8. this.BaseUtil = Ext.create('erp.util.BaseUtil');
  9. this.control({
  10. 'button[id=check]': {
  11. click: function(btn) {
  12. var grid = btn.ownerCt.ownerCt;
  13. grid.store.each(function(r){
  14. r.set('check', '');
  15. });
  16. btn.setDisabled(true);
  17. me.check(grid, 0, btn);
  18. }
  19. },
  20. 'button[id=close]': {
  21. click: function() {
  22. me.BaseUtil.getActiveTab().close();
  23. }
  24. },
  25. 'gridpanel[id=check-grid]': {
  26. afterrender: function(grid) {
  27. grid.check = function(idx) {
  28. var record = grid.store.getAt(idx);
  29. record.set('check', '');
  30. var btn = Ext.getCmp('check');
  31. btn.setDisabled(true);
  32. me.check(grid, record, btn);
  33. };
  34. }
  35. }
  36. });
  37. },
  38. check: function(grid, idx, btn) {
  39. var me = this, r;
  40. if(Ext.isNumber(idx)) {
  41. r = grid.store.getAt(idx);
  42. } else {
  43. r = idx;
  44. }
  45. if(!r) {
  46. btn.setDisabled(false);
  47. return;
  48. }
  49. r.set('check', 'loading');
  50. Ext.Ajax.request({
  51. url: basePath + r.get('action'),
  52. method: 'GET',
  53. callback: function(opt, s, re) {
  54. r.set('check', 'checked');
  55. grid.toggleRow(r);
  56. var rs = Ext.decode(re.responseText);
  57. if(rs.error) {
  58. r.set('check', 'error');
  59. }
  60. if(rs.result) {
  61. r.set('detail', rs.result);
  62. }
  63. if(Ext.isNumber(idx)) {
  64. me.check(grid, ++idx, btn);
  65. } else {
  66. btn.setDisabled(false);
  67. }
  68. }
  69. });
  70. }
  71. });