Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / src / state / StateManager.js
1 /*!
2  * Ext JS Library 3.1.0
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**\r
8  * @class Ext.state.Manager\r
9  * This is the global state manager. By default all components that are "state aware" check this class\r
10  * for state information if you don't pass them a custom state provider. In order for this class\r
11  * to be useful, it must be initialized with a provider when your application initializes. Example usage:\r
12  <pre><code>\r
13 // in your initialization function\r
14 init : function(){\r
15    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());\r
16    var win = new Window(...);\r
17    win.restoreState();\r
18 }\r
19  </code></pre>\r
20  * @singleton\r
21  */\r
22 Ext.state.Manager = function(){\r
23     var provider = new Ext.state.Provider();\r
24 \r
25     return {\r
26         /**\r
27          * Configures the default state provider for your application\r
28          * @param {Provider} stateProvider The state provider to set\r
29          */\r
30         setProvider : function(stateProvider){\r
31             provider = stateProvider;\r
32         },\r
33 \r
34         /**\r
35          * Returns the current value for a key\r
36          * @param {String} name The key name\r
37          * @param {Mixed} defaultValue The default value to return if the key lookup does not match\r
38          * @return {Mixed} The state data\r
39          */\r
40         get : function(key, defaultValue){\r
41             return provider.get(key, defaultValue);\r
42         },\r
43 \r
44         /**\r
45          * Sets the value for a key\r
46          * @param {String} name The key name\r
47          * @param {Mixed} value The state data\r
48          */\r
49          set : function(key, value){\r
50             provider.set(key, value);\r
51         },\r
52 \r
53         /**\r
54          * Clears a value from the state\r
55          * @param {String} name The key name\r
56          */\r
57         clear : function(key){\r
58             provider.clear(key);\r
59         },\r
60 \r
61         /**\r
62          * Gets the currently configured state provider\r
63          * @return {Provider} The state provider\r
64          */\r
65         getProvider : function(){\r
66             return provider;\r
67         }\r
68     };\r
69 }();