X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775:/pkgs/data-foundation-debug.js diff --git a/pkgs/data-foundation-debug.js b/pkgs/data-foundation-debug.js index 5076cfc8..8164b7dc 100644 --- a/pkgs/data-foundation-debug.js +++ b/pkgs/data-foundation-debug.js @@ -1,9 +1,10 @@ /*! - * 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 */ + /** * @class Ext.data.Api * @extends Object @@ -184,10 +185,86 @@ new Ext.data.HttpProxy({ for (var verb in this.restActions) { proxy.api[this.actions[verb]].method = this.restActions[verb]; } + // TODO: perhaps move this interceptor elsewhere? like into DataProxy, perhaps? Placed here + // to satisfy initial 3.0 final release of REST features. + proxy.onWrite = proxy.onWrite.createInterceptor(function(action, o, response, rs) { + var reader = o.reader; + var res = new Ext.data.Response({ + action: action, + raw: response + }); + + switch (response.status) { + case 200: // standard 200 response, send control back to HttpProxy#onWrite + return true; + break; + case 201: // entity created but no response returned + //res[reader.meta.successProperty] = true; + res.success = true; + break; + case 204: // no-content. Create a fake response. + //res[reader.meta.successProperty] = true; + //res[reader.meta.root] = null; + res.success = true; + res.data = null; + break; + default: + return true; + break; + } + /* + if (res[reader.meta.successProperty] === true) { + this.fireEvent("write", this, action, res[reader.meta.root], res, rs, o.request.arg); + } else { + this.fireEvent('exception', this, 'remote', action, o, res, rs); + } + */ + if (res.success === true) { + this.fireEvent("write", this, action, res.data, res, rs, o.request.arg); + } else { + this.fireEvent('exception', this, 'remote', action, o, res, rs); + } + o.request.callback.call(o.request.scope, res.data, res, res.success); + + return false; // <-- false to prevent intercepted function from running. + }, proxy); } }; })(); +/** + * Ext.data.Response + * Experimental. Do not use directly. + */ +Ext.data.Response = function(params, response) { + Ext.apply(this, params, { + raw: response + }); +}; +Ext.data.Response.prototype = { + message : null, + success : false, + status : null, + root : null, + raw : null, + + getMessage : function() { + return this.message; + }, + getSuccess : function() { + return this.success; + }, + getStatus : function() { + return this.status + }, + getRoot : function() { + return this.root; + }, + getRawResponse : function() { + return this.raw; + } +}; + /** * @class Ext.data.Api.Error * @extends Ext.Error @@ -208,6 +285,8 @@ Ext.apply(Ext.data.Api.Error.prototype, { 'execute': 'Attempted to execute an unknown action. Valid API actions are defined in Ext.data.Api.actions"' } }); + + /** * @class Ext.data.SortTypes @@ -309,8 +388,9 @@ Ext.data.SortTypes = { * {@link #data} and {@link #id} properties.

*

Record objects generated by this constructor inherit all the methods of Ext.data.Record listed below.

* @constructor - * This constructor should not be used to create Record objects. Instead, use {@link #create} to - * generate a subclass of Ext.data.Record configured with information about its constituent fields. + *

This constructor should not be used to create Record objects. Instead, use {@link #create} to + * generate a subclass of Ext.data.Record configured with information about its constituent fields.

+ *

The generated constructor has the same signature as this constructor.

* @param {Object} data (Optional) An object, the properties of which provide values for the new Record's * fields. If not specified the {@link Ext.data.Field#defaultValue defaultValue} * for each field will be assigned. @@ -361,7 +441,7 @@ myStore.{@link Ext.data.Store#add add}(myNewRecord); * @method create * @return {function} A constructor which is used to create new Records according - * to the definition. The constructor has the same signature as {@link #Ext.data.Record}. + * to the definition. The constructor has the same signature as {@link #Record}. * @static */ Ext.data.Record.create = function(o){ @@ -813,6 +893,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, @@ -841,7 +924,7 @@ Ext.data.Store = function(config){ } Ext.apply(this, config); - + this.paramNames = Ext.applyIf(this.paramNames || {}, this.defaultParamNames); if(this.url && !this.proxy){ @@ -859,7 +942,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; @@ -991,6 +1075,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', /** @@ -1032,7 +1117,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) @@ -1042,9 +1127,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. @@ -1063,7 +1147,8 @@ var grid = new Ext.grid.EditorGridPanel({ scope: this, add: this.createRecords, remove: this.destroyRecord, - update: this.updateRecord + update: this.updateRecord, + clear: this.onClear }); } @@ -1241,7 +1326,7 @@ sortInfo: { * internally be set to false.

*/ restful: false, - + /** * @cfg {Object} paramNames *

An object containing properties which specify the names of the paging and @@ -1261,7 +1346,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 @@ -1278,13 +1363,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(); }, /** @@ -1327,6 +1416,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); @@ -1350,14 +1440,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); }, /** @@ -1429,6 +1530,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: