﻿Ext.ns('immUserSujetUpload');

immUserSujetUpload.uploadSujetAction=new Ext.Action({
		text: 'data upload',
		handler: function(){
			immUserSujetUpload.showUploadDialog();
		},
		iconCls: ''
});

immUserSujetUpload.showUploadDialog=function(){
	immUserSujetUpload.editWindow.setTitle(iMap.lang.sujetUploadTitle);
	immUserSujetUpload.Store.load();
	immUserSujetUpload.resetForm();
	
	
	//
	immUserSujetUpload.editWindow.show();
	//immUserSujetUpload.emailField.blankText=iMap.lang.formFieldBlankText;
	immUserSujetUpload.formatList.blankText=iMap.lang.formFieldBlankText;
//	immUserSujetUpload.emailField.vtypeText=iMap.lang.formFieldInvalidEmail;
//	Ext.get('pubOfferEmail').findParentNode(".x-form-item", 5).firstChild.innerHTML=iMap.lang.offerUploadLabelEmail;
	Ext.get('pubFormatList').findParentNode(".x-form-item", 5).firstChild.innerHTML=iMap.lang.sujetUploadLabelFormat;
	Ext.get('pubSujetFile').findParentNode(".x-form-item", 5).firstChild.innerHTML=iMap.lang.sujetUploadLabelFile;
	immUserSujetUpload.introText.load({
	    url: 'publicFormhandler.ashx?formId=getsujetintroText&cmd=load'
	});
	
	setTimeout( 'immUserSujetUpload.editWindow.doLayout()',500);
	
}
immUserSujetUpload.proxy=new Ext.data.HttpProxy(
	{url: 'publicFormhandler.ashx?formId=getsujetformats&cmd=load'
});

immUserSujetUpload.Store = new Ext.data.Store({
		url: 'publicFormhandler.ashx?formId=getsujetformats&cmd=load',
		reader: new Ext.data.JsonReader(
			{root:'data'      },
			[{name: 'formatId',mapping:'formatId'},
		{name: 'formatName',mapping:'formatName'}])
});
immUserSujetUpload.formatList = new Ext.form.ComboBox({
		id:'pubFormatList',
		name: 'formats',
		fieldLabel: iMap.lang.sujetUploadLabelFormat,
		store:immUserSujetUpload.Store,
		autoLoad:false,
		forceSelection:true,
		mode: 'remote',
		displayField: 'formatName',
		allowBlank: false,
		valueField: 'formatId',
		hiddenName : 'selFormatId',
		triggerAction: 'all'
});




immUserSujetUpload.resetForm=function(){
	immUserSujetUpload.editForm.getForm().reset();
};

immUserSujetUpload.introText=new Ext.Panel({
        id:'sujetFileIntro',
		bodyStyle:'padding:5px 5px 5px 5px'
	
});
immUserSujetUpload.editForm=new Ext.FormPanel({
		labelWidth: 75,
		frame:false,
		fileUpload:true,
		bodyStyle:'padding:5px 5px 0',
		autoWidth: true,
		autoHeight:true,
		
		defaults: {width: 230},
		defaultType: 'textfield',
		
		items: [immUserSujetUpload.formatList,
		
		
		{
			id:'pubSujetFile',
			inputType:'file',
			fieldLabel: 'file',
			name: 'sujetFile',
			allowBlank:false
		}
		
		],
		
		buttons: [{
			text: 'Ok',
			scope:this,
			handler:function(){immUserSujetUpload.editWindowSave();}
			},{
			text: 'Cancel',
			handler:function(){immUserSujetUpload.editWindow.hide();}
		}]
});
immUserSujetUpload.editWindow = new Ext.Window({
		title:'imm sujet file upload',
		closeAction:'hide',
		modal:true,
		width:350,
		autoHeight:true,
		items: [immUserSujetUpload.introText,
		immUserSujetUpload.editForm]
});
var lastResult;
immUserSujetUpload.editWindowSave=function(){
	
	immUserSujetUpload.editForm.getForm().submit({
			
			url:'publicFormhandler.ashx' ,
			waitMsg:'uploading  ...',
			success:function(form,action){
			    //alert("upload:");
			    lastResult=action;
				immUserSujetUpload.editWindow.hide();
				lastresult=action.result.data;confirmAndRedirect(action);
				
			},
			failure:function(response,action){if (  immUserSujetUpload.editForm.getForm().isValid()){lastresult=action.result.data;Ext.Msg.alert(iMap.lang.sujetUploadTitleError,action.result.data)} else {Ext.Msg.alert(iMap.lang.formErrorTitle,iMap.lang.formError)}},
			params:{formId:"userSujetUpload",cmd:'save'}
	});
};

function confirmAndRedirect(action){
	Ext.Msg.show({
			title:iMap.lang.sujetUploadTitleSuccess,
			msg: action.result.data,
			buttons: Ext.Msg.OK,
			fn: function(){},
			icon: Ext.MessageBox.INFO
	});
	
}

