/ext/docs/source/PollingProvider.html

https://github.com/ktk070/Anopier · HTML · 154 lines · 144 code · 10 blank · 0 comment · 0 complexity · 8359e368e042559678ad67861311d432 MD5 · raw file

  1. <html>
  2. <head>
  3. <title>The source code</title>
  4. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  5. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  6. </head>
  7. <body onload="prettyPrint();">
  8. <pre class="prettyprint lang-js"><div id="cls-Ext.direct.PollingProvider"></div>/**
  9. * @class Ext.direct.PollingProvider
  10. * @extends Ext.direct.JsonProvider
  11. *
  12. * <p>Provides for repetitive polling of the server at distinct {@link #interval intervals}.
  13. * The initial request for data originates from the client, and then is responded to by the
  14. * server.</p>
  15. *
  16. * <p>All configurations for the PollingProvider should be generated by the server-side
  17. * API portion of the Ext.Direct stack.</p>
  18. *
  19. * <p>An instance of PollingProvider may be created directly via the new keyword or by simply
  20. * specifying <tt>type = 'polling'</tt>. For example:</p>
  21. * <pre><code>
  22. var pollA = new Ext.direct.PollingProvider({
  23. type:'polling',
  24. url: 'php/pollA.php',
  25. });
  26. Ext.Direct.addProvider(pollA);
  27. pollA.disconnect();
  28. Ext.Direct.addProvider(
  29. {
  30. type:'polling',
  31. url: 'php/pollB.php',
  32. id: 'pollB-provider'
  33. }
  34. );
  35. var pollB = Ext.Direct.getProvider('pollB-provider');
  36. * </code></pre>
  37. */
  38. Ext.direct.PollingProvider = Ext.extend(Ext.direct.JsonProvider, {
  39. <div id="cfg-Ext.direct.PollingProvider-priority"></div>/**
  40. * @cfg {Number} priority
  41. * Priority of the request (defaults to <tt>3</tt>). See {@link Ext.direct.Provider#priority}.
  42. */
  43. // override default priority
  44. priority: 3,
  45. <div id="cfg-Ext.direct.PollingProvider-interval"></div>/**
  46. * @cfg {Number} interval
  47. * How often to poll the server-side in milliseconds (defaults to <tt>3000</tt> - every
  48. * 3 seconds).
  49. */
  50. interval: 3000,
  51. <div id="cfg-Ext.direct.PollingProvider-baseParams"></div>/**
  52. * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
  53. * on every polling request
  54. */
  55. <div id="cfg-Ext.direct.PollingProvider-url"></div>/**
  56. * @cfg {String/Function} url
  57. * The url which the PollingProvider should contact with each request. This can also be
  58. * an imported Ext.Direct method which will accept the baseParams as its only argument.
  59. */
  60. // private
  61. constructor : function(config){
  62. Ext.direct.PollingProvider.superclass.constructor.call(this, config);
  63. this.addEvents(
  64. <div id="event-Ext.direct.PollingProvider-beforepoll"></div>/**
  65. * @event beforepoll
  66. * Fired immediately before a poll takes place, an event handler can return false
  67. * in order to cancel the poll.
  68. * @param {Ext.direct.PollingProvider}
  69. */
  70. 'beforepoll',
  71. <div id="event-Ext.direct.PollingProvider-poll"></div>/**
  72. * @event poll
  73. * This event has not yet been implemented.
  74. * @param {Ext.direct.PollingProvider}
  75. */
  76. 'poll'
  77. );
  78. },
  79. // inherited
  80. isConnected: function(){
  81. return !!this.pollTask;
  82. },
  83. <div id="method-Ext.direct.PollingProvider-connect"></div>/**
  84. * Connect to the server-side and begin the polling process. To handle each
  85. * response subscribe to the data event.
  86. */
  87. connect: function(){
  88. if(this.url && !this.pollTask){
  89. this.pollTask = Ext.TaskMgr.start({
  90. run: function(){
  91. if(this.fireEvent('beforepoll', this) !== false){
  92. if(typeof this.url == 'function'){
  93. this.url(this.baseParams);
  94. }else{
  95. Ext.Ajax.request({
  96. url: this.url,
  97. callback: this.onData,
  98. scope: this,
  99. params: this.baseParams
  100. });
  101. }
  102. }
  103. },
  104. interval: this.interval,
  105. scope: this
  106. });
  107. this.fireEvent('connect', this);
  108. }else if(!this.url){
  109. throw 'Error initializing PollingProvider, no url configured.';
  110. }
  111. },
  112. <div id="method-Ext.direct.PollingProvider-disconnect"></div>/**
  113. * Disconnect from the server-side and stop the polling process. The disconnect
  114. * event will be fired on a successful disconnect.
  115. */
  116. disconnect: function(){
  117. if(this.pollTask){
  118. Ext.TaskMgr.stop(this.pollTask);
  119. delete this.pollTask;
  120. this.fireEvent('disconnect', this);
  121. }
  122. },
  123. // private
  124. onData: function(opt, success, xhr){
  125. if(success){
  126. var events = this.getEvents(xhr);
  127. for(var i = 0, len = events.length; i < len; i++){
  128. var e = events[i];
  129. this.fireEvent('data', this, e);
  130. }
  131. }else{
  132. var e = new Ext.Direct.ExceptionEvent({
  133. data: e,
  134. code: Ext.Direct.exceptions.TRANSPORT,
  135. message: 'Unable to connect to the server.',
  136. xhr: xhr
  137. });
  138. this.fireEvent('data', this, e);
  139. }
  140. }
  141. });
  142. Ext.Direct.PROVIDERS['polling'] = Ext.direct.PollingProvider;</pre>
  143. </body>
  144. </html>