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>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.direct.PollingProvider"></div>/**
16 * @class Ext.direct.PollingProvider
17 * @extends Ext.direct.JsonProvider
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
23 * <p>All configurations for the PollingProvider should be generated by the server-side
24 * API portion of the Ext.Direct stack.</p>
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>
29 var pollA = new Ext.direct.PollingProvider({
33 Ext.Direct.addProvider(pollA);
36 Ext.Direct.addProvider(
43 var pollB = Ext.Direct.getProvider('pollB-provider');
46 Ext.direct.PollingProvider = Ext.extend(Ext.direct.JsonProvider, {
47 <div id="cfg-Ext.direct.PollingProvider-priority"></div>/**
48 * @cfg {Number} priority
49 * Priority of the request (defaults to <tt>3</tt>). See {@link Ext.direct.Provider#priority}.
51 // override default priority
54 <div id="cfg-Ext.direct.PollingProvider-interval"></div>/**
55 * @cfg {Number} interval
56 * How often to poll the server-side in milliseconds (defaults to <tt>3000</tt> - every
61 <div id="cfg-Ext.direct.PollingProvider-baseParams"></div>/**
62 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
63 * on every polling request
66 <div id="cfg-Ext.direct.PollingProvider-url"></div>/**
67 * @cfg {String/Function} url
68 * The url which the PollingProvider should contact with each request. This can also be
69 * an imported Ext.Direct method which will accept the baseParams as its only argument.
73 constructor : function(config){
74 Ext.direct.PollingProvider.superclass.constructor.call(this, config);
76 <div id="event-Ext.direct.PollingProvider-beforepoll"></div>/**
78 * Fired immediately before a poll takes place, an event handler can return false
79 * in order to cancel the poll.
80 * @param {Ext.direct.PollingProvider}
83 <div id="event-Ext.direct.PollingProvider-poll"></div>/**
85 * This event has not yet been implemented.
86 * @param {Ext.direct.PollingProvider}
93 isConnected: function(){
94 return !!this.pollTask;
97 <div id="method-Ext.direct.PollingProvider-connect"></div>/**
98 * Connect to the server-side and begin the polling process. To handle each
99 * response subscribe to the data event.
102 if(this.url && !this.pollTask){
103 this.pollTask = Ext.TaskMgr.start({
105 if(this.fireEvent('beforepoll', this) !== false){
106 if(typeof this.url == 'function'){
107 this.url(this.baseParams);
111 callback: this.onData,
113 params: this.baseParams
118 interval: this.interval,
121 this.fireEvent('connect', this);
123 throw 'Error initializing PollingProvider, no url configured.';
127 <div id="method-Ext.direct.PollingProvider-disconnect"></div>/**
128 * Disconnect from the server-side and stop the polling process. The disconnect
129 * event will be fired on a successful disconnect.
131 disconnect: function(){
133 Ext.TaskMgr.stop(this.pollTask);
134 delete this.pollTask;
135 this.fireEvent('disconnect', this);
140 onData: function(opt, success, xhr){
142 var events = this.getEvents(xhr);
143 for(var i = 0, len = events.length; i < len; i++){
145 this.fireEvent('data', this, e);
148 var e = new Ext.Direct.ExceptionEvent({
150 code: Ext.Direct.exceptions.TRANSPORT,
151 message: 'Unable to connect to the server.',
154 this.fireEvent('data', this, e);
159 Ext.Direct.PROVIDERS['polling'] = Ext.direct.PollingProvider;</pre>