﻿Ext.ns('immPublicOfferUpload');

immPublicOfferUpload.uploadFacesAction=new Ext.Action({
		text: 'data upload',
		handler: function(){
			immPublicOfferUpload.showUploadDialog();
		},
		iconCls: ''
});

immPublicOfferUpload.showUploadDialog=function(){
immPublicOfferUpload.editWindow.setTitle(iMap.lang.offerUploadTitle);

    immPublicOfferUpload.Store.load();
    immPublicOfferUpload.resetForm();
	immPublicOfferUpload.editWindow.show();
	immPublicOfferUpload.emailField.blankText=iMap.lang.formFieldBlankText;
	immPublicOfferUpload.companyList.blankText=iMap.lang.formFieldBlankText;
	immPublicOfferUpload.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; 
	
}
immPublicOfferUpload.proxy=new Ext.data.HttpProxy(
		{url: 'publicFormhandler.ashx?formId=getpubliccompaniesdata&cmd=load'
		});

immPublicOfferUpload.Store = new Ext.data.Store({
		url: 'publicFormhandler.ashx?formId=getpubliccompaniesdata&cmd=load',
		reader: new Ext.data.JsonReader(
			{root:'data'      },
			[{name: 'companyId',mapping:'companyId'},
		{name: 'companyName',mapping:'companyName'}])
});
immPublicOfferUpload.companyList = new Ext.form.ComboBox({
		id:'pubCompanyList',
		name: 'companies',
		fieldLabel: iMap.lang.offerUploadLabelCompany,
		store:immPublicOfferUpload.Store,
		autoLoad:false,
		forceSelection:true,
		//mode: 'remote',
		displayField: 'companyName',
		allowBlank: false,
		valueField: 'companyId',
		hiddenName : 'selCompanyId',
		triggerAction: 'all'
});




immPublicOfferUpload.resetForm=function(){
	immPublicOfferUpload.editForm.getForm().reset();
};
immPublicOfferUpload.emailField=new Ext.form.TextField({

		    id:'pubOfferEmail',
			fieldLabel: iMap.lang.offerUploadLabelEmail,
			name: 'email',
			vtype:'email',
			allowBlank:false,
			emptyText:iMap.lang.offerUploadLabelEmail
			
});
immPublicOfferUpload.editForm=new Ext.FormPanel({
		labelWidth: 75,
		frame:false,
		fileUpload:true,
		bodyStyle:'padding:5px 5px 0',
		width: '100%',
		defaults: {width: 230},
		defaultType: 'textfield',
		
		items: [immPublicOfferUpload.companyList,immPublicOfferUpload.emailField,
		
			{
		    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(){immPublicOfferUpload.editWindowSave();}
			},{
			text: 'Cancel',
			handler:function(){immPublicOfferUpload.editWindow.hide();}
		}]
});
immPublicOfferUpload.editWindow = new Ext.Window({
		title:'imm offer data upload',
		closeAction:'hide',
		modal:true,
		width:350,
		autoHeight:true,
		items: immPublicOfferUpload.editForm
});
immPublicOfferUpload.editWindowSave=function(){
	
	immPublicOfferUpload.editForm.getForm().submit({
			
			url:'publicFormhandler.ashx' ,
			waitMsg:'uploading  ...',
			success:function(form,action){
				immPublicOfferUpload.editWindow.hide();
				lastresult=action.result.data;confirmAndRedirect(action);
		
			},
			failure:function(response,action){if (  immPublicOfferUpload.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:"publicOfferUpload",cmd:'save'}
	});
};

function confirmAndRedirect(action){
Ext.Msg.show({
   title:'success',
   msg: action.result.data,
   buttons: Ext.Msg.OK,
   fn: function(){try{eval("window.location='" + action.result.redirect + "'");  }catch(e){}},
  icon: Ext.MessageBox.INFO
});

}
