GridWin.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * 点击按钮,弹出window,内嵌grid,可修改保存
  3. * button.caller,
  4. * button.condition传入条件
  5. */
  6. Ext.define('erp.view.core.button.GridWin', {
  7. extend : 'Ext.Button',
  8. alias : 'widget.erpGridWinButton',
  9. iconCls : 'x-button-icon-detail',
  10. cls : 'x-btn-gray',
  11. text : ' ',
  12. style : {
  13. marginLeft : '10px'
  14. },
  15. width : 90,
  16. initComponent : function() {
  17. this.callParent(arguments);
  18. },
  19. setConfig: function(args) {
  20. if(args && args instanceof Object) {
  21. var me = this, keys = Ext.Object.getKeys(args);
  22. Ext.each(keys, function(k){
  23. me[k] = args[k];
  24. var f = me['set' + Ext.String.capitalize(k)];
  25. if(f && typeof f === 'function') {
  26. f.call(me, args[k]);
  27. }
  28. });
  29. }
  30. },
  31. handler: function(btn) {
  32. var win = this.win;
  33. if(!win) {
  34. var url = 'jsps/common/gridpage.jsp?whoami=' + btn.caller + '&gridCondition=' +
  35. btn.condition;
  36. var p = btn.parseParamConfig();
  37. if(p) {
  38. url += '&' + p;
  39. }
  40. win = this.createWin(url);
  41. }
  42. win.show();
  43. var me = this;
  44. if(!me.contentWin) {
  45. me.setContentWin();
  46. }
  47. },
  48. setContentWin : function() {
  49. var me = this, win = this.win;
  50. setTimeout(function(){
  51. var iframe = win.getEl().down('iframe');
  52. if(iframe) {
  53. me.contentWin = iframe.dom.contentWindow;
  54. if(me.contentWin.Ext) {
  55. var grid = me.contentWin.Ext.getCmp('grid');
  56. if ( grid ) {
  57. var saveBtn = grid.down('erpSaveButton');
  58. if(saveBtn) {
  59. saveBtn.on('beforesave', function(){
  60. return me.fireEvent('beforesave', me);
  61. });
  62. saveBtn.on('aftersave', function(){
  63. me.fireEvent('aftersave', me);
  64. });
  65. }
  66. }
  67. }
  68. }
  69. }, 2000);
  70. },
  71. createWin: function(url) {
  72. this.win = Ext.create('Ext.window.Window', {
  73. title: this.text,
  74. height: '80%',
  75. width: '80%',
  76. items: [{
  77. height: '100%',
  78. width: '100%',
  79. html: '<iframe src="' + basePath + url + '" height="100%" width="100%"></iframe>'
  80. }],
  81. buttonAlign: 'center',
  82. buttons: [{
  83. text: $I18N.common.button.erpCloseButton,
  84. cls: 'x-btn-gray',
  85. handler: function(b) {
  86. b.ownerCt.ownerCt.hide();
  87. }
  88. }]
  89. });
  90. return this.win;
  91. },
  92. parseParamConfig: function() {
  93. var p = this.paramConfig, u = [];
  94. if(p && p instanceof Object) {
  95. var keys = Ext.Object.getKeys(p);
  96. Ext.each(keys, function(k){
  97. u.push(k + '=' + p[k]);
  98. });
  99. }
  100. return u.join('&');
  101. }
  102. });