Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / direct / Provider.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.direct.Provider
17  * <p>Ext.direct.Provider is an abstract class meant to be extended.</p>
18  *
19  * <p>For example Ext JS implements the following subclasses:</p>
20  * <pre><code>
21 Provider
22 |
23 +---{@link Ext.direct.JsonProvider JsonProvider}
24     |
25     +---{@link Ext.direct.PollingProvider PollingProvider}
26     |
27     +---{@link Ext.direct.RemotingProvider RemotingProvider}
28  * </code></pre>
29  * @abstract
30  */
31 Ext.define('Ext.direct.Provider', {
32
33     /* Begin Definitions */
34
35    alias: 'direct.provider',
36
37     mixins: {
38         observable: 'Ext.util.Observable'
39     },
40
41     /* End Definitions */
42
43    /**
44      * @cfg {String} id
45      * The unique id of the provider (defaults to an {@link Ext#id auto-assigned id}).
46      * You should assign an id if you need to be able to access the provider later and you do
47      * not have an object reference available, for example:
48      * <pre><code>
49 Ext.direct.Manager.addProvider({
50     type: 'polling',
51     url:  'php/poll.php',
52     id:   'poll-provider'
53 });
54 var p = {@link Ext.direct.Manager}.{@link Ext.direct.Manager#getProvider getProvider}('poll-provider');
55 p.disconnect();
56      * </code></pre>
57      */
58
59     constructor : function(config){
60         var me = this;
61
62         Ext.apply(me, config);
63         me.addEvents(
64             /**
65              * @event connect
66              * Fires when the Provider connects to the server-side
67              * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.
68              */
69             'connect',
70             /**
71              * @event disconnect
72              * Fires when the Provider disconnects from the server-side
73              * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.
74              */
75             'disconnect',
76             /**
77              * @event data
78              * Fires when the Provider receives data from the server-side
79              * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.
80              * @param {Ext.direct.Event} e The Ext.direct.Event type that occurred.
81              */
82             'data',
83             /**
84              * @event exception
85              * Fires when the Provider receives an exception from the server-side
86              */
87             'exception'
88         );
89         me.mixins.observable.constructor.call(me, config);
90     },
91
92     /**
93      * Returns whether or not the server-side is currently connected.
94      * Abstract method for subclasses to implement.
95      */
96     isConnected: function(){
97         return false;
98     },
99
100     /**
101      * Abstract methods for subclasses to implement.
102      * @method
103      */
104     connect: Ext.emptyFn,
105
106     /**
107      * Abstract methods for subclasses to implement.
108      * @method
109      */
110     disconnect: Ext.emptyFn
111 });
112