X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/6746dc89c47ed01b165cc1152533605f97eb8e8d..f562e4c6e5fac7bcb445985b99acbea4d706e6f0:/src/state/Stateful.js diff --git a/src/state/Stateful.js b/src/state/Stateful.js index d916f2f6..76c44882 100644 --- a/src/state/Stateful.js +++ b/src/state/Stateful.js @@ -55,7 +55,7 @@ Ext.state.Manager.setProvider(new Ext.state.CookieProvider({ * object hash which represents the restorable state of the object.

*

The value yielded by getState is passed to {@link Ext.state.Manager#set} * which uses the configured {@link Ext.state.Provider} to save the object - * keyed by the {@link #stateId}

. + * keyed by the {@link #stateId}.

*

During construction, a stateful object attempts to restore * its state by calling {@link Ext.state.Manager#get} passing the * {@link #stateId}

@@ -76,9 +76,9 @@ Ext.state.Manager.setProvider(new Ext.state.CookieProvider({ */ /** - * @cfg {Array} stateEvents + * @cfg {String[]} stateEvents *

An array of events that, when fired, should trigger this object to - * save its state (defaults to none). stateEvents may be any type + * save its state. Defaults to none. stateEvents may be any type * of event supported by this object, including browser or custom events * (e.g., ['click', 'customerchange']).

*

See {@link #stateful} for an explanation of saving and @@ -86,8 +86,8 @@ Ext.state.Manager.setProvider(new Ext.state.CookieProvider({ */ /** - * @cfg {Number} saveBuffer A buffer to be applied if many state events are fired within - * a short period. Defaults to 100. + * @cfg {Number} saveDelay + * A buffer to be applied if many state events are fired within a short period. */ saveDelay: 100, @@ -172,7 +172,7 @@ Ext.state.Manager.setProvider(new Ext.state.CookieProvider({ /** * Add events that will trigger the state to be saved. - * @param {String/Array} events The event name or an array of event names. + * @param {String/String[]} events The event name or an array of event names. */ addStateEvents: function(events){ if (!Ext.isArray(events)) { @@ -285,6 +285,41 @@ Ext.state.Manager.setProvider(new Ext.state.CookieProvider({ } }, + /** + * Conditionally saves a single property from this object to the given state object. + * The idea is to only save state which has changed from the initial state so that + * current software settings do not override future software settings. Only those + * values that are user-changed state should be saved. + * + * @param {String} propName The name of the property to save. + * @param {Object} state The state object in to which to save the property. + * @param {String} stateName (optional) The name to use for the property in state. + * @return {Boolean} True if the property was saved, false if not. + */ + savePropToState: function (propName, state, stateName) { + var me = this, + value = me[propName], + config = me.initialConfig; + + if (me.hasOwnProperty(propName)) { + if (!config || config[propName] !== value) { + if (state) { + state[stateName || propName] = value; + } + return true; + } + } + return false; + }, + + savePropsToState: function (propNames, state) { + var me = this; + Ext.each(propNames, function (propName) { + me.savePropToState(propName, state); + }); + return state; + }, + /** * Destroys this stateful object. */