/**
 * file User.js with user class
 * @author Janusz Rygał
 * @date 12.08.2008 
 */

/**
 * @class User
 * User class
 */
 User = function(){
	/**loader object*/
	var userLoader;
	/**preferences object class*/
	this.preferences = new Preferences();
	/**loader with user data*/
	this.userData = new UserData();
	
	/**
	 * method to load loader
	 */
	this.load = function(){
			 	this.userLoader.load();	 
	}
	
	this.isLogged = function(){
		if(this.userLoader.getAt(0).get('logged'))
			return true;
		return false;
	}
	
	/**
	 * method to get firstname
	 * @return firstname
	 */
	this.getFirstname = function(){
		return this.userLoader.getAt(0).get('firstname');
	}
	
	/**
	 * method to get secondname
	 * @return secondname
	 */
	this.getSecondname = function(){
		 return this.userLoader.getAt(0).get('secondname');
	}
	
	/**
	 * method to get id
	 * @return id
	 */
	this.getId = function(){
		return this.userLoader.getAt(0).get('id');
	}
	
	/**
	 * method to get email address
	 * @return mail
	 */
	this.getMail = function(){
		return this.userLoader.getAt(0).get('mail');
	}
	
	/**
	 * method to get user system position
	 * @return user system position
	 */
	this.getUserSystemPosition = function(){
		return this.userLoader.getAt(0).get('system_position');	
	} 
	
	/**
	 * method to get User department
	 * @return user department 
	 */
	 this.getUserDepartment = function(){
	 	return this.userLoader.getAt(0).get('department');
	 }
	
	/**
	 * method to check is user manager
	 * @return false or true
	 */
	this.isManager = function(){
		return this.userLoader.getAt(0).get('manager');
	} 

	/**
	 * method to initialize user class object
	 */
	this.init = function(){
			  this.userData.init();
			  this.preferences.init();
	          this.userLoader = new Ext.data.Store({
						                    proxy: new Ext.data.HttpProxy({ 
						                                      url: project_url + 'GetUserData',
						                                      method: 'GET',
						                                      waitMsg:'Loading ...' 
						                                     }),
						                   reader : new Ext.data.JsonReader({
									                            id: 'user_reader',
									                            idProperty:'id',
									                            root: 'user',
									                            fields: [
									                            		 {name: 'id'					, type: 'int'},
									                            		 {name: 'firstname'				, type: 'string'},
									                            		 {name: 'secondname'			, type: 'string'},
									                            		 {name: 'mail'					, type: 'string'},
									                            		 {name: 'logged'				, type: 'bool'},
									                            		 {name: 'cookie_log'			, type: 'string'},
									                            		 {name: 'cookie_pass'			, type: 'string'},
                                                                         {name: 'jabber_login'			, type: 'string'},
									                            		 {name: 'system_position'		, type: 'int'},
									                            		 {name: 'department'			, type: 'int'},
									                            		 {name: 'manager'				, type: 'bool'}
									                            		]
							                         		 })     		 
						                });				                
	}	
}