X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..05ce1c11e98b33f14ddee184493bd5a60dc947e2:/src/data/Store.js?ds=inline diff --git a/src/data/Store.js b/src/data/Store.js index fb368f73..2bc6be73 100644 --- a/src/data/Store.js +++ b/src/data/Store.js @@ -1,5 +1,5 @@ /*! - * Ext JS Library 3.0.0 + * Ext JS Library 3.0.3 * Copyright(c) 2006-2009 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license @@ -67,6 +67,9 @@ var recId = 100; // provide unique id for the record var r = new myStore.recordType(defaultData, ++recId); // create new record myStore.{@link #insert}(0, r); // insert a new record into the store (also see {@link #add}) * + *
Writing Data
+ *And new in Ext version 3, use the new {@link Ext.data.DataWriter DataWriter} to create an automated, Writable Store
+ * along with RESTful features.
* @constructor
* Creates a new Store.
* @param {Object} config A config object containing the objects needed for the Store to access data,
@@ -95,7 +98,7 @@ Ext.data.Store = function(config){
}
Ext.apply(this, config);
-
+
this.paramNames = Ext.applyIf(this.paramNames || {}, this.defaultParamNames);
if(this.url && !this.proxy){
@@ -113,7 +116,8 @@ Ext.data.Store = function(config){
this.recordType = this.reader.recordType;
}
if(this.reader.onMetaChange){
- this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
+ //this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
+ this.reader.onMetaChange = this.reader.onMetaChange.createSequence(this.onMetaChange, this);
}
if (this.writer) { // writer passed
this.writer.meta = this.reader.meta;
@@ -245,6 +249,7 @@ var grid = new Ext.grid.EditorGridPanel({
* @event clear
* Fires when the data cache has been cleared.
* @param {Store} this
+ * @param {Record[]} The records that were cleared.
*/
'clear',
/**
@@ -286,7 +291,7 @@ var grid = new Ext.grid.EditorGridPanel({
'loadexception',
/**
* @event beforewrite
- * @param {DataProxy} this
+ * @param {Ext.data.Store} store
* @param {String} action [Ext.data.Api.actions.create|update|destroy]
* @param {Record/Array[Record]} rs
* @param {Object} options The loading options that were specified. Edit options.params
to add Http parameters to the request. (see {@link #save} for details)
@@ -296,9 +301,8 @@ var grid = new Ext.grid.EditorGridPanel({
/**
* @event write
* Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
- * Success or failure of the action is available in the result['successProperty']
property.
- * The server-code might set the successProperty
to false if a database validation
- * failed, for example.
+ * Success of the action is determined in the result['successProperty']
property (NOTE for RESTful stores,
+ * a simple 20x response is sufficient for the actions "destroy" and "update". The "create" action should should return 200 along with a database pk).
* @param {Ext.data.Store} store
* @param {String} action [Ext.data.Api.actions.create|update|destroy]
* @param {Object} result The 'data' picked-out out of the response for convenience.
@@ -317,7 +321,8 @@ var grid = new Ext.grid.EditorGridPanel({
scope: this,
add: this.createRecords,
remove: this.destroyRecord,
- update: this.updateRecord
+ update: this.updateRecord,
+ clear: this.onClear
});
}
@@ -495,7 +500,7 @@ sortInfo: {
* internally be set to false.
An object containing properties which specify the names of the paging and @@ -515,7 +520,7 @@ sortInfo: { * the parameter names to use in its {@link #load requests}. */ paramNames : undefined, - + /** * @cfg {Object} defaultParamNames * Provides the default values for the {@link #paramNames} property. To globally modify the parameters @@ -532,13 +537,17 @@ sortInfo: { * Destroys the store. */ destroy : function(){ - if(this.storeId){ - Ext.StoreMgr.unregister(this); + if(!this.isDestroyed){ + if(this.storeId){ + Ext.StoreMgr.unregister(this); + } + this.clearData(); + this.data = null; + Ext.destroy(this.proxy); + this.reader = this.writer = null; + this.purgeListeners(); + this.isDestroyed = true; } - this.data = null; - Ext.destroy(this.proxy); - this.reader = this.writer = null; - this.purgeListeners(); }, /** @@ -581,6 +590,7 @@ sortInfo: { remove : function(record){ var index = this.data.indexOf(record); if(index > -1){ + record.join(null); this.data.removeAt(index); if(this.pruneModifiedRecords){ this.modified.remove(record); @@ -604,14 +614,25 @@ sortInfo: { * Remove all Records from the Store and fires the {@link #clear} event. */ removeAll : function(){ - this.data.clear(); + var items = []; + this.each(function(rec){ + items.push(rec); + }); + this.clearData(); if(this.snapshot){ this.snapshot.clear(); } if(this.pruneModifiedRecords){ this.modified = []; } - this.fireEvent('clear', this); + this.fireEvent('clear', this, items); + }, + + // private + onClear: function(store, records){ + Ext.each(records, function(rec, index){ + this.destroyRecord(this, rec, index); + }, this); }, /** @@ -683,6 +704,14 @@ sortInfo: { this.lastOptions = o; }, + // private + clearData: function(){ + this.data.each(function(rec) { + rec.join(null); + }); + this.data.clear(); + }, + /** *
Loads the Record cache from the configured {@link #proxy} using the configured {@link #reader}.
*Notes: