3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
15 Ext.define('Writer.Form', {
16 extend: 'Ext.form.Panel',
17 alias: 'widget.writerform',
19 requires: ['Ext.form.field.Text'],
21 initComponent: function(){
22 this.addEvents('create');
27 title: 'User -- All fields are required',
28 defaultType: 'textfield',
60 iconCls: 'icon-user-add',
63 handler: this.onCreate
65 iconCls: 'icon-reset',
75 setActiveRecord: function(record){
76 this.activeRecord = record;
78 this.down('#save').enable();
79 this.getForm().loadRecord(record);
81 this.down('#save').disable();
82 this.getForm().reset();
87 var active = this.activeRecord,
88 form = this.getForm();
94 form.updateRecord(active);
100 var form = this.getForm();
102 if (form.isValid()) {
103 this.fireEvent('create', this, form.getValues());
110 this.setActiveRecord(null);
111 this.getForm().reset();
115 Ext.define('Writer.Grid', {
116 extend: 'Ext.grid.Panel',
117 alias: 'widget.writergrid',
120 'Ext.grid.plugin.CellEditing',
121 'Ext.form.field.Text',
122 'Ext.toolbar.TextItem'
125 initComponent: function(){
127 this.editing = Ext.create('Ext.grid.plugin.CellEditing');
130 iconCls: 'icon-grid',
132 plugins: [this.editing],
139 handler: this.onAddClick
141 iconCls: 'icon-delete',
146 handler: this.onDeleteClick
159 tooltip: 'When enabled, Store will execute Ajax requests as soon as a Record becomes dirty.',
161 toggleHandler: function(btn, pressed){
162 this.store.autoSync = pressed;
168 tooltip: 'When enabled, Store will batch all records for each type of CRUD verb into a single Ajax request.',
170 toggleHandler: function(btn, pressed){
171 this.store.getProxy().batchActions = pressed;
174 text: 'writeAllFields',
177 tooltip: 'When enabled, Writer will write *all* fields to the server -- not just those that changed.',
179 toggleHandler: function(btn, pressed){
180 this.store.getProxy().getWriter().writeAllFields = pressed;
189 iconCls: 'icon-save',
227 this.getSelectionModel().on('selectionchange', this.onSelectChange, this);
230 onSelectChange: function(selModel, selections){
231 this.down('#delete').setDisabled(selections.length === 0);
238 onDeleteClick: function(){
239 var selection = this.getView().getSelectionModel().getSelection()[0];
241 this.store.remove(selection);
245 onAddClick: function(){
246 var rec = new Writer.Person({
250 }), edit = this.editing;
253 this.store.insert(0, rec);
254 edit.startEditByPosition({
261 Ext.define('Writer.Person', {
262 extend: 'Ext.data.Model',
267 }, 'email', 'first', 'last'],
285 'Ext.tip.QuickTipManager',
286 'Ext.window.MessageBox'
289 Ext.onReady(function(){
290 Ext.tip.QuickTipManager.init();
291 var store = Ext.create('Ext.data.Store', {
292 model: 'Writer.Person',
298 read: 'app.php/users/view',
299 create: 'app.php/users/create',
300 update: 'app.php/users/update',
301 destroy: 'app.php/users/destroy'
305 successProperty: 'success',
307 messageProperty: 'message'
311 writeAllFields: false,
315 exception: function(proxy, response, operation){
316 Ext.MessageBox.show({
317 title: 'REMOTE EXCEPTION',
318 msg: operation.getError(),
319 icon: Ext.MessageBox.ERROR,
326 write: function(proxy, operation){
327 if (operation.action == 'destroy') {
328 main.child('#form').setActiveRecord(null);
330 Ext.example.msg(operation.action, operation.resultSet.message);
335 var main = Ext.create('Ext.container.Container', {
339 renderTo: document.body,
350 create: function(form, data){
351 store.insert(0, data);
361 selectionchange: function(selModel, selected) {
362 main.child('#form').setActiveRecord(selected[0] || null);