+ onDeleteClick: function(){
+ var selection = this.getView().getSelectionModel().getSelection()[0];
+ if (selection) {
+ this.store.remove(selection);
+ }
+ },
+
+ onAddClick: function(){
+ var rec = new Writer.Person({
+ first: '',
+ last: '',
+ email: ''
+ }), edit = this.editing;
+
+ edit.cancelEdit();
+ this.store.insert(0, rec);
+ edit.startEditByPosition({
+ row: 0,
+ column: 1
+ });
+ }
+});
+
+Ext.define('Writer.Person', {
+ extend: 'Ext.data.Model',
+ fields: [{
+ name: 'id',
+ type: 'int',
+ useNull: true
+ }, 'email', 'first', 'last'],
+ validations: [{
+ type: 'length',
+ field: 'email',
+ min: 1
+ }, {
+ type: 'length',
+ field: 'first',
+ min: 1
+ }, {
+ type: 'length',
+ field: 'last',
+ min: 1
+ }]
+});
+
+Ext.require([
+ 'Ext.data.*',
+ 'Ext.tip.QuickTipManager',
+ 'Ext.window.MessageBox'
+]);
+
+Ext.onReady(function(){
+ Ext.tip.QuickTipManager.init();
+ var store = Ext.create('Ext.data.Store', {
+ model: 'Writer.Person',
+ autoLoad: true,
+ autoSync: true,
+ proxy: {
+ type: 'ajax',
+ api: {
+ read: 'app.php/users/view',
+ create: 'app.php/users/create',
+ update: 'app.php/users/update',
+ destroy: 'app.php/users/destroy'
+ },
+ reader: {
+ type: 'json',
+ successProperty: 'success',
+ root: 'data',
+ messageProperty: 'message'
+ },
+ writer: {
+ type: 'json',
+ writeAllFields: false,
+ root: 'data'
+ },
+ listeners: {
+ exception: function(proxy, response, operation){
+ Ext.MessageBox.show({
+ title: 'REMOTE EXCEPTION',
+ msg: operation.getError(),
+ icon: Ext.MessageBox.ERROR,
+ buttons: Ext.Msg.OK
+ });
+ }
+ }
+ },