4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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 every 3 seconds.
69 <span id='Ext-direct-PollingProvider-cfg-baseParams'> /**
70 </span> * @cfg {Object} baseParams
71 * An object containing properties which are to be sent as parameters on every polling request
74 <span id='Ext-direct-PollingProvider-cfg-url'> /**
75 </span> * @cfg {String/Function} url
76 * The url which the PollingProvider should contact with each request. This can also be
77 * an imported Ext.Direct method which will accept the baseParams as its only argument.
81 constructor : function(config){
82 this.callParent(arguments);
84 <span id='Ext-direct-PollingProvider-event-beforepoll'> /**
85 </span> * @event beforepoll
86 * Fired immediately before a poll takes place, an event handler can return false
87 * in order to cancel the poll.
88 * @param {Ext.direct.PollingProvider} this
91 <span id='Ext-direct-PollingProvider-event-poll'> /**
93 * This event has not yet been implemented.
94 * @param {Ext.direct.PollingProvider} this
101 isConnected: function(){
102 return !!this.pollTask;
105 <span id='Ext-direct-PollingProvider-method-connect'> /**
106 </span> * Connect to the server-side and begin the polling process. To handle each
107 * response subscribe to the data event.
110 var me = this, url = me.url;
112 if (url && !me.pollTask) {
113 me.pollTask = Ext.TaskManager.start({
115 if (me.fireEvent('beforepoll', me) !== false) {
116 if (Ext.isFunction(url)) {
123 params: me.baseParams
128 interval: me.interval,
131 me.fireEvent('connect', me);
134 Ext.Error.raise('Error initializing PollingProvider, no url configured.');
139 <span id='Ext-direct-PollingProvider-method-disconnect'> /**
140 </span> * Disconnect from the server-side and stop the polling process. The disconnect
141 * event will be fired on a successful disconnect.
143 disconnect: function(){
147 Ext.TaskManager.stop(me.pollTask);
149 me.fireEvent('disconnect', me);
154 onData: function(opt, success, response){
161 events = me.createEvents(response);
162 for (len = events.length; i < len; ++i) {
163 me.fireEvent('data', me, events[i]);
166 me.fireEvent('data', me, Ext.create('Ext.direct.ExceptionEvent', {
168 code: Ext.direct.Manager.self.exceptions.TRANSPORT,
169 message: 'Unable to connect to the server.',