4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-direct-PollingProvider'>/**
19 </span> * @class Ext.direct.PollingProvider
20 * @extends Ext.direct.JsonProvider
22 * <p>Provides for repetitive polling of the server at distinct {@link #interval intervals}.
23 * The initial request for data originates from the client, and then is responded to by the
26 * <p>All configurations for the PollingProvider should be generated by the server-side
27 * API portion of the Ext.Direct stack.</p>
29 * <p>An instance of PollingProvider may be created directly via the new keyword or by simply
30 * specifying <tt>type = 'polling'</tt>. For example:</p>
31 * <pre><code>
32 var pollA = new Ext.direct.PollingProvider({
36 Ext.direct.Manager.addProvider(pollA);
39 Ext.direct.Manager.addProvider(
46 var pollB = Ext.direct.Manager.getProvider('pollB-provider');
47 * </code></pre>
49 Ext.define('Ext.direct.PollingProvider', {
51 /* Begin Definitions */
53 extend: 'Ext.direct.JsonProvider',
55 alias: 'direct.pollingprovider',
57 uses: ['Ext.direct.ExceptionEvent'],
59 requires: ['Ext.Ajax', 'Ext.util.DelayedTask'],
63 <span id='Ext-direct-PollingProvider-cfg-interval'> /**
64 </span> * @cfg {Number} interval
65 * How often to poll the server-side in milliseconds (defaults to <tt>3000</tt> - every
70 <span id='Ext-direct-PollingProvider-cfg-baseParams'> /**
71 </span> * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
72 * on every polling request
75 <span id='Ext-direct-PollingProvider-cfg-url'> /**
76 </span> * @cfg {String/Function} url
77 * The url which the PollingProvider should contact with each request. This can also be
78 * an imported Ext.Direct method which will accept the baseParams as its only argument.
82 constructor : function(config){
83 this.callParent(arguments);
85 <span id='Ext-direct-PollingProvider-event-beforepoll'> /**
86 </span> * @event beforepoll
87 * Fired immediately before a poll takes place, an event handler can return false
88 * in order to cancel the poll.
89 * @param {Ext.direct.PollingProvider}
92 <span id='Ext-direct-PollingProvider-event-poll'> /**
94 * This event has not yet been implemented.
95 * @param {Ext.direct.PollingProvider}
102 isConnected: function(){
103 return !!this.pollTask;
106 <span id='Ext-direct-PollingProvider-method-connect'> /**
107 </span> * Connect to the server-side and begin the polling process. To handle each
108 * response subscribe to the data event.
111 var me = this, url = me.url;
113 if (url && !me.pollTask) {
114 me.pollTask = Ext.TaskManager.start({
116 if (me.fireEvent('beforepoll', me) !== false) {
117 if (Ext.isFunction(url)) {
124 params: me.baseParams
129 interval: me.interval,
132 me.fireEvent('connect', me);
135 Ext.Error.raise('Error initializing PollingProvider, no url configured.');
140 <span id='Ext-direct-PollingProvider-method-disconnect'> /**
141 </span> * Disconnect from the server-side and stop the polling process. The disconnect
142 * event will be fired on a successful disconnect.
144 disconnect: function(){
148 Ext.TaskManager.stop(me.pollTask);
150 me.fireEvent('disconnect', me);
155 onData: function(opt, success, response){
162 events = me.createEvents(response);
163 for (len = events.length; i < len; ++i) {
164 me.fireEvent('data', me, events[i]);
167 me.fireEvent('data', me, Ext.create('Ext.direct.ExceptionEvent', {
169 code: Ext.direct.Manager.self.exceptions.TRANSPORT,
170 message: 'Unable to connect to the server.',