3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
7 // Application instance for showing user-feedback messages.
8 var App = new Ext.App({});
10 // Create HttpProxy instance. Notice new configuration parameter "api" here instead of load. However, you can still use
11 // the "url" paramater -- All CRUD requests will be directed to your single url instead.
12 var proxy = new Ext.data.HttpProxy({
14 read : 'app.php/users/view',
15 create : 'app.php/users/create',
16 update: 'app.php/users/update',
17 destroy: 'app.php/users/destroy'
21 // Typical JsonReader. Notice additional meta-data params for defining the core attributes of your json-response
22 var reader = new Ext.data.JsonReader({
23 totalProperty: 'total',
24 successProperty: 'success',
29 {name: 'email', allowBlank: false},
30 {name: 'first', allowBlank: false},
31 {name: 'last', allowBlank: false}
34 // The new DataWriter component.
35 var writer = new Ext.data.JsonWriter({
40 // Typical Store collecting the Proxy, Reader and Writer together.
41 var store = new Ext.data.Store({
45 writer: writer, // <-- plug a DataWriter into the store just as you would a Reader
46 autoSave: true, // <-- false would delay executing create, update, destroy requests until specifically told to do so with some [save] buton.
48 write : function(store, action, result, res, rs) {
49 App.setAlert(res.success, res.message); // <-- show user-feedback for all write actions
51 exception : function(proxy, type, action, options, res, arg) {
52 if (type === 'remote') {
54 title: 'REMOTE EXCEPTION',
56 icon: Ext.MessageBox.ERROR,
65 // A new generic text field
66 var textField = new Ext.form.TextField();
68 // Let's pretend we rendered our grid-columns with meta-data from our ORM framework.
70 {header: "ID", width: 40, sortable: true, dataIndex: 'id'},
71 {header: "Email", width: 100, sortable: true, dataIndex: 'email', editor: textField},
72 {header: "First", width: 50, sortable: true, dataIndex: 'first', editor: textField},
73 {header: "Last", width: 50, sortable: true, dataIndex: 'last', editor: textField}
76 // load the store immeditately
80 Ext.onReady(function() {
83 // create user.Form instance (@see UserForm.js)
84 var userForm = new App.user.Form({
85 renderTo: 'user-form',
87 create : function(fpanel, data) { // <-- custom "create" event defined in App.user.Form class
88 var rec = new userGrid.store.recordType(data);
89 userGrid.store.insert(0, rec);
94 // create user.Grid instance (@see UserGrid.js)
95 var userGrid = new App.user.Grid({
96 renderTo: 'user-grid',
98 columns : userColumns,
100 rowclick: function(g, index, ev) {
101 var rec = g.store.getAt(index);
102 userForm.loadRecord(rec);
104 destroy : function() {
105 userForm.getForm().reset();