initial import
[roojs1] / Roo / state / Manager.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11 /**
12  * @class Roo.state.Manager
13  * This is the global state manager. By default all components that are "state aware" check this class
14  * for state information if you don't pass them a custom state provider. In order for this class
15  * to be useful, it must be initialized with a provider when your application initializes.
16  <pre><code>
17 // in your initialization function
18 init : function(){
19    Roo.state.Manager.setProvider(new Roo.state.CookieProvider());
20    ...
21    // supposed you have a {@link Roo.BorderLayout}
22    var layout = new Roo.BorderLayout(...);
23    layout.restoreState();
24    // or a {Roo.BasicDialog}
25    var dialog = new Roo.BasicDialog(...);
26    dialog.restoreState();
27  </code></pre>
28  * @singleton
29  */
30 Roo.state.Manager = function(){
31     var provider = new Roo.state.Provider();
32     
33     return {
34         /**
35          * Configures the default state provider for your application
36          * @param {Provider} stateProvider The state provider to set
37          */
38         setProvider : function(stateProvider){
39             provider = stateProvider;
40         },
41         
42         /**
43          * Returns the current value for a key
44          * @param {String} name The key name
45          * @param {Mixed} defaultValue The default value to return if the key lookup does not match
46          * @return {Mixed} The state data
47          */
48         get : function(key, defaultValue){
49             return provider.get(key, defaultValue);
50         },
51         
52         /**
53          * Sets the value for a key
54          * @param {String} name The key name
55          * @param {Mixed} value The state data
56          */
57          set : function(key, value){
58             provider.set(key, value);
59         },
60         
61         /**
62          * Clears a value from the state
63          * @param {String} name The key name
64          */
65         clear : function(key){
66             provider.clear(key);
67         },
68         
69         /**
70          * Gets the currently configured state provider
71          * @return {Provider} The state provider
72          */
73         getProvider : function(){
74             return provider;
75         }
76     };
77 }();