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