-/*!
- * Ext JS Library 3.3.1
- * Copyright(c) 2006-2010 Sencha Inc.
- * licensing@sencha.com
- * http://www.sencha.com/license
- */
-// Application instance for showing user-feedback messages.
-var App = new Ext.App({});
-
-// Create HttpProxy instance. Notice new configuration parameter "api" here instead of load. However, you can still use
-// the "url" paramater -- All CRUD requests will be directed to your single url instead.
-var proxy = new Ext.data.HttpProxy({
- api: {
- read : 'app.php/users/view',
- create : 'app.php/users/create',
- update: 'app.php/users/update',
- destroy: 'app.php/users/destroy'
+Ext.define('Writer.Form', {
+ extend: 'Ext.form.Panel',
+ alias: 'widget.writerform',
+
+ requires: ['Ext.form.field.Text'],
+
+ initComponent: function(){
+ this.addEvents('create');
+ Ext.apply(this, {
+ activeRecord: null,
+ iconCls: 'icon-user',
+ frame: true,
+ title: 'User -- All fields are required',
+ defaultType: 'textfield',
+ bodyPadding: 5,
+ fieldDefaults: {
+ anchor: '100%',
+ labelAlign: 'right'
+ },
+ items: [{
+ fieldLabel: 'Email',
+ name: 'email',
+ allowBlank: false,
+ vtype: 'email'
+ }, {
+ fieldLabel: 'First',
+ name: 'first',
+ allowBlank: false
+ }, {
+ fieldLabel: 'Last',
+ name: 'last',
+ allowBlank: false
+ }],
+ dockedItems: [{
+ xtype: 'toolbar',
+ dock: 'bottom',
+ ui: 'footer',
+ items: ['->', {
+ iconCls: 'icon-save',
+ itemId: 'save',
+ text: 'Save',
+ disabled: true,
+ scope: this,
+ handler: this.onSave
+ }, {
+ iconCls: 'icon-user-add',
+ text: 'Create',
+ scope: this,
+ handler: this.onCreate
+ }, {
+ iconCls: 'icon-reset',
+ text: 'Reset',
+ scope: this,
+ handler: this.onReset
+ }]
+ }]
+ });
+ this.callParent();
+ },
+
+ setActiveRecord: function(record){
+ this.activeRecord = record;
+ if (record) {
+ this.down('#save').enable();
+ this.getForm().loadRecord(record);
+ } else {
+ this.down('#save').disable();
+ this.getForm().reset();
+ }
+ },
+
+ onSave: function(){
+ var active = this.activeRecord,
+ form = this.getForm();
+
+ if (!active) {
+ return;
+ }
+ if (form.isValid()) {
+ form.updateRecord(active);
+ this.onReset();
+ }
+ },
+
+ onCreate: function(){
+ var form = this.getForm();
+
+ if (form.isValid()) {
+ this.fireEvent('create', this, form.getValues());
+ form.reset();
+ }
+
+ },
+
+ onReset: function(){
+ this.setActiveRecord(null);
+ this.getForm().reset();