Callback Functions

Callback Methods

loadEvents ( start, end, viewName)
Summary This function is responsible to provide the data to be displayed. 
Parameters
  • start - Date - The start of the range of dates currently displayed
  • end - Date - The end of the range of dates currently displayed.
  • viewName - String - The name of the view currently being displayed. 
    One of day, week, month, workshift, w2cview, agenda, custom

 

Returns Returns an Array of Group Objects. For more information about the structure, please see the Calendar Data Structure.
Description This function is invoked after the calendar is rendered for the first time and also every time the view is changed.
onNewEvent(event, groups, allDay)
Summary This callback function is invoked when user is creating an event by either dragging on the calendar grid or clicking Quick Add on the calendar.
Parameters
  • event - Object. Event object contains the start time and end time of the event.
  • groups - Array. List of group objects. (Provided for convenience)
  • allDay - boolean. Indicates if the user tried to create an all day event.
Returns void
Description

Typical use of this function will be to display a form to collect additional information for an event. We can pre-populate the start time and end time in the form with the start and end returned in the event object. 

Note: There is one specific callback function for each view. With Web2Cal 2.0 or greater, you can specify one generic onNewEvent callback for all views. 

  • weekOnNewEvent - For Week View
  • wsOnNewEvent - For Workshift View
  • agendaOnNewEvent - For Agenda View
  • monthOnNewEvent - For Month View
onUpdate( event )
Summary This function is invoked when user drags an event to change its date and time.
Parameters
  • event - Object - The event object that is being dragged. Note: If an event object contains many custom fields, all those fields will be provided. Not just the new date and time. 
Returns void
Description

Typical use of this function will be to persist the new date and time for the event. Once the database is updated,  you must, update it in Web2Cal's cache as well. This is done by invoking updateEvent on Web2Cal API. For more information on updateEvent click here.

Note: Although implementing this method is optional, it is highly recommended you do implement. This is the only way to persist user's drag and drop action.

onPreview( calEvent, event, html)
Summary This function is invoked when user clicks on any event that is being displayed in the calendar.
Parameters
  • calEvent - Dom Object - This is the event that user clicked on.
  • event - Object - This is the entire event data object.
  • html - jQuery Object - If you have specified a preview element, Web2Cal will parse the template and replace the variables with the values in event Object. The updated Html object is provided to you for convenience.
Returns void
Description

This method is a window to control the behavior of event preview being displayed. If you implement this function, you must explicitly call showPreview on Web2Cal API to display the preview. Click here for more information on showPreview method.

Note: Implementing this method is optional. If you do no specify this method, Web2Cal will implicitly convert the preview with event's information and display. 

There is a unique onPreview function for each view in Web2Cal. There is a specific callback for each view in the calendar. So, the following callbacks are similar to this one.

  • monthOnPreview - For Month View
  • wsOnPreview - For Workshift View
  • agendaOnPreview - For Agenda View
  • w2cOnPreview - For w2c View

With Web2Cal premium 2.0 onwards, you can just specify a generic "onPreview" callback for all views.