﻿Ext.ns("eKonx.Profile");
Ext.ns("eKonx.Res.Profile");
Ext.ns("eKonx.Urls.Profile");

eKonx.Res.Profile =
{
	Title: "Мой профиль",
	Name: "Имя",
	FamilyName: "Отчество",
	Born: "Дата рождения",
	Phone: "Моб. телефон",
	InnerPhone: "Гор. телефон",
	EmailSignature: "Подпись в электронных письмах"

}

Ext.ns("eKonx.Res");
Ext.ns("eKonx.Res.Global");
Ext.ns("eKonx.Res.Common");

eKonx.Urls.Profile =
{
	GetUserProfile: "Account/GetUserProfile",
	SaveUserProfile: "Account/SaveUserProfile"
}
eKonx.ProfileFields =
[
	{
		fieldLabel: eKonx.Res.Profile.Name,
		xtype: 'textfield',
		allowBlank: false,
		name: 'Name',
		width: 200
	},
	{
		fieldLabel: eKonx.Res.Profile.FamilyName,
		xtype: 'textfield',
		name: 'FamilyName',
		//allowBlank: false,
		width: 200
	},
	{
		fieldLabel: eKonx.Res.Profile.Phone,
		xtype: 'textfield',
		name: 'Phone',
		allowBlank: false,
		width: 200
	},
	{
		fieldLabel: eKonx.Res.Common.Email,
		xtype: 'textfield',
		name: 'Email',
		vtype:'email',
		allowBlank: true,
		width: 200
	},
	{
		fieldLabel: eKonx.Res.Profile.InnerPhone,
		xtype: 'textfield',
		name: 'InnerPhone',
		width: 200
	},
	{
		xtype: 'combo',
		fieldLabel: eKonx.Res.Common.Sex,
		name: 'Sex',
		//id: "cbSex",
		editable: false,
		triggerAction: 'all',
		hiddenName: "Sex",
		mode: 'local',
		valueField: 'id',
		displayField: 'displayText',
		width: 200,
		store: new Ext.data.ArrayStore(
		{
			fields: ['id', 'displayText'],
			data:
			[
				[0, eKonx.Res.Common.MSex],
				[1, eKonx.Res.Common.WSex]
			]
		})
	},
	{
		xtype: 'datefield',
		fieldLabel: eKonx.Res.Profile.Born,
		name: 'Born',
		width: 200
	},
	{
		fieldLabel: eKonx.Res.Profile.EmailSignature,
		xtype: 'htmleditor',
		name: 'EmailSignature',
		height: 200,
		width: 550
	}
];

eKonx.Profile = Ext.extend(
Ext.form.FormPanel,
{
	profileConfig:
	{
		title: eKonx.Res.Profile.Title,
		bodyStyle: "padding: 10px",
		url: eKonx.Urls.Profile.SaveUserProfile,
		standardSubmit: false,
		height: 450,
		items: eKonx.ProfileFields,
		buttons:
		[
			{
				text: 'OK',
				handler: function()
				{
					var frm = this.ownerCt.ownerCt;
					eKonx.SubmitForms(
					{
						Forms: [frm],
						SubmitUrl: frm.url
					});
				}
			}
		],
		listeners:
		{
			afterrender: function()
			{
				this.getForm().load({ url: eKonx.Urls.Profile.GetUserProfile });
			}
		}
	},
	constructor: function(config)
	{
		if (!config)
		{
			config = {};
			config.removeItems = [{ name: "Email"}];
		}
		eKonx.Profile.superclass.constructor.call(
			this,
			eKonx.ApplyConfigWithItems(Ext.apply({}, this.profileConfig), config));
	}
});

