/********
* @version : 2.1.1 - Ext.NET Pro License
* @author : Ext.NET, Inc. http://www.ext.net/
* @date : 2012-12-10
* @copyright : Copyright (c) 2007-2012, Ext.NET, Inc. (http://www.ext.net/). All rights reserved.
* @license : See license.txt and http://www.ext.net/license/.
********/
using System.ComponentModel;
using System.Web.UI;
using Ext.Net.Utilities;
namespace Ext.Net
{
///
/// AbstractStore is a superclass of Ext.data.Store and Ext.data.TreeStore. It's never used directly, but offers a set of methods used by both of those subclasses.
/// We've left it here in the docs for reference purposes, but unless you need to make a whole new type of Store, what you're probably looking for is Ext.data.Store. If you're still interested, here's a brief description of what AbstractStore is and is not.
/// AbstractStore provides the basic configuration for anything that can be considered a Store. It expects to be given a Model that represents the type of data in the Store. It also expects to be given a Proxy that handles the loading of data into the Store.
/// AbstractStore provides a few helpful methods such as load and sync, which load and save data respectively, passing the requests through the configured proxy. Both built-in Store subclasses add extra behavior to each of these functions. Note also that each AbstractStore subclass has its own way of storing data - in Ext.data.Store the data is saved as a flat MixedCollection, whereas in TreeStore we use a Ext.data.Tree to maintain the data's hierarchy.
/// The store provides filtering and sorting support. This sorting/filtering can happen on the client side or can be completed on the server. This is controlled by the remoteSort and remoteFilter config options. For more information see the sort and filter methods.
///
[Meta]
[Description("")]
public abstract partial class AbstractStore : Observable
{
protected override void OnBeforeClientInit(Observable sender)
{
if (this.SyncUrl.IsNotEmpty())
{
if (this.Proxy.Count > 0 && this.Proxy.Primary is ServerProxy)
{
((ServerProxy)this.Proxy.Primary).API.Sync = this.SyncUrl;
}
else if (this.ModelInstance != null && this.ModelInstance.Proxy.Count > 0 && this.ModelInstance.Proxy.Primary is ServerProxy)
{
((ServerProxy)this.ModelInstance.Proxy.Primary).API.Sync = this.SyncUrl;
}
else if (this.ServerProxy.Count > 0)
{
if (this.ServerProxy.Primary is ServerProxy)
{
((ServerProxy)this.ServerProxy.Primary).API.Sync = this.SyncUrl;
}
}
else
{
this.ServerProxy.Add(new AjaxProxy
{
API =
{
Sync = this.SyncUrl
}
});
}
}
base.OnBeforeClientInit(sender);
}
///
///
///
[Description("")]
protected internal override bool IsIdRequired
{
get
{
return !this.IsGeneratedID || !(this.IsSelfRender || this.IsPageSelfRender || this.IsDynamic || this.IsMVC) || this.ForceIdRendering;
}
}
///
///
///
[ConfigOption("storeId")]
[DefaultValue("")]
[Description("")]
protected override string ConfigIDProxy
{
get
{
return base.ConfigIDProxy;
}
}
///
///
///
protected virtual string StoreType
{
get
{
return "";
}
}
///
///
///
[ConfigOption("type")]
[DefaultValue("")]
protected string StoreTypeProxy
{
get
{
return this.IsLazy ? this.StoreType : "";
}
}
///
///
///
[Description("")]
protected override bool RemoveContainer
{
get
{
return true;
}
}
///
/// true to destroy the store when the component the store is bound to is destroyed (defaults to false). Note: this should be set to true when using stores that are bound to only 1 component.
///
[Meta]
[ConfigOption]
[Category("3. AbstractStore")]
[DefaultValue(false)]
[NotifyParentProperty(true)]
[Description("true to destroy the store when the component the store is bound to is destroyed (defaults to false). Note: this should be set to true when using stores that are bound to only 1 component.")]
public virtual bool AutoDestroy
{
get
{
return this.State.Get("AutoDestroy", false);
}
set
{
this.State.Set("AutoDestroy", value);
}
}
///
/// If data is not specified, and if autoLoad is true or an Object, this store's load method is automatically called after creation. If the value of autoLoad is an Object, this Object will be passed to the store's load method. Defaults to false.
///
[Meta]
[Category("3. AbstractStore")]
[DefaultValue(true)]
[Description("If data is not specified, and if autoLoad is true or an Object, this store's load method is automatically called after creation. If the value of autoLoad is an Object, this Object will be passed to the store's load method. Defaults to false.")]
public virtual bool AutoLoad
{
get
{
return this.State.Get("AutoLoad", true);
}
set
{
this.State.Set("AutoLoad", value);
}
}
///
///
///
public virtual bool IsAutoLoadUndefined
{
get
{
return this.State.Get("AutoLoad", true);
}
}
///
///
///
[ConfigOption("autoLoad")]
[DefaultValue(false)]
[Description("")]
protected virtual bool AutoLoadProxy
{
get
{
if (this.AutoLoadParams.Count == 0)
{
return this.AutoLoad;
}
return false;
}
}
private ParameterCollection autoParams;
///
/// If data is not specified, and if autoLoad is true or an Object, this store's load method is automatically called after creation. If the value of autoLoad is an Object, this Object will be passed to the store's load method.
///
[Meta]
[Category("3. Store")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("An object containing properties which are to be sent as parameters on auto load HTTP request.")]
public virtual ParameterCollection AutoLoadParams
{
get
{
return this.autoParams ?? (this.autoParams = new ParameterCollection { Owner = this });
}
}
///
///
///
[ConfigOption("autoLoad", typeof(AutoLoadParamsJsonConverter))]
[Description("")]
protected ParameterCollection AutoLoadParamsProxy
{
get
{
if (this.AutoLoad == false)
{
return new ParameterCollection();
}
return this.AutoLoadParams;
}
}
private StoreParameterCollection parameters;
///
/// An object containing properties which are to be sent as parameters on any HTTP request.
///
[Meta]
[Category("3. Store")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("An object containing properties which are to be sent as parameters on any HTTP request.")]
public virtual StoreParameterCollection Parameters
{
get
{
return this.parameters ?? (this.parameters = new StoreParameterCollection {Owner = this});
}
}
///
///
///
[DefaultValue("")]
[ConfigOption("readParameters", JsonMode.Raw)]
protected virtual string ParametersProxy
{
get
{
return this.Parameters.Count == 0 ? "" : this.Parameters.Serialize(true, false);
}
}
private StoreParameterCollection syncParameters;
///
/// An object containing properties which are to be sent as parameters on sync request.
///
[Meta]
[Category("3. Store")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("An object containing properties which are to be sent as parameters on sync request.")]
public virtual StoreParameterCollection SyncParameters
{
get
{
return this.syncParameters ?? (this.syncParameters = new StoreParameterCollection { Owner = this });
}
}
///
///
///
[DefaultValue("")]
[ConfigOption("writeParameters", JsonMode.Raw)]
protected virtual string SyncParametersProxy
{
get
{
return this.SyncParameters.Count == 0 ? "" : this.SyncParameters.Serialize(true, true);
}
}
///
/// True to automatically sync the Store with its Proxy after every edit to one of its Records. Defaults to false.
///
[Meta]
[ConfigOption]
[Category("3. AbstractStore")]
[DefaultValue(false)]
[Description("True to automatically sync the Store with its Proxy after every edit to one of its Records. Defaults to false.")]
public virtual bool AutoSync
{
get
{
return this.State.Get("AutoSync", false);
}
set
{
this.State.Set("AutoSync", value);
}
}
private ProxyCollection proxy;
///
/// The Proxy to use for this Store.
///
[Meta]
[ConfigOption("proxy>Primary")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The Proxy to use for this Store.")]
public virtual ProxyCollection Proxy
{
get
{
return this.proxy ?? (this.proxy = new ProxyCollection());
}
}
///
///
///
[Meta]
[Category("3. AbstractStore")]
[DefaultValue("")]
[Description("")]
public virtual string SyncUrl
{
get
{
return this.State.Get("SyncUrl", "");
}
set
{
this.State.Set("SyncUrl", value);
}
}
private ProxyCollection serverProxy;
///
/// The Proxy to use for reload or sync actions when Memory proxy is used for initial data
///
[Meta]
[ConfigOption("serverProxy>Primary")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The Proxy to use for this Store.")]
public virtual ProxyCollection ServerProxy
{
get
{
return this.serverProxy ?? (this.serverProxy = new ProxyCollection());
}
}
///
/// Sets the updating behavior based on batch synchronization. 'operation' (the default) will update the Store's internal representation of the data after each operation of the batch has completed, 'complete' will wait until the entire batch has been completed before updating the Store's data. 'complete' is a good choice for local storage proxies, 'operation' is better for remote proxies, where there is a comparatively high latency.
///
[Meta]
[ConfigOption(JsonMode.ToLower)]
[DefaultValue(BatchUpdateMode.Operation)]
[Description("Sets the updating behavior based on batch synchronization.")]
public virtual BatchUpdateMode BatchUpdateMode
{
get
{
return this.State.Get("BatchUpdateMode", BatchUpdateMode.Operation);
}
set
{
this.State.Set("BatchUpdateMode", value);
}
}
///
/// If true, any filters attached to this Store will be run after loading data, before the datachanged event is fired. Defaults to true, ignored if remoteFilter is true
///
[Meta]
[ConfigOption]
[DefaultValue(true)]
[Description("If true, any filters attached to this Store will be run after loading data, before the datachanged event is fired. Defaults to true, ignored if remoteFilter is true")]
public virtual bool FilterOnLoad
{
get
{
return this.State.Get("FilterOnLoad", true);
}
set
{
this.State.Set("FilterOnLoad", value);
}
}
private DataFilterCollection filters;
///
/// The collection of Filters currently applied to this Store
///
[Meta]
[ConfigOption(JsonMode.AlwaysArray)]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The collection of Filters currently applied to this Store")]
public virtual DataFilterCollection Filters
{
get
{
return this.filters ?? (this.filters = new DataFilterCollection());
}
}
///
/// If true, any sorters attached to this Store will be run after loading data, before the datachanged event is fired. Defaults to true, igored if remoteSort is true
///
[Meta]
[ConfigOption]
[DefaultValue(true)]
[Description("If true, any sorters attached to this Store will be run after loading data, before the datachanged event is fired. Defaults to true, igored if remoteSort is true")]
public virtual bool SortOnLoad
{
get
{
return this.State.Get("SortOnLoad", true);
}
set
{
this.State.Set("SortOnLoad", value);
}
}
///
/// The field name by which to sort the store's data (defaults to '').
///
[Meta]
[ConfigOption]
[Category("3. Store")]
[DefaultValue("")]
[Description("The field name by which to sort the store's data (defaults to '').")]
public virtual string SortRoot
{
get
{
return this.State.Get("SortRoot", "");
}
set
{
this.State.Set("SortRoot", value);
}
}
private DataSorterCollection sorters;
///
/// The collection of Sorters currently applied to this Store
///
[Meta]
[ConfigOption(JsonMode.AlwaysArray)]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The collection of Sorters currently applied to this Store")]
public virtual DataSorterCollection Sorters
{
get
{
return this.sorters ?? (this.sorters = new DataSorterCollection());
}
}
///
/// Show warning if request fail.
///
[Meta]
[ConfigOption]
[DefaultValue(true)]
[NotifyParentProperty(true)]
[Description("Show a Window with error message is DirectEvent request fails.")]
public bool ShowWarningOnFailure
{
get
{
return this.State.Get("ShowWarningOnFailure", true);
}
set
{
this.State.Set("ShowWarningOnFailure", value);
}
}
///
/// The Ext.data.Model associated with this store
///
[Meta]
[ConfigOption("model")]
[DefaultValue(null)]
[Description("The Ext.data.Model associated with this store")]
public virtual string ModelName
{
get
{
return this.State.Get("ModelName", null);
}
set
{
this.modelInstance = null;
this.State.Set("ModelName", value);
}
}
private ModelCollection model;
///
///
///
[Meta]
[ConfigOption("model>Primary", 1)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("")]
public virtual ModelCollection Model
{
get
{
if (this.model == null)
{
this.model = new ModelCollection();
this.model.AfterItemAdd += this.AfterItemAdd;
this.model.AfterItemRemove += this.AfterItemRemove;
}
return this.model;
}
}
private Model modelInstance;
///
///
///
public virtual Model ModelInstance
{
get
{
if (this.DesignMode)
{
return null;
}
if (this.modelInstance != null)
{
return this.modelInstance;
}
if (this.Model.Primary != null)
{
return this.Model.Primary;
}
if (this.ModelName.IsEmpty() && !this.DesignMode)
{
return null;
//throw new Exception("Model is not defined for the store");
}
if (!Ext.Net.Model.IsRegistered(this.ModelName) && !this.DesignMode)
{
return null;
//throw new Exception("Model with name '{0}' doesn't exist".FormatWith(this.ModelName));
}
this.modelInstance = Ext.Net.Model.Get(this.ModelName);
return this.modelInstance;
}
}
///
/// Loads data into the Store via the configured proxy. This uses the Proxy to make an asynchronous call to whatever storage backend the Proxy uses, automatically adding the retrieved instances into the Store and calling an optional callback if required.
///
/// config object, passed into the Ext.data.Operation object before loading. Additionally addRecords: true can be specified to add these records to the existing records, default is to remove the Store's existing records first.
[Meta]
public virtual void LoadProxy(object options)
{
this.Call("load", options);
}
///
/// Loads data into the Store via the configured proxy. This uses the Proxy to make an asynchronous call to whatever storage backend the Proxy uses, automatically adding the retrieved instances into the Store and calling an optional callback if required.
///
[Meta]
public virtual void LoadProxy()
{
this.Call("load");
}
///
/// Reloads the Store.
///
[Meta]
public virtual void Reload()
{
this.Call("reload");
}
///
/// Reloads the Store.
///
/// Optional config object. This is passed into the Operation object that is created and then sent to the proxy's Ext.data.proxy.Proxy.read function
[Meta]
public virtual void Reload(object options)
{
this.Call("reload", options);
}
///
/// Reloads the Store.
///
/// Optional config object. This is passed into the Operation object that is created and then sent to the proxy's Ext.data.proxy.Proxy.read function
/// The new Proxy, which is an instance
[Meta]
public virtual void Reload(object options, AbstractProxy proxy)
{
this.Call("reload", options, new ClientConfig().Serialize(proxy, true));
}
///
/// Reloads the Store.
///
/// Optional config object. This is passed into the Operation object as the options.params that is created and then sent to the proxy's Ext.data.proxy.Proxy.read function
[Meta]
public virtual void Reload(ParameterCollection parameters)
{
this.Reload(new
{
@params = JRawValue.From(parameters.ToJson())
});
}
///
/// Sets the Store's Proxy by string
///
/// The new Proxy, which is a type string
[Meta]
public virtual void SetProxy(string proxyType)
{
this.Call("setProxy", proxyType);
}
///
/// Sets the Store's Proxy by instance
///
/// The new Proxy, which is an instance
[Meta]
public virtual void SetProxy(AbstractProxy proxy)
{
this.Call("setProxy", new ClientConfig().Serialize(proxy, true));
}
///
/// Synchronizes the Store with its Proxy. This asks the Proxy to batch together any new, updated and deleted records in the store, updating the Store's internal representation of the records as each operation completes.
///
[Meta]
public virtual void Sync()
{
this.Call("sync");
}
///
/// Resumes automatically syncing the Store with its Proxy. Only applicable if autoSync is true
///
[Meta]
public virtual void ResumeAutoSync()
{
this.Call("resumeAutoSync");
}
///
/// Suspends automatically syncing the Store with its Proxy. Only applicable if autoSync is true
///
[Meta]
public virtual void SuspendAutoSync()
{
this.Call("suspendAutoSync");
}
}
}