In this tutorial, We will see how Web2Cal can be used in a health-club to display events. The aim of this tutorial is to help you understand the integration of the calendar and how to create custom templates and integrate them using callback methods.
For the impatient, Click Here to view the demo in a new window.
Manager calendar will have the ability to schedule New Training Session in the club.
For this screen, we will
We will identify the information required by the calendar to display events on the web calendar.
Shown below is the preview. This element will be displayed when the user clicks on any event in the calendar.
| Start: ${function: printStartDate} End: ${formattedEndTime} |
Location: ${location} Conducted By: ${instructor} |
| Facility: ${facility} Event Type: ${eventType} |
Capacity: ${capacity} Lead Days to Cancel: ${leadDaysToCancel} |
| Description:
${description}
|
|
Note that the attributes of the JSON object are surrounded with a ${ }. Web2Cal will replace these attributes with actual values when preview is invoked. You can further customize it by providing a callback method onPreview (For More Information check the Callbacks section of this article). You can further customize each attribute by providing a function. ${function: printTime}. This function will be invoked when Web2Cal parses the the preview element. In the example shown below, We print just the Date and Month for Start Time:
function printStartDate(eventObject)
{
return eventObject.startTime.getDate() +"/" + eventObject.startTime.getMonth();
}
Don't forget to return the string.
The HTML for preview element is shown below
onPreview function is a useful hook if you need to fetch the most recent information from database before showing preview, you may want to make the DB call before showing the preview.
In the next step, we will design the form to create the new event.
We will implement the "onNewEvent" callback, to populate the appropriate text fields. When the user clicks "Save Event" button, the information in the form will be persisted in a database( or any other datastore ) and the newly added event will be displayed in the calendar by invoking ical.addEvent(<new event object>).
Custom form to create a new event
|
Select Product
|
|
|
Facility
|
Trainers
|
|
From Date
|
To Date
|
|
Start Time
|
End Time
|
|
Capacity
|
|
|
Notes
|
|
The Calendar exposes rich set of callback events to enable fine grained control of the behavior. For the above Health Club example we will focus on:
This callback event is invoked when user attempts to create a new event by either dragging the mouse or clicking Quick Add. Use this callback method to populate the custom fields of your form.
The parameters for the onNewEvent callback are
This callback is invoked when user moves an event or resizes an event in any view.
A typical implementation is
This callback is invoked when user clicks on any event displayed in Web2Cal. The Default implementation will attempt to convert and display your preview element( Explained above ) with the actual event data.
This callback will be particularly useful if you need to get real-time data to show the preview.
An example would be, if you want to get the Registered / Waitlisted members list for an event.
A typical implementation is
The parameters are
When you are ready to show the updated preview, you must invoke ical.showPreview(calEvent, updatedHTML);
Coming Soon... Please check again..