4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-state-Provider'>/**
19 </span> * @class Ext.state.Provider
20 * <p>Abstract base class for state provider implementations. The provider is responsible
21 * for setting values and extracting values to/from the underlying storage source. The
22 * storage source can vary and the details should be implemented in a subclass. For example
23 * a provider could use a server side database or the browser localstorage where supported.</p>
25 * <p>This class provides methods for encoding and decoding <b>typed</b> variables including
26 * dates and defines the Provider interface. By default these methods put the value and the
27 * type information into a delimited string that can be stored. These should be overridden in
28 * a subclass if you want to change the format of the encoded value and subsequent decoding.</p>
30 Ext.define('Ext.state.Provider', {
32 observable: 'Ext.util.Observable'
35 <span id='Ext-state-Provider-cfg-prefix'> /**
36 </span> * @cfg {String} prefix A string to prefix to items stored in the underlying state store.
37 * Defaults to <tt>'ext-'</tt>
41 constructor : function(config){
42 config = config || {};
44 Ext.apply(me, config);
45 <span id='Ext-state-Provider-event-statechange'> /**
46 </span> * @event statechange
47 * Fires when a state change occurs.
48 * @param {Provider} this This state provider
49 * @param {String} key The state key which was changed
50 * @param {String} value The encoded value for the state
52 me.addEvents("statechange");
54 me.mixins.observable.constructor.call(me);
57 <span id='Ext-state-Provider-method-get'> /**
58 </span> * Returns the current value for a key
59 * @param {String} name The key name
60 * @param {Mixed} defaultValue A default value to return if the key's value is not found
61 * @return {Mixed} The state data
63 get : function(name, defaultValue){
64 return typeof this.state[name] == "undefined" ?
65 defaultValue : this.state[name];
68 <span id='Ext-state-Provider-method-clear'> /**
69 </span> * Clears a value from the state
70 * @param {String} name The key name
72 clear : function(name){
74 delete me.state[name];
75 me.fireEvent("statechange", me, name, null);
78 <span id='Ext-state-Provider-method-set'> /**
79 </span> * Sets the value for a key
80 * @param {String} name The key name
81 * @param {Mixed} value The value to set
83 set : function(name, value){
85 me.state[name] = value;
86 me.fireEvent("statechange", me, name, value);
89 <span id='Ext-state-Provider-method-decodeValue'> /**
90 </span> * Decodes a string previously encoded with {@link #encodeValue}.
91 * @param {String} value The value to decode
92 * @return {Mixed} The decoded value
94 decodeValue : function(value){
102 // -> Empty (null)
105 re = /^(a|n|d|b|s|o|e)\:(.*)$/,
106 matches = re.exec(unescape(value)),
112 if(!matches || !matches[1]){
122 return parseFloat(value);
124 return new Date(Date.parse(value));
126 return (value == '1');
130 Ext.each(value.split('^'), function(val){
131 all.push(me.decodeValue(val));
138 Ext.each(value.split('^'), function(val){
139 keyValue = val.split('=');
140 all[keyValue[0]] = me.decodeValue(keyValue[1]);
149 <span id='Ext-state-Provider-method-encodeValue'> /**
150 </span> * Encodes a value including type information. Decode with {@link #decodeValue}.
151 * @param {Mixed} value The value to encode
152 * @return {String} The encoded value
154 encodeValue : function(value){
163 } else if(typeof value == 'number') {
165 } else if(typeof value == 'boolean') {
166 enc = 'b:' + (value ? '1' : '0');
167 } else if(Ext.isDate(value)) {
168 enc = 'd:' + value.toGMTString();
169 } else if(Ext.isArray(value)) {
170 for (len = value.length; i < len; i++) {
171 flat += this.encodeValue(value[i]);
177 } else if (typeof value == 'object') {
179 if (typeof value[key] != 'function' && value[key] !== undefined) {
180 flat += key + '=' + this.encodeValue(value[key]) + '^';
183 enc = 'o:' + flat.substring(0, flat.length-1);