StateManager.js 2.1 KB

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