-// The new DataWriter component.
-var writer = new Ext.data.JsonWriter({
- encode: false // <-- don't return encoded JSON -- causes Ext.Ajax#request to send data using jsonData config rather than HTTP params
-});
-
-// Typical Store collecting the Proxy, Reader and Writer together.
-var store = new Ext.data.Store({
- id: 'user',
- restful: true, // <-- This Store is RESTful
- proxy: proxy,
- reader: reader,
- writer: writer // <-- plug a DataWriter into the store just as you would a Reader
-});
-
-// 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) {
- App.setAlert(false, "Something bad happend while executing " + action);
-});
-
-// Let's pretend we rendered our grid-columns with meta-data from our ORM framework.
-var userColumns = [
- {header: "ID", width: 40, sortable: true, dataIndex: 'id'},
- {header: "Email", width: 100, sortable: true, dataIndex: 'email', editor: new Ext.form.TextField({})},
- {header: "First", width: 50, sortable: true, dataIndex: 'first', editor: new Ext.form.TextField({})},
- {header: "Last", width: 50, sortable: true, dataIndex: 'last', editor: new Ext.form.TextField({})}
-];
-
-
-Ext.onReady(function() {
- Ext.QuickTips.init();
-
- // use RowEditor for editing
- var editor = new Ext.ux.grid.RowEditor({
- saveText: 'Update'
+ var store = Ext.create('Ext.data.Store', {
+ autoLoad: true,
+ autoSync: true,
+ model: 'Person',
+ proxy: {
+ type: 'rest',
+ url: 'app.php/users',
+ reader: {
+ type: 'json',
+ root: 'data'
+ },
+ writer: {
+ type: 'json'
+ }
+ },
+ listeners: {
+ write: function(store, operation){
+ var record = operation.records[0],
+ name = Ext.String.capitalize(operation.action),
+ verb;
+
+ if (name == 'Destroy') {
+ verb = 'Destroyed';
+ } else {
+ verb = name + 'd';
+ }
+ Ext.example.msg(name, Ext.String.format("{0} user: {1}", verb, record.getId()));
+
+ }
+ }