3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.direct.PollingProvider"></div>/**
\r
10 * @class Ext.direct.PollingProvider
\r
11 * @extends Ext.direct.JsonProvider
\r
13 * <p>Provides for repetitive polling of the server at distinct {@link #interval intervals}.
\r
14 * The initial request for data originates from the client, and then is responded to by the
\r
17 * <p>All configurations for the PollingProvider should be generated by the server-side
\r
18 * API portion of the Ext.Direct stack.</p>
\r
20 * <p>An instance of PollingProvider may be created directly via the new keyword or by simply
\r
21 * specifying <tt>type = 'polling'</tt>. For example:</p>
\r
23 var pollA = new Ext.direct.PollingProvider({
\r
25 url: 'php/pollA.php',
\r
27 Ext.Direct.addProvider(pollA);
\r
30 Ext.Direct.addProvider(
\r
33 url: 'php/pollB.php',
\r
34 id: 'pollB-provider'
\r
37 var pollB = Ext.Direct.getProvider('pollB-provider');
\r
40 Ext.direct.PollingProvider = Ext.extend(Ext.direct.JsonProvider, {
\r
41 <div id="cfg-Ext.direct.PollingProvider-priority"></div>/**
\r
42 * @cfg {Number} priority
\r
43 * Priority of the request (defaults to <tt>3</tt>). See {@link Ext.direct.Provider#priority}.
\r
45 // override default priority
\r
48 <div id="cfg-Ext.direct.PollingProvider-interval"></div>/**
\r
49 * @cfg {Number} interval
\r
50 * How often to poll the server-side in milliseconds (defaults to <tt>3000</tt> - every
\r
55 <div id="cfg-Ext.direct.PollingProvider-baseParams"></div>/**
\r
56 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
\r
57 * on every polling request
\r
60 <div id="cfg-Ext.direct.PollingProvider-url"></div>/**
\r
61 * @cfg {String/Function} url
\r
62 * The url which the PollingProvider should contact with each request. This can also be
\r
63 * an imported Ext.Direct method which will accept the baseParams as its only argument.
\r
67 constructor : function(config){
\r
68 Ext.direct.PollingProvider.superclass.constructor.call(this, config);
\r
70 <div id="event-Ext.direct.PollingProvider-beforepoll"></div>/**
\r
72 * Fired immediately before a poll takes place, an event handler can return false
\r
73 * in order to cancel the poll.
\r
74 * @param {Ext.direct.PollingProvider}
\r
77 <div id="event-Ext.direct.PollingProvider-poll"></div>/**
\r
79 * This event has not yet been implemented.
\r
80 * @param {Ext.direct.PollingProvider}
\r
87 isConnected: function(){
\r
88 return !!this.pollTask;
\r
91 <div id="method-Ext.direct.PollingProvider-connect"></div>/**
\r
92 * Connect to the server-side and begin the polling process. To handle each
\r
93 * response subscribe to the data event.
\r
95 connect: function(){
\r
96 if(this.url && !this.pollTask){
\r
97 this.pollTask = Ext.TaskMgr.start({
\r
99 if(this.fireEvent('beforepoll', this) !== false){
\r
100 if(typeof this.url == 'function'){
\r
101 this.url(this.baseParams);
\r
105 callback: this.onData,
\r
107 params: this.baseParams
\r
112 interval: this.interval,
\r
115 this.fireEvent('connect', this);
\r
116 }else if(!this.url){
\r
117 throw 'Error initializing PollingProvider, no url configured.';
\r
121 <div id="method-Ext.direct.PollingProvider-disconnect"></div>/**
\r
122 * Disconnect from the server-side and stop the polling process. The disconnect
\r
123 * event will be fired on a successful disconnect.
\r
125 disconnect: function(){
\r
127 Ext.TaskMgr.stop(this.pollTask);
\r
128 delete this.pollTask;
\r
129 this.fireEvent('disconnect', this);
\r
134 onData: function(opt, success, xhr){
\r
136 var events = this.getEvents(xhr);
\r
137 for(var i = 0, len = events.length; i < len; i++){
\r
139 this.fireEvent('data', this, e);
\r
142 var e = new Ext.Direct.ExceptionEvent({
\r
144 code: Ext.Direct.exceptions.TRANSPORT,
\r
145 message: 'Unable to connect to the server.',
\r
148 this.fireEvent('data', this, e);
\r
153 Ext.Direct.PROVIDERS['polling'] = Ext.direct.PollingProvider;</pre>
\r