/**
 * file Reminder.js with Reminder class
 * @author Janusz Rygał
 * @date 24.09.2008 
 */

/**
 * @class Reminder class
 */
Reminder = function(){
	/**loader object*/
	this.reminderLoader;
	/**news body*/
	var html;
	
	
	/**
	 * method to apply scheduler application
	 */
	this.applyScheduler = function(){
			var elem = new Ext.Element();
			
			elem.windowId = 684;
		 	elem.url  	  = 'imc/human_resources.php/main_calendar';	
		 	elem.winText  = 'SCHEDULER NEW';
		 	elem.type     = 'standard';
		 	context.menu.programs.openProgramWindow(elem);
	}
	
	/**
	 * method to apply bow window
	 */ 
	this.applyBow = function(){
			var elem = new Ext.Element();
			
			elem.windowId = 553;
		 	elem.url  	  = 'ines3/index.php?module=OFFICE_TASKS';	
		 	elem.winText  = 'OFFICE TASKS';
		 	elem.type     = 'standard';
		 	context.menu.programs.openProgramWindow(elem);
	} 
	
	/**
	 * method to get meetings number
	 */	
	 this.getMeetingsNum = function(){
	 	return this.reminderLoader.getAt(0).get('meetings_num');
	 }
	 
	/**
	 * method to get tasks number
	 */
	 this.getTasksNum = function(){
	 	return this.reminderLoader.getAt(0).get('tasks_num');
	 } 
	 
 
 	 /**
 	  * method to create reminder body
 	  */
 	 this.createReminderContent = function(){
 	 		 html  = "<div>";
 	 	
 	 		 html += "<div style=\"cursor: pointer;\" onclick=\"context.reminder.applyBow()\">";
 	 		 		html += "<div> <img src='../images/omsImages/main/icons/wrench_orange.png'/> ";	
 	 		 		html += context.translator.translate('tasks_num_today')+' ';
 	 		 		
 	 		 		html += this.getTasksNum();
 	 		 		html += "</div>";
 	 		 html += "</div>";	
 	 		 
 	 		 html += "<div style=\"cursor: pointer;\" onclick=\"context.reminder.applyScheduler()\">";
 	 		 		html += "<div> <img src='../images/omsImages/main/icons/user_suit.gif'/> ";	
 	 		 		html += context.translator.translate('meet_num_today')+' ';
 	 		 		
 	 		 		html += this.getMeetingsNum();
 	 		 		html += "</div>";
 	 		 html += "</div>";
 	 		 
 	 	    html += "</div>";
 	 }
 
 	 /**
 	  * method to display reminder body
 	  */
 	 this.display = function(){
 	 	Ext.example.msg( context.translator.translate('Reminder'),  html, 't-t', 7, null);
 	 }
 	
 	this.loadLoader = function(){
 			this.reminderLoader.load();
 			var ranNum = Math.random()*300000 + 300000;
				ranNum = Math.floor(ranNum);						
 			setTimeout("context.reminder.loadLoader()", ranNum);
 	}
 	/**
 	 * method to load reminder
 	 */
 	this.load = function(){
 		this.loadLoader();
 		this.reminderLoader.on('load', function(loader_, records){
 			context.reminder.createReminderContent();
 			context.reminder.display();
 		});
 		
 		
 	} 

	/**
	 * method to initialize user class object
	 */
	this.init = function(){
	          this.reminderLoader = new Ext.data.Store({
						                    proxy: new Ext.data.HttpProxy({ 
						                                      url: project_url + 'GetReminder',
						                                      method: 'GET',
						                                      waitMsg:'Loading ...' 
						                                     }),
						                   reader : new Ext.data.JsonReader({
									                            id: 'reminder_reader',
									                            root: 'reminder',
									                            fields: [
									                            		 {name: 'tasks_num', type: 'int'},
									                            		 {name: 'meetings_num', type: 'int'}
                                                                        ]
							                         		 })     		 
						                });			                				                
	}	
}