Sunday, March 14, 2010

Extjs Login

Ext.onReady(function(){
Ext.QuickTips.init();

Ext.Ajax.request({
url:'biz/index.php',
params:{service:'security',func:'start'}
});

var unm = new Ext.form.TextField({fieldLabel:'Username',name:'unm',nx:'pwd'});
unm.on('specialkey',function(f,e){ if(e.getKey() == e.ENTER) pwd.focus();});
var pwd = new Ext.form.TextField({fieldLabel:'Password',name:'pwd',inputType:'password',nx:'btn'});
pwd.on('specialkey',function(f,e){ test3 = 'pwd test'; if(e.getKey() == e.ENTER) btn.focus();});
var btn = new Ext.Button({
text:'Login',
formBind: true,
// Function that fires when user clicks the button
handler:function(){
login.getForm().submit({
method:'POST',
waitTitle:'Connecting',
waitMsg:'Sending data...',
baseParams: {service:'security',func:'login'},
success:function(f,a){
var out = a.result;
if (out.sd.gid == 1){
window.location = 'main.html';
f.destroy();
win.close();
}
else if(out.failure){
Ext.Msg.alert(out.et, out.em);
}
},

failure:function(f, a){
try{
var out = a.result;
if(out.failure)
Ext.Msg.alert(out.et, out.em);
}

}
catch(e){
res = a.response.responseText;
if(a.failureType == 'server'){
var o = Ext.decode(res);
Ext.Msg.alert('Login Failed!', o.errors.reason);
}
else
Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + res);
}
login.getForm().reset();
}
});
}
});
// Create a variable to hold our EXT Form Panel.
// Assign various config options as seen.
var login = new Ext.FormPanel({
labelWidth:80,
url:'biz/index.php',
baseParams: {service:'security',func:'login'},
frame:true,
defaultType:'textfield',
defaults:{allowBlank:false},
monitorValid:true,
items:[unm,pwd],
buttons:[btn]
});


// This just creates a window to wrap the login form.
// The login object is passed to the items collection.
var win = new Ext.Window({
renderto:document.body,
layout:'fit',
width:300,
height:150,
closable: false,
resizable: false,
plain: true,
title:'Please Login',
border: false,
items: [login]
});
win.show();
});