﻿Ext.ns('immUserOfferUpload');

immUserOfferUpload.uploadFacesAction=new Ext.Action({
		text: 'data upload',
		handler: function(){
			immUserOfferUpload.showUploadDialog();
		},
		iconCls: ''
});

immUserOfferUpload.showUploadDialog=function(){
	immUserOfferUpload.editWindow.setTitle(iMap.lang.offerUploadTitle);
	immUserOfferUpload.Store.load();
	immUserOfferUpload.resetForm();
	
	//
	immUserOfferUpload.editWindow.show();
	//immUserOfferUpload.emailField.blankText=iMap.lang.formFieldBlankText;
	immUserOfferUpload.companyList.blankText=iMap.lang.formFieldBlankText;
//	immUserOfferUpload.emailField.vtypeText=iMap.lang.formFieldInvalidEmail;
//	Ext.get('pubOfferEmail').findParentNode(".x-form-item", 5).firstChild.innerHTML=iMap.lang.offerUploadLabelEmail;
	Ext.get('pubCompanyList').findParentNode(".x-form-item", 5).firstChild.innerHTML=iMap.lang.offerUploadLabelCompany;
	Ext.get('pubOfferFile').findParentNode(".x-form-item", 5).firstChild.innerHTML=iMap.lang.offerUploadLabelFile;
	Ext.get('pubOfferSubject').findParentNode(".x-form-item", 5).firstChild.innerHTML=iMap.lang.offerUploadLabelofferSubject;
	
	
}
immUserOfferUpload.proxy=new Ext.data.HttpProxy(
	{url: 'publicFormhandler.ashx?formId=getusercompaniesdata&cmd=load'
});

immUserOfferUpload.Store = new Ext.data.Store({
		url: 'publicFormhandler.ashx?formId=getusercompaniesdata&cmd=load',
		reader: new Ext.data.JsonReader(
			{root:'data'      },
			[{name: 'companyId',mapping:'companyId'},
		{name: 'companyName',mapping:'companyName'}])
});
immUserOfferUpload.companyList = new Ext.form.ComboBox({
		id:'pubCompanyList',
		name: 'companies',
		fieldLabel: iMap.lang.offerUploadLabelCompany,
		store:immUserOfferUpload.Store,
		autoLoad:false,
		forceSelection:true,
		mode: 'remote',
		displayField: 'companyName',
		allowBlank: false,
		valueField: 'companyId',
		hiddenName : 'selCompanyId',
		triggerAction: 'all'
});




immUserOfferUpload.resetForm=function(){
	immUserOfferUpload.editForm.getForm().reset();
};
immUserOfferUpload.editForm=new Ext.FormPanel({
		labelWidth: 75,
		frame:false,
		fileUpload:true,
		bodyStyle:'padding:5px 5px 0',
		width: '100%',
		defaults: {width: 230},
		defaultType: 'textfield',
		
		items: [immUserOfferUpload.companyList,
		
		{
			id:'pubOfferSubject',
			fieldLabel: iMap.lang.offerUploadLabelofferSubject,
			name: 'offerSubject',
			allowBlank:true
		},
		{
			id:'pubOfferFile',
			inputType:'file',
			fieldLabel: 'file',
			name: 'offerFile',
			allowBlank:false
		}
		
		],
		
		buttons: [{
			text: 'Ok',
			scope:this,
			handler:function(){immUserOfferUpload.editWindowSave();}
			},{
			text: 'Cancel',
			handler:function(){immUserOfferUpload.editWindow.hide();}
		}]
});
immUserOfferUpload.editWindow = new Ext.Window({
		title:'imm offer data upload',
		closeAction:'hide',
		modal:true,
		width:350,
		autoHeight:true,
		items: immUserOfferUpload.editForm
});
immUserOfferUpload.editWindowSave=function(){
	
	immUserOfferUpload.editForm.getForm().submit({
			
			url:'publicFormhandler.ashx' ,
			waitMsg:'uploading  ...',
			success:function(form,action){
				immUserOfferUpload.editWindow.hide();
				lastresult=action.result.data;confirmAndRedirect(action);
				
			},
			failure:function(response,action){if (  immUserOfferUpload.editForm.getForm().isValid()){lastresult=action.result.data;Ext.Msg.alert(iMap.lang.publicUploadErrorTitle,action.result.data)} else {Ext.Msg.alert(iMap.lang.formErrorTitle,iMap.lang.formError)}},
			params:{formId:"publicUserUpload",cmd:'save'}
	});
};

function confirmAndRedirect(action){
	Ext.Msg.show({
			title:'success',
			msg: action.result.data,
			buttons: Ext.Msg.OK,
			fn: function(){},
			icon: Ext.MessageBox.INFO
	});
	
}

