Login = function(){ return{ Init:function() { Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; var username = new Ext.form.TextField({ id:'user', fieldLabel: 'Usuario', name: 'user', allowBlank:false, defaultAutoCreate : {tag: "input", type: "text"}, anchor:'100%' }); var password = new Ext.form.TextField({ id:'pass', fieldLabel: 'Clave', name: 'pass', allowBlank:false, defaultAutoCreate : {tag: "input", type: "password"}, anchor:'100%' }); username.on("specialkey", specialKey, form); password.on("specialkey", specialKey, form); var form = new Ext.FormPanel({ labelWidth: 55, labelAlign:'right', url:'login.do', frame:true, border:false, bodyStyle:'padding:0px', defaultType: 'textfield', buttonAlign: 'right', hideBorders: true, items: [username,password], buttons: [{ text: 'Ingresar', type: 'submit', handler: function(){ if (form.getForm().isValid()){ Ext.MessageBox.wait('Validando usuario...', 'Por favor espere'); form.getForm().submit({ url:'login.do', method: 'POST', success:function(form, action) { if(action && action.result){ Ext.MessageBox.hide(); dialog.close(); window.location = 'index.do'; } }, failure: function(form, action) { Ext.MessageBox.hide(); Ext.Msg.show({ title:'Error', msg: action.result.errorInfo, buttons: Ext.Msg.OK, icon: Ext.MessageBox.ERROR }); } }); } } }] }); function specialKey(field, e) { if (e.getKey() == e.RETURN || e.getKey() == e.ENTER ) { if (form.getForm().isValid()){ Ext.MessageBox.wait('Validando usuario...', 'Por favor espere'); form.getForm().submit({ url:'login.do', method: 'POST', success:function(form, action) { if(action && action.result){ Ext.MessageBox.hide(); dialog.close(); window.location = 'index.do'; } }, failure: function(form, action) { Ext.MessageBox.hide(); Ext.MessageBox.alert('Error', 'Usuario o Clave inválida!'); } }); } } } var dialog = new Ext.Window({ width: 310, height: 130, modal: false, closable:false, resizable:false, draggable:false, collapsible:false, border:false, title:'ADIMRA Intranet - Login', plain:true, items: form, renderTo: document.body }); dialog.on('show', function(){ var f = Ext.get('user'); f.focus.defer(100, f); }); dialog.show(); } } }(); Ext.onReady(Login.Init, Login, true);