+++ /dev/null
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.data.Store\r
- * @extends Ext.util.Observable\r
- * The Store class encapsulates a client side cache of {@link Ext.data.Record Record}\r
- * objects which provide input data for Components such as the {@link Ext.grid.GridPanel GridPanel},\r
- * the {@link Ext.form.ComboBox ComboBox}, or the {@link Ext.DataView DataView}</p>\r
- * <p>A Store object uses its {@link #proxy configured} implementation of {@link Ext.data.DataProxy DataProxy}\r
- * to access a data object unless you call {@link #loadData} directly and pass in your data.</p>\r
- * <p>A Store object has no knowledge of the format of the data returned by the Proxy.</p>\r
- * <p>A Store object uses its {@link #reader configured} implementation of {@link Ext.data.DataReader DataReader}\r
- * to create {@link Ext.data.Record Record} instances from the data object. These Records\r
- * are cached and made available through accessor functions.</p>\r
- * @constructor\r
- * Creates a new Store.\r
- * @param {Object} config A config object containing the objects needed for the Store to access data,\r
- * and read the data into Records.\r
- */\r
-Ext.data.Store = function(config){\r
- this.data = new Ext.util.MixedCollection(false);\r
- this.data.getKey = function(o){\r
- return o.id;\r
- };\r
- /**\r
- * An object containing properties which are used as parameters on any HTTP request.\r
- * This property can be changed after creating the Store to send different parameters.\r
- * @property\r
- */\r
- this.baseParams = {};\r
- /**\r
- * <p>An object containing properties which specify the names of the paging and\r
- * sorting parameters passed to remote servers when loading blocks of data. By default, this\r
- * object takes the following form:</p><pre><code>\r
-{\r
- start : "start", // The parameter name which specifies the start row\r
- limit : "limit", // The parameter name which specifies number of rows to return\r
- sort : "sort", // The parameter name which specifies the column to sort on\r
- dir : "dir" // The parameter name which specifies the sort direction\r
-}\r
-</code></pre>\r
- * <p>The server must produce the requested data block upon receipt of these parameter names.\r
- * If different parameter names are required, this property can be overriden using a configuration\r
- * property.</p>\r
- * <p>A {@link Ext.PagingToolbar PagingToolbar} bound to this grid uses this property to determine\r
- * the parameter names to use in its requests.\r
- * @property\r
- */\r
- this.paramNames = {\r
- "start" : "start",\r
- "limit" : "limit",\r
- "sort" : "sort",\r
- "dir" : "dir"\r
- };\r
-\r
- if(config && config.data){\r
- this.inlineData = config.data;\r
- delete config.data;\r
- }\r
-\r
- Ext.apply(this, config);\r
-\r
- if(this.url && !this.proxy){\r
- this.proxy = new Ext.data.HttpProxy({url: this.url});\r
- }\r
-\r
- if(this.reader){ // reader passed\r
- if(!this.recordType){\r
- this.recordType = this.reader.recordType;\r
- }\r
- if(this.reader.onMetaChange){\r
- this.reader.onMetaChange = this.onMetaChange.createDelegate(this);\r
- }\r
- }\r
-\r
- /**\r
- * The {@link Ext.data.Record Record} constructor as supplied to (or created by) the {@link Ext.data.Reader#Reader Reader}. Read-only.\r
- * <p>If the Reader was constructed by passing in an Array of field definition objects, instead of an created\r
- * Record constructor it will have {@link Ext.data.Record#create created a constructor} from that Array.</p>\r
- * <p>This property may be used to create new Records of the type held in this Store.</p>\r
- * @property recordType\r
- * @type Function\r
- */\r
- if(this.recordType){\r
- /**\r
- * A MixedCollection containing the defined {@link Ext.data.Field Field}s for the Records stored in this Store. Read-only.\r
- * @property fields\r
- * @type Ext.util.MixedCollection\r
- */\r
- this.fields = this.recordType.prototype.fields;\r
- }\r
- this.modified = [];\r
-\r
- this.addEvents(\r
- /**\r
- * @event datachanged\r
- * Fires when the data cache has changed in a bulk manner (e.g., it has been sorted, filtered, etc.) and a \r
- * widget that is using this Store as a Record cache should refresh its view.\r
- * @param {Store} this\r
- */\r
- 'datachanged',\r
- /**\r
- * @event metachange\r
- * Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders.\r
- * @param {Store} this\r
- * @param {Object} meta The JSON metadata\r
- */\r
- 'metachange',\r
- /**\r
- * @event add\r
- * Fires when Records have been added to the Store\r
- * @param {Store} this\r
- * @param {Ext.data.Record[]} records The array of Records added\r
- * @param {Number} index The index at which the record(s) were added\r
- */\r
- 'add',\r
- /**\r
- * @event remove\r
- * Fires when a Record has been removed from the Store\r
- * @param {Store} this\r
- * @param {Ext.data.Record} record The Record that was removed\r
- * @param {Number} index The index at which the record was removed\r
- */\r
- 'remove',\r
- /**\r
- * @event update\r
- * Fires when a Record has been updated\r
- * @param {Store} this\r
- * @param {Ext.data.Record} record The Record that was updated\r
- * @param {String} operation The update operation being performed. Value may be one of:\r
- * <pre><code>\r
- Ext.data.Record.EDIT\r
- Ext.data.Record.REJECT\r
- Ext.data.Record.COMMIT\r
- * </code></pre>\r
- */\r
- 'update',\r
- /**\r
- * @event clear\r
- * Fires when the data cache has been cleared.\r
- * @param {Store} this\r
- */\r
- 'clear',\r
- /**\r
- * @event beforeload\r
- * Fires before a request is made for a new data object. If the beforeload handler returns false\r
- * the load action will be canceled.\r
- * @param {Store} this\r
- * @param {Object} options The loading options that were specified (see {@link #load} for details)\r
- */\r
- 'beforeload',\r
- /**\r
- * @event load\r
- * Fires after a new set of Records has been loaded.\r
- * @param {Store} this\r
- * @param {Ext.data.Record[]} records The Records that were loaded\r
- * @param {Object} options The loading options that were specified (see {@link #load} for details)\r
- */\r
- 'load',\r
- /**\r
- * @event loadexception\r
- * Fires if an exception occurs in the Proxy during loading.\r
- * Called with the signature of the Proxy's "loadexception" event.\r
- */\r
- 'loadexception'\r
- );\r
-\r
- if(this.proxy){\r
- this.relayEvents(this.proxy, ["loadexception"]);\r
- }\r
-\r
- this.sortToggle = {};\r
- if(this.sortInfo){\r
- this.setDefaultSort(this.sortInfo.field, this.sortInfo.direction);\r
- }\r
-\r
- Ext.data.Store.superclass.constructor.call(this);\r
-\r
- if(this.storeId || this.id){\r
- Ext.StoreMgr.register(this);\r
- }\r
- if(this.inlineData){\r
- this.loadData(this.inlineData);\r
- delete this.inlineData;\r
- }else if(this.autoLoad){\r
- this.load.defer(10, this, [\r
- typeof this.autoLoad == 'object' ?\r
- this.autoLoad : undefined]);\r
- }\r
-};\r
-Ext.extend(Ext.data.Store, Ext.util.Observable, {\r
- /**\r
- * @cfg {String} storeId If passed, the id to use to register with the StoreMgr\r
- */\r
- /**\r
- * @cfg {String} url If passed, an HttpProxy is created for the passed URL\r
- */\r
- /**\r
- * @cfg {Boolean/Object} autoLoad If passed, this store's load method is automatically called after creation with the autoLoad object\r
- */\r
- /**\r
- * @cfg {Ext.data.DataProxy} proxy The Proxy object which provides access to a data object.\r
- */\r
- /**\r
- * @cfg {Array} data Inline data to be loaded when the store is initialized.\r
- */\r
- /**\r
- * @cfg {Ext.data.DataReader} reader The DataReader object which processes the data object and returns\r
- * an Array of Ext.data.Record objects which are cached keyed by their <em>id</em> property.\r
- */\r
- /**\r
- * @cfg {Object} baseParams An object containing properties which are to be sent as parameters\r
- * on any HTTP request\r
- */\r
- /**\r
- * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"} to \r
- * specify the sort order in the request of a remote Store's {@link #load} operation. Note that for\r
- * local sorting, the direction property is case-sensitive.\r
- */\r
- /**\r
- * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the\r
- * Proxy to provide a refreshed version of the data object in sorted order, as\r
- * opposed to sorting the Record cache in place (defaults to false).\r
- * <p>If remote sorting is specified, then clicking on a column header causes the\r
- * current page to be requested from the server with the addition of the following\r
- * two parameters:\r
- * <div class="mdetail-params"><ul>\r
- * <li><b>sort</b> : String<p class="sub-desc">The name (as specified in\r
- * the Record's Field definition) of the field to sort on.</p></li>\r
- * <li><b>dir</b> : String<p class="sub-desc">The direction of the sort, "ASC" or "DESC" (case-sensitive).</p></li>\r
- * </ul></div></p>\r
- */\r
- remoteSort : false,\r
-\r
- /**\r
- * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is\r
- * loaded or when a record is removed. (defaults to false).\r
- */\r
- pruneModifiedRecords : false,\r
-\r
- /**\r
- * Contains the last options object used as the parameter to the load method. See {@link #load}\r
- * for the details of what this may contain. This may be useful for accessing any params which\r
- * were used to load the current Record cache.\r
- * @property\r
- */\r
- lastOptions : null,\r
-\r
- destroy : function(){\r
- if(this.storeId || this.id){\r
- Ext.StoreMgr.unregister(this);\r
- }\r
- this.data = null;\r
- this.purgeListeners();\r
- },\r
-\r
- /**\r
- * Add Records to the Store and fires the {@link #add} event.\r
- * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects to add to the cache.\r
- */\r
- add : function(records){\r
- records = [].concat(records);\r
- if(records.length < 1){\r
- return;\r
- }\r
- for(var i = 0, len = records.length; i < len; i++){\r
- records[i].join(this);\r
- }\r
- var index = this.data.length;\r
- this.data.addAll(records);\r
- if(this.snapshot){\r
- this.snapshot.addAll(records);\r
- }\r
- this.fireEvent("add", this, records, index);\r
- },\r
-\r
- /**\r
- * (Local sort only) Inserts the passed Record into the Store at the index where it\r
- * should go based on the current sort information.\r
- * @param {Ext.data.Record} record\r
- */\r
- addSorted : function(record){\r
- var index = this.findInsertIndex(record);\r
- this.insert(index, record);\r
- },\r
-\r
- /**\r
- * Remove a Record from the Store and fires the {@link #remove} event.\r
- * @param {Ext.data.Record} record The Ext.data.Record object to remove from the cache.\r
- */\r
- remove : function(record){\r
- var index = this.data.indexOf(record);\r
- this.data.removeAt(index);\r
- if(this.pruneModifiedRecords){\r
- this.modified.remove(record);\r
- }\r
- if(this.snapshot){\r
- this.snapshot.remove(record);\r
- }\r
- this.fireEvent("remove", this, record, index);\r
- },\r
- \r
- /**\r
- * Remove a Record from the Store at the specified index. Fires the {@link #remove} event.\r
- * @param {Number} index The index of the record to remove.\r
- */\r
- removeAt : function(index){\r
- this.remove(this.getAt(index)); \r
- },\r
-\r
- /**\r
- * Remove all Records from the Store and fires the {@link #clear} event.\r
- */\r
- removeAll : function(){\r
- this.data.clear();\r
- if(this.snapshot){\r
- this.snapshot.clear();\r
- }\r
- if(this.pruneModifiedRecords){\r
- this.modified = [];\r
- }\r
- this.fireEvent("clear", this);\r
- },\r
-\r
- /**\r
- * Inserts Records into the Store at the given index and fires the {@link #add} event.\r
- * @param {Number} index The start index at which to insert the passed Records.\r
- * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects to add to the cache.\r
- */\r
- insert : function(index, records){\r
- records = [].concat(records);\r
- for(var i = 0, len = records.length; i < len; i++){\r
- this.data.insert(index, records[i]);\r
- records[i].join(this);\r
- }\r
- this.fireEvent("add", this, records, index);\r
- },\r
-\r
- /**\r
- * Get the index within the cache of the passed Record.\r
- * @param {Ext.data.Record} record The Ext.data.Record object to find.\r
- * @return {Number} The index of the passed Record. Returns -1 if not found.\r
- */\r
- indexOf : function(record){\r
- return this.data.indexOf(record);\r
- },\r
-\r
- /**\r
- * Get the index within the cache of the Record with the passed id.\r
- * @param {String} id The id of the Record to find.\r
- * @return {Number} The index of the Record. Returns -1 if not found.\r
- */\r
- indexOfId : function(id){\r
- return this.data.indexOfKey(id);\r
- },\r
-\r
- /**\r
- * Get the Record with the specified id.\r
- * @param {String} id The id of the Record to find.\r
- * @return {Ext.data.Record} The Record with the passed id. Returns undefined if not found.\r
- */\r
- getById : function(id){\r
- return this.data.key(id);\r
- },\r
-\r
- /**\r
- * Get the Record at the specified index.\r
- * @param {Number} index The index of the Record to find.\r
- * @return {Ext.data.Record} The Record at the passed index. Returns undefined if not found.\r
- */\r
- getAt : function(index){\r
- return this.data.itemAt(index);\r
- },\r
-\r
- /**\r
- * Returns a range of Records between specified indices.\r
- * @param {Number} startIndex (optional) The starting index (defaults to 0)\r
- * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)\r
- * @return {Ext.data.Record[]} An array of Records\r
- */\r
- getRange : function(start, end){\r
- return this.data.getRange(start, end);\r
- },\r
-\r
- // private\r
- storeOptions : function(o){\r
- o = Ext.apply({}, o);\r
- delete o.callback;\r
- delete o.scope;\r
- this.lastOptions = o;\r
- },\r
-\r
- /**\r
- * Loads the Record cache from the configured Proxy using the configured Reader.\r
- * <p>If using remote paging, then the first load call must specify the <tt>start</tt>\r
- * and <tt>limit</tt> properties in the options.params property to establish the initial\r
- * position within the dataset, and the number of Records to cache on each read from the Proxy.</p>\r
- * <p><b>It is important to note that for remote data sources, loading is asynchronous,\r
- * and this call will return before the new data has been loaded. Perform any post-processing\r
- * in a callback function, or in a "load" event handler.</b></p>\r
- * @param {Object} options An object containing properties which control loading options:<ul>\r
- * <li><b>params</b> :Object<p class="sub-desc">An object containing properties to pass as HTTP parameters to a remote data source.</p></li>\r
- * <li><b>callback</b> : Function<p class="sub-desc">A function to be called after the Records have been loaded. The callback is\r
- * passed the following arguments:<ul>\r
- * <li>r : Ext.data.Record[]</li>\r
- * <li>options: Options object from the load call</li>\r
- * <li>success: Boolean success indicator</li></ul></p></li>\r
- * <li><b>scope</b> : Object<p class="sub-desc">Scope with which to call the callback (defaults to the Store object)</p></li>\r
- * <li><b>add</b> : Boolean<p class="sub-desc">Indicator to append loaded records rather than replace the current cache.</p></li>\r
- * </ul>\r
- * @return {Boolean} Whether the load fired (if beforeload failed).\r
- */\r
- load : function(options){\r
- options = options || {};\r
- if(this.fireEvent("beforeload", this, options) !== false){\r
- this.storeOptions(options);\r
- var p = Ext.apply(options.params || {}, this.baseParams);\r
- if(this.sortInfo && this.remoteSort){\r
- var pn = this.paramNames;\r
- p[pn["sort"]] = this.sortInfo.field;\r
- p[pn["dir"]] = this.sortInfo.direction;\r
- }\r
- this.proxy.load(p, this.reader, this.loadRecords, this, options);\r
- return true;\r
- } else {\r
- return false;\r
- }\r
- },\r
-\r
- /**\r
- * <p>Reloads the Record cache from the configured Proxy using the configured Reader and\r
- * the options from the last load operation performed.</p>\r
- * <p><b>It is important to note that for remote data sources, loading is asynchronous,\r
- * and this call will return before the new data has been loaded. Perform any post-processing\r
- * in a callback function, or in a "load" event handler.</b></p>\r
- * @param {Object} options (optional) An object containing loading options which may override the options\r
- * used in the last load operation. See {@link #load} for details (defaults to null, in which case\r
- * the most recently used options are reused).\r
- */\r
- reload : function(options){\r
- this.load(Ext.applyIf(options||{}, this.lastOptions));\r
- },\r
-\r
- // private\r
- // Called as a callback by the Reader during a load operation.\r
- loadRecords : function(o, options, success){\r
- if(!o || success === false){\r
- if(success !== false){\r
- this.fireEvent("load", this, [], options);\r
- }\r
- if(options.callback){\r
- options.callback.call(options.scope || this, [], options, false);\r
- }\r
- return;\r
- }\r
- var r = o.records, t = o.totalRecords || r.length;\r
- if(!options || options.add !== true){\r
- if(this.pruneModifiedRecords){\r
- this.modified = [];\r
- }\r
- for(var i = 0, len = r.length; i < len; i++){\r
- r[i].join(this);\r
- }\r
- if(this.snapshot){\r
- this.data = this.snapshot;\r
- delete this.snapshot;\r
- }\r
- this.data.clear();\r
- this.data.addAll(r);\r
- this.totalLength = t;\r
- this.applySort();\r
- this.fireEvent("datachanged", this);\r
- }else{\r
- this.totalLength = Math.max(t, this.data.length+r.length);\r
- this.add(r);\r
- }\r
- this.fireEvent("load", this, r, options);\r
- if(options.callback){\r
- options.callback.call(options.scope || this, r, options, true);\r
- }\r
- },\r
-\r
- /**\r
- * Loads data from a passed data block and fires the {@link #load} event. A Reader which understands the format of the data\r
- * must have been configured in the constructor.\r
- * @param {Object} data The data block from which to read the Records. The format of the data expected\r
- * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.\r
- * @param {Boolean} add (Optional) True to add the new Records rather than replace the existing cache. <b>Remember that\r
- * Records in a Store are keyed by their {@link Ext.data.Record#id id}, so added Records with ids which are already present in\r
- * the Store will <i>replace</i> existing Records. Records with new, unique ids will be added.</b>\r
- */\r
- loadData : function(o, append){\r
- var r = this.reader.readRecords(o);\r
- this.loadRecords(r, {add: append}, true);\r
- },\r
-\r
- /**\r
- * Gets the number of cached records.\r
- * <p>If using paging, this may not be the total size of the dataset. If the data object\r
- * used by the Reader contains the dataset size, then the {@link #getTotalCount} function returns\r
- * the dataset size.</p>\r
- * @return {Number} The number of Records in the Store's cache.\r
- */\r
- getCount : function(){\r
- return this.data.length || 0;\r
- },\r
-\r
- /**\r
- * Gets the total number of records in the dataset as returned by the server.\r
- * <p>If using paging, for this to be accurate, the data object used by the Reader must contain\r
- * the dataset size. For remote data sources, this is provided by a query on the server.</p>\r
- * @return {Number} The number of Records as specified in the data object passed to the Reader\r
- * by the Proxy\r
- * <p><b>This value is not updated when changing the contents of the Store locally.</b></p>\r
- */\r
- getTotalCount : function(){\r
- return this.totalLength || 0;\r
- },\r
-\r
- /**\r
- * Returns an object describing the current sort state of this Store.\r
- * @return {Object} The sort state of the Store. An object with two properties:<ul>\r
- * <li><b>field : String<p class="sub-desc">The name of the field by which the Records are sorted.</p></li>\r
- * <li><b>direction : String<p class="sub-desc">The sort order, "ASC" or "DESC" (case-sensitive).</p></li>\r
- * </ul>\r
- */\r
- getSortState : function(){\r
- return this.sortInfo;\r
- },\r
-\r
- // private\r
- applySort : function(){\r
- if(this.sortInfo && !this.remoteSort){\r
- var s = this.sortInfo, f = s.field;\r
- this.sortData(f, s.direction);\r
- }\r
- },\r
-\r
- // private\r
- sortData : function(f, direction){\r
- direction = direction || 'ASC';\r
- var st = this.fields.get(f).sortType;\r
- var fn = function(r1, r2){\r
- var v1 = st(r1.data[f]), v2 = st(r2.data[f]);\r
- return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);\r
- };\r
- this.data.sort(direction, fn);\r
- if(this.snapshot && this.snapshot != this.data){\r
- this.snapshot.sort(direction, fn);\r
- }\r
- },\r
-\r
- /**\r
- * Sets the default sort column and order to be used by the next load operation.\r
- * @param {String} fieldName The name of the field to sort by.\r
- * @param {String} dir (optional) The sort order, "ASC" or "DESC" (case-sensitive, defaults to "ASC")\r
- */\r
- setDefaultSort : function(field, dir){\r
- dir = dir ? dir.toUpperCase() : "ASC";\r
- this.sortInfo = {field: field, direction: dir};\r
- this.sortToggle[field] = dir;\r
- },\r
-\r
- /**\r
- * Sort the Records.\r
- * If remote sorting is used, the sort is performed on the server, and the cache is\r
- * reloaded. If local sorting is used, the cache is sorted internally.\r
- * @param {String} fieldName The name of the field to sort by.\r
- * @param {String} dir (optional) The sort order, "ASC" or "DESC" (case-sensitive, defaults to "ASC")\r
- */\r
- sort : function(fieldName, dir){\r
- var f = this.fields.get(fieldName);\r
- if(!f){\r
- return false;\r
- }\r
- if(!dir){\r
- if(this.sortInfo && this.sortInfo.field == f.name){ // toggle sort dir\r
- dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");\r
- }else{\r
- dir = f.sortDir;\r
- }\r
- }\r
- var st = (this.sortToggle) ? this.sortToggle[f.name] : null;\r
- var si = (this.sortInfo) ? this.sortInfo : null;\r
-\r
- this.sortToggle[f.name] = dir;\r
- this.sortInfo = {field: f.name, direction: dir};\r
- if(!this.remoteSort){\r
- this.applySort();\r
- this.fireEvent("datachanged", this);\r
- }else{\r
- if (!this.load(this.lastOptions)) {\r
- if (st) {\r
- this.sortToggle[f.name] = st;\r
- }\r
- if (si) {\r
- this.sortInfo = si;\r
- }\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Calls the specified function for each of the Records in the cache.\r
- * @param {Function} fn The function to call. The Record is passed as the first parameter.\r
- * Returning <tt>false</tt> aborts and exits the iteration.\r
- * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).\r
- */\r
- each : function(fn, scope){\r
- this.data.each(fn, scope);\r
- },\r
-\r
- /**\r
- * Gets all records modified since the last commit. Modified records are persisted across load operations\r
- * (e.g., during paging).\r
- * @return {Ext.data.Record[]} An array of Records containing outstanding modifications.\r
- */\r
- getModifiedRecords : function(){\r
- return this.modified;\r
- },\r
-\r
- // private\r
- createFilterFn : function(property, value, anyMatch, caseSensitive){\r
- if(Ext.isEmpty(value, false)){\r
- return false;\r
- }\r
- value = this.data.createValueMatcher(value, anyMatch, caseSensitive);\r
- return function(r){\r
- return value.test(r.data[property]);\r
- };\r
- },\r
-\r
- /**\r
- * Sums the value of <i>property</i> for each record between start and end and returns the result.\r
- * @param {String} property A field on your records\r
- * @param {Number} start The record index to start at (defaults to 0)\r
- * @param {Number} end The last record index to include (defaults to length - 1)\r
- * @return {Number} The sum\r
- */\r
- sum : function(property, start, end){\r
- var rs = this.data.items, v = 0;\r
- start = start || 0;\r
- end = (end || end === 0) ? end : rs.length-1;\r
-\r
- for(var i = start; i <= end; i++){\r
- v += (rs[i].data[property] || 0);\r
- }\r
- return v;\r
- },\r
-\r
- /**\r
- * Filter the records by a specified property.\r
- * @param {String} field A field on your records\r
- * @param {String/RegExp} value Either a string that the field\r
- * should begin with, or a RegExp to test against the field.\r
- * @param {Boolean} anyMatch (optional) True to match any part not just the beginning\r
- * @param {Boolean} caseSensitive (optional) True for case sensitive comparison\r
- */\r
- filter : function(property, value, anyMatch, caseSensitive){\r
- var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);\r
- return fn ? this.filterBy(fn) : this.clearFilter();\r
- },\r
-\r
- /**\r
- * Filter by a function. The specified function will be called for each\r
- * Record in this Store. If the function returns <tt>true</tt> the Record is included,\r
- * otherwise it is filtered out.\r
- * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>\r
- * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}\r
- * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>\r
- * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>\r
- * </ul>\r
- * @param {Object} scope (optional) The scope of the function (defaults to this)\r
- */\r
- filterBy : function(fn, scope){\r
- this.snapshot = this.snapshot || this.data;\r
- this.data = this.queryBy(fn, scope||this);\r
- this.fireEvent("datachanged", this);\r
- },\r
-\r
- /**\r
- * Query the records by a specified property.\r
- * @param {String} field A field on your records\r
- * @param {String/RegExp} value Either a string that the field\r
- * should begin with, or a RegExp to test against the field.\r
- * @param {Boolean} anyMatch (optional) True to match any part not just the beginning\r
- * @param {Boolean} caseSensitive (optional) True for case sensitive comparison\r
- * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records\r
- */\r
- query : function(property, value, anyMatch, caseSensitive){\r
- var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);\r
- return fn ? this.queryBy(fn) : this.data.clone();\r
- },\r
-\r
- /**\r
- * Query the cached records in this Store using a filtering function. The specified function\r
- * will be called with each record in this Store. If the function returns <tt>true</tt> the record is\r
- * included in the results.\r
- * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>\r
- * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}\r
- * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>\r
- * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>\r
- * </ul>\r
- * @param {Object} scope (optional) The scope of the function (defaults to this)\r
- * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records\r
- **/\r
- queryBy : function(fn, scope){\r
- var data = this.snapshot || this.data;\r
- return data.filterBy(fn, scope||this);\r
- },\r
-\r
- /**\r
- * Finds the index of the first matching record in this store by a specific property/value.\r
- * @param {String} property A property on your objects\r
- * @param {String/RegExp} value Either a string that the property value\r
- * should begin with, or a RegExp to test against the property.\r
- * @param {Number} startIndex (optional) The index to start searching at\r
- * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning\r
- * @param {Boolean} caseSensitive (optional) True for case sensitive comparison\r
- * @return {Number} The matched index or -1\r
- */\r
- find : function(property, value, start, anyMatch, caseSensitive){\r
- var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);\r
- return fn ? this.data.findIndexBy(fn, null, start) : -1;\r
- },\r
-\r
- /**\r
- * Find the index of the first matching Record in this Store by a function.\r
- * If the function returns <tt>true</tt> it is considered a match.\r
- * @param {Function} fn The function to be called. It will be passed the following parameters:<ul>\r
- * <li><b>record</b> : Ext.data.Record<p class="sub-desc">The {@link Ext.data.Record record}\r
- * to test for filtering. Access field values using {@link Ext.data.Record#get}.</p></li>\r
- * <li><b>id</b> : Object<p class="sub-desc">The ID of the Record passed.</p></li>\r
- * </ul>\r
- * @param {Object} scope (optional) The scope of the function (defaults to this)\r
- * @param {Number} startIndex (optional) The index to start searching at\r
- * @return {Number} The matched index or -1\r
- */\r
- findBy : function(fn, scope, start){\r
- return this.data.findIndexBy(fn, scope, start);\r
- },\r
-\r
- /**\r
- * Collects unique values for a particular dataIndex from this store.\r
- * @param {String} dataIndex The property to collect\r
- * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values\r
- * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered\r
- * @return {Array} An array of the unique values\r
- **/\r
- collect : function(dataIndex, allowNull, bypassFilter){\r
- var d = (bypassFilter === true && this.snapshot) ?\r
- this.snapshot.items : this.data.items;\r
- var v, sv, r = [], l = {};\r
- for(var i = 0, len = d.length; i < len; i++){\r
- v = d[i].data[dataIndex];\r
- sv = String(v);\r
- if((allowNull || !Ext.isEmpty(v)) && !l[sv]){\r
- l[sv] = true;\r
- r[r.length] = v;\r
- }\r
- }\r
- return r;\r
- },\r
-\r
- /**\r
- * Revert to a view of the Record cache with no filtering applied.\r
- * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners\r
- */\r
- clearFilter : function(suppressEvent){\r
- if(this.isFiltered()){\r
- this.data = this.snapshot;\r
- delete this.snapshot;\r
- if(suppressEvent !== true){\r
- this.fireEvent("datachanged", this);\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Returns true if this store is currently filtered\r
- * @return {Boolean}\r
- */\r
- isFiltered : function(){\r
- return this.snapshot && this.snapshot != this.data;\r
- },\r
-\r
- // private\r
- afterEdit : function(record){\r
- if(this.modified.indexOf(record) == -1){\r
- this.modified.push(record);\r
- }\r
- this.fireEvent("update", this, record, Ext.data.Record.EDIT);\r
- },\r
-\r
- // private\r
- afterReject : function(record){\r
- this.modified.remove(record);\r
- this.fireEvent("update", this, record, Ext.data.Record.REJECT);\r
- },\r
-\r
- // private\r
- afterCommit : function(record){\r
- this.modified.remove(record);\r
- this.fireEvent("update", this, record, Ext.data.Record.COMMIT);\r
- },\r
-\r
- /**\r
- * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the\r
- * Store's "update" event, and perform updating when the third parameter is Ext.data.Record.COMMIT.\r
- */\r
- commitChanges : function(){\r
- var m = this.modified.slice(0);\r
- this.modified = [];\r
- for(var i = 0, len = m.length; i < len; i++){\r
- m[i].commit();\r
- }\r
- },\r
-\r
- /**\r
- * Cancel outstanding changes on all changed records.\r
- */\r
- rejectChanges : function(){\r
- var m = this.modified.slice(0);\r
- this.modified = [];\r
- for(var i = 0, len = m.length; i < len; i++){\r
- m[i].reject();\r
- }\r
- },\r
-\r
- // private\r
- onMetaChange : function(meta, rtype, o){\r
- this.recordType = rtype;\r
- this.fields = rtype.prototype.fields;\r
- delete this.snapshot;\r
- this.sortInfo = meta.sortInfo;\r
- this.modified = [];\r
- this.fireEvent('metachange', this, this.reader.meta);\r
- },\r
-\r
- // private\r
- findInsertIndex : function(record){\r
- this.suspendEvents();\r
- var data = this.data.clone();\r
- this.data.add(record);\r
- this.applySort();\r
- var index = this.data.indexOf(record);\r
- this.data = data;\r
- this.resumeEvents();\r
- return index;\r
- }\r
-});
\ No newline at end of file