Skip to content

Instantly share code, notes, and snippets.

@jacobheric
Created March 13, 2011 02:13
Show Gist options
  • Save jacobheric/867803 to your computer and use it in GitHub Desktop.
Save jacobheric/867803 to your computer and use it in GitHub Desktop.
A sample extjs crud grid and form app (building on the extjs example offering)
Ext.ns("youbrew");
// Application instance for showing user-feedback messages.
var App = new Ext.App({});
// HttpProxy instance, utilizes parameter "api" object here constructing url manually.
var proxy = new Ext.data.HttpProxy({
api: {
read : {url: 'recipe', method: 'GET'},
create : {url: 'recipe', method: 'POST'},
update: {url: 'recipe', method: 'PUT'},
destroy: {url: 'recipe', method: 'DELETE'}
}
});
// Recipe json reader
var reader = new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'id',
root: 'items',
messageProperty: 'message'
}, [
{name: 'id'},
{name: 'name', allowBlank: false},
{name: 'brewNotes', allowBlank: false},
{name: 'tasteNotes', allowBlank: false},
{name: 'yeast', allowBlank: true},
{name: 'yeastName', allowBlank: true}
]);
// DataWriter component.
var writer = new Ext.data.JsonWriter({
encode: false,
writeAllFields: true,
listful: true
});
// Store collecting the Proxy, Reader and Writer together.
var store = new Ext.data.Store({
id: 'recipes',
proxy: proxy,
reader: reader,
writer: writer,
autoSave: false // requires user to hit save
//autoLoad: true
});
store.load({params:{start:0, limit:10}});
var yeastStore = new Ext.data.JsonStore({
root: 'items',
idProperty: 'id',
remoteSort: true,
restful: true,
autoSave: false,
proxy: new Ext.data.HttpProxy({
url: 'recipe/yeast'
}),
writer: null,
fields: [
{name: 'id'},
{name: 'description', type: 'string'},
{name: 'name', type: 'string'},
{name: 'attenuation'},
{name: 'yeastName'}
]
});
//
// Listen to all write events
Ext.data.DataProxy.on('write', function(proxy, action, result, res, rs) {
App.setAlert(true, action + ':' + res.message);
});
//
// Listen to all write 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
});
}
});
/** remainder snipped for brevity **/
@IYoni
Copy link

IYoni commented Jul 16, 2015

Hi all,

Where is the form submit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment