Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / examples / writer / writer.js
index 5c307b6..a2ee1b7 100644 (file)
@@ -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
  * Copyright(c) 2006-2009 Ext JS, LLC
  * licensing@extjs.com
  * http://www.extjs.com/license
@@ -23,7 +23,8 @@ var reader = new Ext.data.JsonReader({
     totalProperty: 'total',
     successProperty: 'success',
     idProperty: 'id',
     totalProperty: 'total',
     successProperty: 'success',
     idProperty: 'id',
-    root: 'data'
+    root: 'data',
+    messageProperty: 'message'  // <-- New "messageProperty" meta-data
 }, [
     {name: 'id'},
     {name: 'email', allowBlank: false},
 }, [
     {name: 'id'},
     {name: 'email', allowBlank: false},
@@ -43,24 +44,43 @@ var store = new Ext.data.Store({
     proxy: proxy,
     reader: reader,
     writer: writer,  // <-- plug a DataWriter into the store just as you would a Reader
     proxy: proxy,
     reader: reader,
     writer: writer,  // <-- plug a DataWriter into the store just as you would a Reader
-    autoSave: true,  // <-- false would delay executing create, update, destroy requests until specifically told to do so with some [save] buton.
-    listeners: {
-        write : function(store, action, result, res, rs) {
-            App.setAlert(res.success, res.message); // <-- show user-feedback for all write actions
-        },
-        exception : function(proxy, type, action, options, res, arg) {
-            if (type === 'remote') {
-                Ext.Msg.show({
-                    title: 'REMOTE EXCEPTION',
-                    msg: res.message,
-                    icon: Ext.MessageBox.ERROR,
-                    buttons: Ext.Msg.OK
-                });
-            }
-        }
-    }
+    autoSave: true // <-- false would delay executing create, update, destroy requests until specifically told to do so with some [save] buton.
+});
+
+// load the store immeditately
+store.load();
+
+////
+// ***New*** centralized listening of DataProxy events "beforewrite", "write" and "writeexception"
+// upon Ext.data.DataProxy class.  This is handy for centralizing user-feedback messaging into one place rather than
+// attaching listenrs to EACH Store.
+//
+// Listen to all DataProxy beforewrite events
+//
+Ext.data.DataProxy.addListener('beforewrite', function(proxy, action) {
+    App.setAlert(App.STATUS_NOTICE, "Before " + action);
 });
 
 });
 
+////
+// all write events
+//
+Ext.data.DataProxy.addListener('write', function(proxy, action, result, res, rs) {
+    App.setAlert(true, action + ':' + res.message);
+});
+
+////
+// all exception events
+//
+Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) {
+    if (type === 'remote') {
+        Ext.Msg.show({
+            title: 'REMOTE EXCEPTION',
+            msg: res.message,
+            icon: Ext.MessageBox.ERROR,
+            buttons: Ext.Msg.OK
+        });
+    }
+});
 
 // A new generic text field
 var textField =  new Ext.form.TextField();
 
 // A new generic text field
 var textField =  new Ext.form.TextField();
@@ -73,10 +93,6 @@ var userColumns =  [
     {header: "Last", width: 50, sortable: true, dataIndex: 'last', editor: textField}
 ];
 
     {header: "Last", width: 50, sortable: true, dataIndex: 'last', editor: textField}
 ];
 
-// load the store immeditately
-store.load();
-
-
 Ext.onReady(function() {
     Ext.QuickTips.init();
 
 Ext.onReady(function() {
     Ext.QuickTips.init();