Child pages
  • [development sugar] Add universal ajax wrapper for events [5.3.0-B1]
Skip to end of metadata
Go to start of metadata

Every action user can make on website results in event being sent to server. If event needs to be changed to be able to work from within AJAX request, then new event needs to be created for each wrapped event:

protected function OnCreateAjax(kEvent $event)
	$ajax_form_helper = $this->Application->recallObject('AjaxFormHelper');
	/* @var $ajax_form_helper AjaxFormHelper */
	$ajax_form_helper->transitEvent($event, 'OnCreate');


I propose to create a universal wrapper code, e.g. new "wrapForAjax" method in event handler, that would catch all requests to undefined *Ajax events and if original event (after removing Ajax word) exists call it.

As for permissions, then we should check a permissions for a wrapped event and not create a special permission for *Ajax events directly.


Related Tasks

INP-1320 - Getting issue details... STATUS


  1. Also we can introduce @ajax annotation for events. Once present, then we automatically perform check (outside event), that $this->Application->GetVar('ajax') == 'yes' before even allowing event to run. 

  2. Sidenote about permission checking: if you a custom permission checking logic (e.g. one not involving the mapping set in the mapPermissions method), then you need to check for actual event name (e.g. OnCreateAjax) and not for transit event name (e.g. OnCreate) in your CheckPermission method code.