/**
 * @author Konstantin
 */
App.ForgotPasswordDlg = function(config)
{
	config = config || {};
	this.Fields = 
	{
		Email:new Ext.form.TextField({
			fieldName:'Email',
			fieldLabel:txt.Email,
			allowBlank:false,
			width:210
		})
	};
	this.Form = new Ext.form.FormPanel({
		bodyStyle:'padding:5px 5px 0',
		labelWidth:50,
		items:[this.Fields.Email],
		buttons:[{text:txt.Send, handler:this.handleSend, scope:this}, {text:txt.Cancel, handler:this.handleCancel, scope:this}]
	});
	config = Ext.applyIf(config, {
		closable:true,
		mimimizabe:false,
		maximizable:false,
		title: txt.RecoverPassword,
		items:[this.Form],
		layout:"fit",
		closeAction:'hide',
		width:300,
		height:100
	});
	this.Connection = new Ext.data.Connection({
		url:App.url.RecoverPassword,
		method:"POST"
	})
	App.ForgotPasswordDlg.superclass.constructor.call(this, config);
}

Ext.extend(App.ForgotPasswordDlg, Ext.Window, {
	handleCancel:function()
	{
		this.hide();
	},
	handleSend:function()
	{
		if (!this.Fields.Email.isValid())
		{
			Ext.Msg.alert(txt.Error, txt.PutEmail)
		}
		this.Connection.request({
			params:{Email:this.Fields.Email.getValue()},
			callback:this.handleSendResponse,
			scope:this
		});
		Ext.Msg.wait(txt.SendingLoginData, txt.Sending)
	},
	handleSendResponse:function(o, success, response)
	{
		Ext.Msg.hide();
		if (!success)
		{
			Ext.Msg.alert(txt.RequestError, txt.RequestErrorMessage);
			return;
		}
		if (response.responseText)
		{
			var res = Ext.util.JSON.decode(response.responseText);
			if (!res.Result)
			{
				Ext.Msg.alert(txt.Error, res.Message);
				return;
			}
			else
			{
				Ext.Msg.alert(txt.Success, txt.LoginDataSent);
			}
		}
	},
	show:function()
	{
		App.ForgotPasswordDlg.superclass.show.call(this);
		this.Fields.Email.setRawValue('');
	}
});
