Master.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.common.Master', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.BaseUtil'],
  5. views: ['common.init.Master'],
  6. init: function(){
  7. var me = this;
  8. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  9. this.control({
  10. 'button[id=prev]': {
  11. click: function(btn){
  12. var bt = parent.Ext.ComponentQuery.query('button[step=1]')[0];
  13. bt.fireEvent('click', bt);
  14. }
  15. },
  16. 'button[id=next]': {
  17. click: function(btn){
  18. var bt = parent.Ext.ComponentQuery.query('button[step=3]')[0];
  19. bt.fireEvent('click', bt);
  20. }
  21. },
  22. 'button[id=confirm]': {
  23. click: function(btn){
  24. var form = btn.ownerCt.ownerCt;
  25. me.login(form);
  26. }
  27. },
  28. 'combo[name=ma_name]': {
  29. afterrender: function(f){
  30. me.getMasterNames(f);
  31. }
  32. }
  33. });
  34. },
  35. getMasterNames: function(f){
  36. Ext.Ajax.request({
  37. url: basePath + 'system/getMasters.action',
  38. method: 'get',
  39. callback: function(options, success, response){
  40. var res = new Ext.decode(response.responseText);
  41. if(res.exceptionInfo != null){
  42. showError(res.exceptionInfo);return;
  43. } else if(res.success) {
  44. var datas = new Array();
  45. Ext.each(res.masters, function(m){
  46. datas.push({
  47. display: m,
  48. value: m
  49. });
  50. });
  51. f.store.loadData(datas);
  52. if(datas.length > 0){
  53. f.select(f.store.first().get('display'));
  54. }
  55. }
  56. }
  57. });
  58. },
  59. login: function(form){
  60. form.setLoading(true);
  61. Ext.Ajax.request({
  62. url: basePath + 'common/login.action',
  63. method: 'post',
  64. params: {
  65. sob: form.down('#ma_name').value,
  66. username: form.down('#em_code').value,
  67. password: form.down('#em_password').value
  68. },
  69. callback: function(o, s, r){
  70. form.setLoading(false);
  71. var res = new Ext.decode(r.responseText);
  72. if(res.exceptionInfo != null){
  73. showError(res.exceptionInfo);
  74. } else if(res.success) {
  75. var b = form.down('button[id=next]');
  76. b.setDisabled(false);
  77. b.fireEvent('click', b);
  78. } else if(res.reason) {
  79. showError(res.reason);
  80. } else{
  81. alert('系统错误!');
  82. }
  83. }
  84. });
  85. }
  86. });