How to Add Server-side Event Handlers to the Web2Cal Calendar to Respond to Event Changes

Description

Event handlers can be added to the Web2Cal Calendar when an event is added, edited, moved, or deleted.

Discussion

When using the Web2Cal calendar control you might want to execute server-side code for the following events:

  • an event is added
  • an event is edited
  • an event is moved
  • an event is deleted

There are no built-in hooks for these events, but you can easily define you own.

For the event added, edited, or deleted cases, you can add event handlers as follows:

  1. Edit the UX component used to edit events and add the functions shown below to the Xbasic function declarations

    function onEventDelete as v (e as p)
    end function
    
    function onEventUpdate as v (e as p)
    end function
    
    function onEventAdd as v (e as p)
    end function
  2. Edit the UX component used to edit events and modify the server-side afterDialogValidate event to add calls to the onEventUpdate and onEventAdd functions. See below.

  3. Edit the UX component used to edit events and modify the deleteEventXbasic Xbasic function by adding the following at the end of the function: onEventDelete(e)

 How to Update the afterDialogValidate Event Handler Function

In the UX Component used to edit events, update the code in the afterDialogValidate event to call the onEventUpdate() function:

'update the event on the calendar
dim javascriptUpdateCalendar as c
dim po as p
if pv.eventsMode = "EditEvent" then
    po.eventId = convert_type(e.dataSubmitted.eventId,"N")
    
    'add call to onEventUpdate:
    onEventUpdate(e)

else
    po.eventId = eventId

    'add eventId to e and call to onEventUpdate:
    e.eventId = po.eventId
    onEventAdd(e)

end if

To handle the event is moved case, edit the Web2Cal component and add this code to the onComponentExecute server-side event:

if eval_valid("request.variables._XbasicFunction") then 
    if request.variables._XbasicFunction = "updateEvents" then 
        'event was moved
        'event data can be found in request.variables._calEvent_eventId, etc.
    end if 
end if