modx.console.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. MODx.Console = function(config) {
  2. config = config || {};
  3. Ext.Updater.defaults.showLoadIndicator = false;
  4. Ext.applyIf(config,{
  5. title: _('console')
  6. ,modal: Ext.isIE ? false : true
  7. ,closeAction: 'hide'
  8. // ,shadow: true
  9. ,resizable: false
  10. ,collapsible: false
  11. ,closable: true
  12. ,maximizable: true
  13. ,autoScroll: true
  14. ,height: 400
  15. ,width: 600
  16. ,refreshRate: 2
  17. ,cls: 'modx-window modx-console'
  18. ,items: [{
  19. itemId: 'header'
  20. ,cls: 'modx-console-text'
  21. ,html: _('console_running')
  22. ,border: false
  23. },{
  24. xtype: 'panel'
  25. ,itemId: 'body'
  26. ,cls: 'x-panel-bwrap modx-console-text'
  27. }]
  28. ,buttons: [{
  29. text: _('console_download_output')
  30. ,handler: this.download
  31. ,scope: this
  32. },{
  33. text: _('ok')
  34. ,cls: 'primary-button'
  35. ,itemId: 'okBtn'
  36. ,disabled: true
  37. ,scope: this
  38. ,handler: this.hideConsole
  39. }]
  40. ,keys: [{
  41. key: Ext.EventObject.S
  42. ,ctrl: true
  43. ,fn: this.download
  44. ,scope: this
  45. },{
  46. key: Ext.EventObject.ENTER
  47. ,fn: this.hideConsole
  48. ,scope: this
  49. }]
  50. });
  51. MODx.Console.superclass.constructor.call(this,config);
  52. this.config = config;
  53. this.addEvents({
  54. 'shutdown': true
  55. ,'complete': true
  56. });
  57. this.on('show',this.init,this);
  58. this.on('hide',function() {
  59. if (this.provider && this.provider.disconnect) {
  60. try {
  61. this.provider.disconnect();
  62. } catch (e) {}
  63. }
  64. this.fireEvent('shutdown');
  65. //this.getComponent('body').el.update('');
  66. this.destroy();
  67. });
  68. this.on('complete',this.onComplete,this);
  69. };
  70. Ext.extend(MODx.Console,Ext.Window,{
  71. mgr: null
  72. ,running: false
  73. ,init: function() {
  74. Ext.Msg.hide();
  75. this.fbar.setDisabled(true);
  76. this.keyMap.setDisabled(true);
  77. this.getComponent('body').el.dom.innerHTML = '';
  78. this.provider = new Ext.direct.PollingProvider({
  79. type:'polling'
  80. ,url: MODx.config.connector_url
  81. ,interval: 1000
  82. ,baseParams: {
  83. action: 'system/console'
  84. ,register: this.config.register || ''
  85. ,topic: this.config.topic || ''
  86. ,clear: false
  87. ,show_filename: this.config.show_filename || 0
  88. ,format: this.config.format || 'html_log'
  89. }
  90. });
  91. Ext.Direct.addProvider(this.provider);
  92. Ext.Direct.on('message', this.onMessage, this);
  93. }
  94. ,onMessage: function(e,p) {
  95. var out = this.getComponent('body');
  96. if (out) {
  97. out.el.insertHtml('beforeEnd',e.data);
  98. e.data = '';
  99. out.el.scroll('b', out.el.getHeight(), true);
  100. }
  101. if (e.complete) {
  102. this.fireEvent('complete');
  103. }
  104. delete e;
  105. }
  106. ,onComplete: function() {
  107. if (this.provider && this.provider.disconnect) {
  108. try {
  109. this.provider.disconnect();
  110. } catch (e) {}
  111. }
  112. this.fbar.setDisabled(false);
  113. this.keyMap.setDisabled(false);
  114. }
  115. ,download: function() {
  116. var c = this.getComponent('body').getEl().dom.innerHTML || ' ';
  117. MODx.Ajax.request({
  118. url: MODx.config.connector_url
  119. ,params: {
  120. action: 'system/downloadoutput'
  121. ,data: c
  122. }
  123. ,listeners: {
  124. 'success':{fn:function(r) {
  125. location.href = MODx.config.connector_url+'?action=system/downloadOutput&HTTP_MODAUTH='+MODx.siteId+'&download='+r.message;
  126. },scope:this}
  127. }
  128. });
  129. }
  130. ,setRegister: function(register,topic) {
  131. this.config.register = register;
  132. this.config.topic = topic;
  133. }
  134. ,hideConsole: function() {
  135. this.hide();
  136. }
  137. });
  138. Ext.reg('modx-console',MODx.Console);