Ext.ns('Application', 'Application.Index');
 
Application.Index.LoginForm = Ext.extend(Ext.form.FormPanel, {
    url: 'user/login',
	border:false,
	frame: true,
	labelWidth: 50,
	enableKeyEvents:true,
	
	
	
	initComponent:function() {
		this.osSubmit = function() {
			this.getForm().submit({
		  		success: function(form, action){ 
			    	obj = Ext.util.JSON.decode(action.response.responseText);
			    	window.location = obj.redirect.url;
				},
				failure:function(form, action){ 
					if(action.failureType == 'server'){ 
						obj = Ext.util.JSON.decode(action.response.responseText);
						this.getComponent('indexloginerror').setText(obj.errors.reason);
						this.getForm().reset(); 
					}              
				},
				scope: this
			});
		};
		// build the form-fields.  Always a good idea to defer form-building to a method so that this class can
		// be over-ridden to provide different form-fields
		this.items = this.buildForm();
		this.buttons = this.buildUI();
		this.listeners = this.buildListeners();

		Application.Index.LoginForm.superclass.initComponent.apply(this, arguments);
        Ext.apply(this.getForm(),{
            url:'user/login'
        });		
    }, // eo function initComponent

 
    ss: function(button,event){
    	Ext.Msg.alert('ss');
    },
	 

    
    /**
     * buildUI
     * @private
     */
    buildUI: function(){
    	return [{
		  text: 'Login',
		  scope: this,
		  handler: this.osSubmit
	 }]
    },
	 
    /**
     * buildListeners
     * @private
     */
    buildListeners: function(){
    	return [{
    		scope: this,
		  specialkey: function(f,e){
		  	if (e.getKey() == e.ENTER) {
		  		Ext.Msg.alert('f');
		  	}
		  }
	  }]
    },
    listeners: {
    	specialkey: function(f,e){
	  	if (e.getKey() == e.ENTER) {
	  		Ext.Msg.alert('f');
	  	}
	    }
    },
    
    buildForm : function() {
        return [
            {
		  xtype: 'textfield',
		  fieldLabel: 'Login',
		  name: 'username',
		  allowBlank: false,
		  width: 70
	  },{
		  xtype: 'textfield',
		  fieldLabel: 'Password',
		  name: 'password',
		  allowBlank: false,
		  width: 70
	  },{
          xtype: 'label',
          id: 'indexloginerror'
      }];
    }
});
 
Ext.reg('indexloginform', Application.Index.LoginForm);