This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation.

Scheduled task with checker

From Group-Office Groupware and CRM Documentation
Jump to: navigation, search

Every two minutes Group-Office send a request to check for reminders, new e-mail etc. In a module you can register your own request for your module. In the tickets module we use this code for example:

//do this when Group-Office is fully rendered
GO.mainLayout.onReady(function(){
	
	//create notification icon in the top bar
	var notificationArea = Ext.get('notification-area');
	if(notificationArea)
	{
		GO.tickets.notificationEl = notificationArea.createChild({
			id: 'ti-notify',
			tag:'a',
			href:'#',
			style:'display:none'
		});
		GO.tickets.notificationEl.on('click', function(){
			GO.mainLayout.openModule('tickets');
		}, this);
	}
	
	//register a new request to the checker. It will poll unseen tickets every two minutes
	GO.checker.registerRequest("tickets/ticket/unseen",{},function(checker, data){
	
	//get the mainpanel of the tickets module
	var tp = GO.mainLayout.getModulePanel('tickets');
	
	//compare the last unseen valie to the new unseen value
	if(data.tickets.unseen!=GO.tickets.totalUnseen && data.tickets.unseen>0)
	{
		//set the notificationEl 
		if(!tp || !tp.isVisible())
			GO.tickets.notificationEl.setDisplayed(true);
		
		//refresh tickets grid
		if(tp)
			tp.refresh();
	}

	//set the unseen count
	GO.tickets.notificationEl.update(data.tickets.unseen);			
	GO.tickets.totalUnseen=data.tickets.unseen;		
  },this);
});

The controller action code is very simple:

public function actionUnseen($params){			
	  
  $response = array(
	'success' => true,
	'tickets' => array(
	  'unseen' => $this->_getTotalUnseen()
	)
  );
  return $response;
}