1 Ext.define('Writer.Form', {
2 extend: 'Ext.form.Panel',
3 alias: 'widget.writerform',
5 requires: ['Ext.form.field.Text'],
7 initComponent: function(){
8 this.addEvents('create');
13 title: 'User -- All fields are required',
14 defaultType: 'textfield',
46 iconCls: 'icon-user-add',
49 handler: this.onCreate
51 iconCls: 'icon-reset',
61 setActiveRecord: function(record){
62 this.activeRecord = record;
64 this.down('#save').enable();
65 this.getForm().loadRecord(record);
67 this.down('#save').disable();
68 this.getForm().reset();
73 var active = this.activeRecord,
74 form = this.getForm();
80 form.updateRecord(active);
86 var form = this.getForm();
89 this.fireEvent('create', this, form.getValues());
96 this.setActiveRecord(null);
97 this.getForm().reset();
101 Ext.define('Writer.Grid', {
102 extend: 'Ext.grid.Panel',
103 alias: 'widget.writergrid',
106 'Ext.grid.plugin.CellEditing',
107 'Ext.form.field.Text',
108 'Ext.toolbar.TextItem'
111 initComponent: function(){
113 this.editing = Ext.create('Ext.grid.plugin.CellEditing');
116 iconCls: 'icon-grid',
118 plugins: [this.editing],
125 handler: this.onAddClick
127 iconCls: 'icon-delete',
132 handler: this.onDeleteClick
145 tooltip: 'When enabled, Store will execute Ajax requests as soon as a Record becomes dirty.',
147 toggleHandler: function(btn, pressed){
148 this.store.autoSync = pressed;
154 tooltip: 'When enabled, Store will batch all records for each type of CRUD verb into a single Ajax request.',
156 toggleHandler: function(btn, pressed){
157 this.store.getProxy().batchActions = pressed;
160 text: 'writeAllFields',
163 tooltip: 'When enabled, Writer will write *all* fields to the server -- not just those that changed.',
165 toggleHandler: function(btn, pressed){
166 this.store.getProxy().getWriter().writeAllFields = pressed;
175 iconCls: 'icon-save',
213 this.getSelectionModel().on('selectionchange', this.onSelectChange, this);
216 onSelectChange: function(selModel, selections){
217 this.down('#delete').setDisabled(selections.length === 0);
224 onDeleteClick: function(){
225 var selection = this.getView().getSelectionModel().getSelection()[0];
227 this.store.remove(selection);
231 onAddClick: function(){
232 var rec = new Writer.Person({
236 }), edit = this.editing;
239 this.store.insert(0, rec);
240 edit.startEditByPosition({
247 Ext.define('Writer.Person', {
248 extend: 'Ext.data.Model',
253 }, 'email', 'first', 'last'],
271 'Ext.tip.QuickTipManager',
272 'Ext.window.MessageBox'
275 Ext.onReady(function(){
276 Ext.tip.QuickTipManager.init();
277 var store = Ext.create('Ext.data.Store', {
278 model: 'Writer.Person',
284 read: 'app.php/users/view',
285 create: 'app.php/users/create',
286 update: 'app.php/users/update',
287 destroy: 'app.php/users/destroy'
291 successProperty: 'success',
293 messageProperty: 'message'
297 writeAllFields: false,
301 exception: function(proxy, response, operation){
302 Ext.MessageBox.show({
303 title: 'REMOTE EXCEPTION',
304 msg: operation.getError(),
305 icon: Ext.MessageBox.ERROR,
312 write: function(proxy, operation){
313 if (operation.action == 'destroy') {
314 main.child('#form').setActiveRecord(null);
316 Ext.example.msg(operation.action, operation.resultSet.message);
321 var main = Ext.create('Ext.container.Container', {
325 renderTo: document.body,
336 create: function(form, data){
337 store.insert(0, data);
347 selectionchange: function(selModel, selected) {
348 main.child('#form').setActiveRecord(selected[0] || null);