/*!
- * Ext JS Library 3.0.3
+ * Ext JS Library 3.1.0
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
}\r
}),\r
* </code></pre>\r
+ * <p>And <b>new in Ext version 3</b>, attach centralized event-listeners upon the DataProxy class itself! This is a great place\r
+ * to implement a <i>messaging system</i> to centralize your application's user-feedback and error-handling.</p>\r
+ * <pre><code>\r
+// Listen to all "beforewrite" event fired by all proxies.\r
+Ext.data.DataProxy.on('beforewrite', function(proxy, action) {\r
+ console.log('beforewrite: ', action);\r
+});\r
+\r
+// Listen to "write" event fired by all proxies\r
+Ext.data.DataProxy.on('write', function(proxy, action, data, res, rs) {\r
+ console.info('write: ', action);\r
+});\r
+\r
+// Listen to "exception" event fired by all proxies\r
+Ext.data.DataProxy.on('exception', function(proxy, type, action) {\r
+ console.error(type + action + ' exception);\r
+});\r
+ * </code></pre>\r
+ * <b>Note:</b> These three events are all fired with the signature of the corresponding <i>DataProxy instance</i> event {@link #beforewrite beforewrite}, {@link #write write} and {@link #exception exception}.\r
*/\r
Ext.data.DataProxy = function(conn){\r
// make sure we have a config object here to support ux proxies.\r
* @param {Object} params\r
* @param {Ext.data.DataReader} reader\r
* @param {Function} callback\r
- * @param {Object} scope Scope with which to call the callback (defaults to the Proxy object)\r
+ * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the Proxy object.\r
* @param {Object} options Any options specified for the action (e.g. see {@link Ext.data.Store#load}.\r
*/\r
request : function(action, rs, params, reader, callback, scope, options) {\r
load : null,\r
\r
/**\r
- * @cfg {Function} doRequest Abstract method that should be implemented in all subclasses\r
+ * @cfg {Function} doRequest Abstract method that should be implemented in all subclasses. <b>Note:</b> Should only be used by custom-proxy developers.\r
* (e.g.: {@link Ext.data.HttpProxy#doRequest HttpProxy.doRequest},\r
* {@link Ext.data.DirectProxy#doRequest DirectProxy.doRequest}).\r
*/\r
this.load(params, reader, callback, scope, options);\r
},\r
\r
+ /**\r
+ * @cfg {Function} onRead Abstract method that should be implemented in all subclasses. <b>Note:</b> Should only be used by custom-proxy developers. Callback for read {@link Ext.data.Api#actions action}.\r
+ * @param {String} action Action name as per {@link Ext.data.Api.actions#read}.\r
+ * @param {Object} o The request transaction object\r
+ * @param {Object} res The server response\r
+ * @fires loadexception (deprecated)\r
+ * @fires exception\r
+ * @fires load\r
+ * @protected\r
+ */\r
+ onRead : Ext.emptyFn,\r
+ /**\r
+ * @cfg {Function} onWrite Abstract method that should be implemented in all subclasses. <b>Note:</b> Should only be used by custom-proxy developers. Callback for <i>create, update and destroy</i> {@link Ext.data.Api#actions actions}.\r
+ * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]\r
+ * @param {Object} trans The request transaction object\r
+ * @param {Object} res The server response\r
+ * @fires exception\r
+ * @fires write\r
+ * @protected\r
+ */\r
+ onWrite : Ext.emptyFn,\r
/**\r
* buildUrl\r
* Sets the appropriate url based upon the action being executed. If restful is true, and only a single record is being acted upon,\r
*/\r
buildUrl : function(action, record) {\r
record = record || null;\r
- var url = (this.api[action]) ? this.api[action].url : this.url;\r
+\r
+ // conn.url gets nullified after each request. If it's NOT null here, that means the user must have intervened with a call\r
+ // to DataProxy#setUrl or DataProxy#setApi and changed it before the request was executed. If that's the case, use conn.url,\r
+ // otherwise, build the url from the api or this.url.\r
+ var url = (this.conn && this.conn.url) ? this.conn.url : (this.api[action]) ? this.api[action].url : this.url;\r
if (!url) {\r
throw new Ext.data.Api.Error('invalid-url', action);\r
}\r
\r
- // look for urls having "provides" suffix (from Rails/Merb and others...),\r
- // e.g.: /users.json, /users.xml, etc\r
+ // look for urls having "provides" suffix used in some MVC frameworks like Rails/Merb and others. The provides suffice informs\r
+ // the server what data-format the client is dealing with and returns data in the same format (eg: application/json, application/xml, etc)\r
+ // e.g.: /users.json, /users.xml, etc.\r
// with restful routes, we need urls like:\r
// PUT /users/1.json\r
// DELETE /users/1.json\r
- var format = null;\r
+ var provides = null;\r
var m = url.match(/(.*)(\.json|\.xml|\.html)$/);\r
if (m) {\r
- format = m[2]; // eg ".json"\r
- url = m[1]; // eg: "/users"\r
+ provides = m[2]; // eg ".json"\r
+ url = m[1]; // eg: "/users"\r
}\r
// prettyUrls is deprectated in favor of restful-config\r
- if ((this.prettyUrls === true || this.restful === true) && record instanceof Ext.data.Record && !record.phantom) {\r
+ if ((this.restful === true || this.prettyUrls === true) && record instanceof Ext.data.Record && !record.phantom) {\r
url += '/' + record.id;\r
}\r
- if (format) { // <-- append the request format if exists (ie: /users/update/69[.json])\r
- url += format;\r
- }\r
- return url;\r
+ return (provides === null) ? url : url + provides;\r
},\r
\r
/**\r