Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.5 KiB

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