Ext.ns("Vreshenie.window");

Vreshenie.window.UserRegistryWindow = Ext.extend(Ext.Window, {	
    initComponent : function() {
        Ext.apply(this, {
			layout:'fit',
			closeAction:'hide',
			iconCls: 'icon-registration',
			width:280,
			height:110,
			plain: true,
			closable:true,
			resizable:false,
			modal:true,
			animateTarget:'button-registration',
            items:this.buildForm()
        });		
        Vreshenie.window.UserRegistryWindow.superclass.initComponent.call(this);
    },    
    buildForm : function() {
        var formItemDefaults = {
            allowBlank : false,
            anchor     : '-5',
            listeners  : {
                scope      : this,
                specialkey : function(field, e) {
                    if (e.getKey() === e.ENTER && this.handler) {
                        this.handler.call(this.scope);
                    }
                }
            }
        };
        return {
            xtype       : 'form',
            defaultType : 'textfield',
			id:'registryForm',
            labelWidth:80,
            frame       : true,
			monitorValid:true,
            url:'/users/register/sendmail.php',
            labelAlign  : 'right',
            defaults    : formItemDefaults,
            items       : [{
                fieldLabel:'Email',
				name:'email',
				allowBlank:false,
				blankText  :'Введите email',
				vtype:'email'
            }],
			buttons   : [
			'->',{
				text:'Регистрация',
				formBind: true,
				iconCls:'icon-registration',				
				handler:function(){
					var login = Ext.getCmp('registryForm');
					login.getForm().submit({
						method:'POST',
						waitTitle:'Соединение',
						waitMsg:'Отправка данных...',
						success:function(form, response){
							var json = response.result;
							if(json.success == true){
								Ext.getCmp('win-regitry-form').hide();
								Ext.Msg.alert('Ответ сервера', 'На Ваш email отправлено письмо.', function(btn, text){});
							}
							else if(request.response.responseText=='false') {Ext.Msg.alert('Ответ сервера', 'Не предусмотренный ответ сервера 1.', function(btn, text){});}
							else {Ext.Msg.alert('Ответ сервера', 'Не предусмотренный ответ сервера 2.', function(btn, text){});}
						},
						failure:function(form, response){
							var json = response.result;
							if(json.success == false){Ext.Msg.alert('Ответ сервера', 'Этот email занят, либо не получилось<br> отправить письмо на Ваш email');}
							else{Ext.Msg.alert('Ответ сервера', 'Не предусмотренный ответ сервера.');}
						
						}
					});
				}
            }]
        };
    }

});
