X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..6e39d509471fe9b4e2660e0d1631b350d0c66f40:/src/data/DataProxy.js diff --git a/src/data/DataProxy.js b/src/data/DataProxy.js index 2f40235a..2b64bfb5 100644 --- a/src/data/DataProxy.js +++ b/src/data/DataProxy.js @@ -1,5 +1,5 @@ /*! - * Ext JS Library 3.0.0 + * Ext JS Library 3.1.0 * Copyright(c) 2006-2009 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license @@ -39,6 +39,25 @@ proxy : new Ext.data.HttpProxy({ } }), * + *

And new in Ext version 3, attach centralized event-listeners upon the DataProxy class itself! This is a great place + * to implement a messaging system to centralize your application's user-feedback and error-handling.

+ *

+// Listen to all "beforewrite" event fired by all proxies.
+Ext.data.DataProxy.on('beforewrite', function(proxy, action) {
+    console.log('beforewrite: ', action);
+});
+
+// Listen to "write" event fired by all proxies
+Ext.data.DataProxy.on('write', function(proxy, action, data, res, rs) {
+    console.info('write: ', action);
+});
+
+// Listen to "exception" event fired by all proxies
+Ext.data.DataProxy.on('exception', function(proxy, type, action) {
+    console.error(type + action + ' exception);
+});
+ * 
+ * Note: These three events are all fired with the signature of the corresponding DataProxy instance event {@link #beforewrite beforewrite}, {@link #write write} and {@link #exception exception}. */ Ext.data.DataProxy = function(conn){ // make sure we have a config object here to support ux proxies. @@ -67,7 +86,27 @@ api: { update : undefined, destroy : undefined } - + * + *

The url is built based upon the action being executed [load|create|save|destroy] + * using the commensurate {@link #api} property, or if undefined default to the + * configured {@link Ext.data.Store}.{@link Ext.data.Store#url url}.


+ *

For example:

+ *

+api: {
+    load :    '/controller/load',
+    create :  '/controller/new',  // Server MUST return idProperty of new record
+    save :    '/controller/update',
+    destroy : '/controller/destroy_action'
+}
+
+// Alternatively, one can use the object-form to specify each API-action
+api: {
+    load: {url: 'read.php', method: 'GET'},
+    create: 'create.php',
+    destroy: 'destroy.php',
+    save: 'update.php'
+}
+     * 
*

If the specific URL for a given CRUD action is undefined, the CRUD action request * will be directed to the configured {@link Ext.data.Connection#url url}.

*

Note: To modify the URL for an action dynamically the appropriate API @@ -85,22 +124,9 @@ myStore.on({ // permanent, applying this URL for all subsequent requests. store.proxy.setUrl('changed1.php', true); - // manually set the private connection URL. - // Warning: Accessing the private URL property should be avoided. - // Use the public method {@link Ext.data.HttpProxy#setUrl setUrl} instead, shown above. - // It should be noted that changing the URL like this will affect - // the URL for just this request. Subsequent requests will use the - // API or URL defined in your initial proxy configuration. - store.proxy.conn.url = 'changed1.php'; - - // proxy URL will be superseded by API (only if proxy created to use ajax): - // It should be noted that proxy API changes are permanent and will - // be used for all subsequent requests. - store.proxy.api.load = 'changed2.php'; - - // However, altering the proxy API should be done using the public - // method {@link Ext.data.DataProxy#setApi setApi} instead. - store.proxy.setApi('load', 'changed2.php'); + // Altering the proxy API should be done using the public + // method {@link Ext.data.DataProxy#setApi setApi}. + store.proxy.setApi('read', 'changed2.php'); // Or set the entire API with a config-object. // When using the config-object option, you must redefine the entire @@ -117,23 +143,17 @@ myStore.on({ * *

*/ - // Prepare the proxy api. Ensures all API-actions are defined with the Object-form. - try { - Ext.data.Api.prepare(this); - } catch (e) { - if (e instanceof Ext.data.Api.Error) { - e.toConsole(); - } - } this.addEvents( /** * @event exception - *

Fires if an exception occurs in the Proxy during a remote request. - * This event is relayed through a corresponding - * {@link Ext.data.Store}.{@link Ext.data.Store#exception exception}, - * so any Store instance may observe this event. - * This event can be fired for one of two reasons:

+ *

Fires if an exception occurs in the Proxy during a remote request. This event is relayed + * through a corresponding {@link Ext.data.Store}.{@link Ext.data.Store#exception exception}, + * so any Store instance may observe this event.

+ *

In addition to being fired through the DataProxy instance that raised the event, this event is also fired + * through the Ext.data.DataProxy class to allow for centralized processing of exception events from all + * DataProxies by attaching a listener to the Ext.data.Proxy class itself.

+ *

This event can be fired for one of two reasons:

*