
FOS.Organiser.Profile = function(){
};


FOS.Organiser.Profile.viewConfig = {
    xtype: 'form',
    layout: 'form',
	autoScroll : true,
    id: 'organiser-profile',
    renderTo: 'organiserProfile',
    padding: 20,
    labelAlign: 'top',
    labelWidth: 150,
    defaults : {
		anchor: '75%'
	
	},
    frame: false,
    border: false,
	items: [{
        xtype: 'textfield',
        fieldLabel: 'Name',
        id: 'name' 
    }, {
    	labelAlign: 'left',
        xtype: 'textfield',
        fieldLabel: 'Address',
        id: 'address1' 
    }, {
        xtype: 'textfield',
        
        id: 'address2' 
    }, {
        xtype: 'textfield',
        
        id: 'address3' 
    }, {
        xtype: 'textfield',
        fieldLabel: 'City',
        id: 'city' 
    }, {
        xtype: 'textfield',
        fieldLabel: 'County',
        id: 'region' 
    }, {
        xtype: 'textfield',
        fieldLabel: 'Country',
        id: 'country' 
    }, {
        xtype: 'textfield',
        fieldLabel: 'Postcode',
        id: 'postcode' 
    }, {
        xtype: 'textfield',
        fieldLabel: 'Contact Name',
        id: 'contactName' 
    }, {
        xtype: 'textfield',
        fieldLabel: 'Contact Email',
        id: 'contactEmail' 
    }, {
        xtype: 'textfield',
        fieldLabel: 'Tel No',
        id: 'telNo' 
    }, {
        xtype: 'textfield',
        fieldLabel: 'Fax No',
        id: 'faxNo' 
    }, {
        xtype: 'textfield',
        fieldLabel: 'Web Site',
        id: 'webSite' 
    }, {
        xtype: 'textfield',
        fieldLabel: 'Terms and Conditions',
        id: 'tandc' 
    }, {
        xtype: 'displayfield',
        
        value: '(Http link i.e. http://www.myeventco.com/tandc.html)' 
    }, {
        xtype: 'htmleditor',
       
        fieldLabel: 'Profile',
        id: 'profile',
        height: 400 ,anchor: '95%'
    }],
    buttons: [  
	{
        text: 'Save',
		icon : 'resources/icons/disk.png',
        handler: function(){
            FOS.Organiser.Profile.update()
        }
        
    } ]


};

FOS.Organiser.Profile.reload = function(){
	FOS.Organiser.Profile.show(FOS.Organiser.Profile.orgainserId);

}
FOS.Organiser.Profile.load = function(){


}

FOS.Organiser.Profile.create = function(){


}

FOS.Organiser.Profile.destroyView = function(){
	//Ext.getCmp(ORGANISER_MAIN_TAB).removeAll(true);
	 

}

FOS.Organiser.Profile.createView = function(forceCreate) {
	var p = new Ext.FormPanel(FOS.Organiser.Profile.viewConfig);
		   
	 
}

FOS.Organiser.Profile.update = function(){

    Ext.get('organiserProfile').mask('Loading profile. Please wait...', 'x-mask-loading');
    
    
    Ext.Ajax.request({
        url: 'action.php',
        method: 'POST',
        action: 'update',
        params: {
            module: 'organiser',
            action: 'update',
            orgainserId: FOS.Organiser.Profile.orgainserId,
            name: Ext.getCmp('name').getValue(),
            profile: FOS.util.cleanseHTML(Ext.getCmp('profile').getValue()),
            address1: Ext.getCmp('address1').getValue(),
            address2: Ext.getCmp('address2').getValue(),
            address3: Ext.getCmp('address3').getValue(),
            city: Ext.getCmp('city').getValue(),
            region: Ext.getCmp('region').getValue(),
            postcode: Ext.getCmp('postcode').getValue(),
            country: Ext.getCmp('country').getValue(),
            
            contactName: Ext.getCmp('contactName').getValue(),
            contactEmail: Ext.getCmp('contactEmail').getValue(),
            faxNo: Ext.getCmp('faxNo').getValue(),
            telNo: Ext.getCmp('telNo').getValue(),
            tandc: Ext.getCmp('tandc').getValue(),
            webSite: Ext.getCmp('webSite').getValue()
        
        
        },
        failure: function(response, options){
        	Ext.MessageBox.alert('Failed', response.status);
            Ext.get('organiserProfile').unmask();
        },
        success: function(response, options){
            var result = Ext.decode(response.responseText);
            
            if (result.success == false) {
            	Ext.MessageBox.alert('Failed to open organiser profile' + result.errorMsg);
            }
			else
				Ext.MessageBox.alert('Full On Sport', 'Save complete.'); 
            
            Ext.get('organiserProfile').unmask();
        }
    })
    
}

FOS.Organiser.Profile.show = function(oid){

	//FOS.Organiser.Profile.createView();
     
    FOS.Organiser.Profile.orgainserId = oid;
    
    Ext.Ajax.request({
        url: 'action.php',
        method: 'POST',
        params: {
            module: 'organiser',
            action: 'read',
            orgainserId: oid
        },
        failure: function(response, options){
        	Ext.MessageBox.alert('Failed', response.status);
            Ext.get('organiserProfile').unmask();
        },
        success: function(response, options){
            var result = Ext.decode(response.responseText);
            
            if (result.success == true) {
            	FOS.Organiser.Profile.createView();
				FOS.Organiser.Profile.displayFormData(result.data);
            }
            else 
            	Ext.MessageBox.alert('Failed to open organiser profile' + result.errorMsg);
            
            Ext.get('organiserProfile').unmask();
        }
    })
    
    
    
    
    
    
};

FOS.Organiser.Profile.displayFormData = function(data){

	
	if (Ext.getCmp('name') == undefined)
		FOS.Organiser.Profile.createView();
		
    try {
        Ext.getCmp('name').setValue(data[0].name);
        Ext.getCmp('profile').setValue(data[0].profile);
        Ext.getCmp('address1').setValue(data[0].address_1);
        Ext.getCmp('address2').setValue(data[0].address_2);
        Ext.getCmp('address3').setValue(data[0].address_3);
        Ext.getCmp('city').setValue(data[0].city);
        Ext.getCmp('region').setValue(data[0].region_id);
        Ext.getCmp('postcode').setValue(data[0].postcode);
        Ext.getCmp('country').setValue(data[0].country_id);
        
        Ext.getCmp('contactName').setValue(data[0].contact_name);
        Ext.getCmp('contactEmail').setValue(data[0].contact_email);
        Ext.getCmp('faxNo').setValue(data[0].fax_no);
        Ext.getCmp('telNo').setValue(data[0].tel_no);
        Ext.getCmp('tandc').setValue(data[0].terms_and_conditions);
        Ext.getCmp('webSite').setValue(data[0].website);
        
    } 
    catch (e) {
        Ext.MessageBox.alert('Failed', e.message);
        
    }
}




