JavaScript
Run Code
Open in Fiddle
Ext.define('App.model.EnterFormModel', { extend: 'Ext.data.Model', fields: ["login", "password"], proxy: { type: 'ajax', actionMethods: 'POST', api: { create: "app/data/enter.php" }, reader: { type: 'json', rootProperty: 'contatos', successProperty: 'success' }, writer: { type: 'json', writeAllFields: true, encode: true, rootProperty: 'contatos' } } }); Ext.define('App.view.EnterWindow', { extend: 'Ext.Window', alias: 'widget.App.view.EnterWindow', width: 400, title: "Enter in admin", closable: false, resizable: false, tbar: [{ xtype: "App.view.EnterForm" }], fbar: [{ xtype: "App.view.EnterButtonSend" }, { xtype: "App.view.EnterButtonReset" }] }); Ext.define('App.view.EnterForm', { extend: 'Ext.form.FormPanel', alias: 'widget.App.view.EnterForm', padding: 10, frame: true, bodyBorder: false, border: false, items: [{ xtype: "textfield", fieldLabel: "Login:", labelSeparator: "", labelWidth: 80, name: "login", width: 360 }, { xtype: "textfield", fieldLabel: "Password:", labelSeparator: "", labelWidth: 80, name: "password", width: 360 }] }); Ext.define('App.view.EnterButtonSend', { extend: 'Ext.button.Button', alias: 'widget.App.view.EnterButtonSend', text: "Enter", action: 'send' }); Ext.define('App.view.EnterButtonReset', { extend: 'Ext.button.Button', alias: 'widget.App.view.EnterButtonReset', xtype: "button", text: "Reset", action: "reset" }); Ext.define('App.controller.Enter', { extend: 'Ext.app.Controller', views: ['EnterWindow', 'EnterForm', 'EnterButtonSend', 'EnterButtonReset'], models: ['EnterFormModel'], init: function() { var thisObj = this; this.control({ "App\\.view\\.EnterWindow button[action=send]": { click: function(button) { if (button.up("window").down("form").getForm().isValid() == true) { var Mask = new Ext.LoadMask({ target: button.up("window") }); Mask.show(); var EnterFormModel = Ext.create(thisObj.getModel("EnterFormModel"), button.up("window").down("form").getForm().getValues()); EnterFormModel.save({ success: function(form, action) { Mask.hide(); alert(action.getResponse().responseText); }, failure: function(form, action, option) { Mask.hide(); alert(action.getResponse().responseText); } }); } else { Ext.Msg.show({ title:'Test', msg: 'Test', icon: Ext.MessageBox.WARNING, buttons: Ext.MessageBox.OK }); } } }, "App\\.view\\.EnterWindow button[action=reset]": { click: function(button) { button.up("window").down("form").getForm().reset(); } } }); } }); var App = Ext.application({ name: 'App', appFolder: 'app', controllers: ['Enter'], launch: function() { this.EnterWindow = Ext.create('App.view.EnterWindow'); this.EnterWindow.show(); } });