Javascript Widgets:Calendar widget
From ReservesDirect: Open Source EReserves System
To ease the input of dates, ReservesDirect makes use of the Dynarch DHTML Calendar (http://www.dynarch.com/projects/calendar/) widgets, which is available under LGPL. The Dynarch calendar package includes the necessary JavaScript files, as well as a simple wrapper class written in PHP. ReservesDirect adds another wrapping layer to streamline and unify the setup and configuration options of all the widgets.
Setup
First, the calendar is set up in the following way:
- Include the necessary php file(s).
require_once('secure/classes/calendar.class.php');
- The Calendar class includes and extends the DHTM_Calendar class, included in the Dynarch package.
- Initialize a Calendar object.
$calendar = new Calendar();
- The constructor of this wrapper class sets some default options that will affect all the widgets made with this object, such as date format, etc.
- A single Calendar object can be used to insert numerous calendar widgets with different dates.
- Include the JavaScript files.
$calendar->load_files();
- This call must be made inside the HTML <head> </head> tags.
Usage
Once the setup is complete, inserting a calendar widget into a form is simple, although careful attention must be paid to the form elements' ID attributes.
- The most simple way is to include a date input field, calendar widget, and calendar trigger (button that brings up a pop-up calendar) in one method call.
- The first argument is set as the name of the input field and the second (optional) argument pre-fills the input field with a date and defaults the widget to that date.
$calendar->getDateFieldWidget("date", $default_date=null)
- The second way is to create your own input field and then set up a widget/trigger for it
- The first argument is the ID of the input element.
<input type="text" name="date" id="date-target" /> <?php echo $calendar->getWidgetAndTrigger("date-target", $default_date = null); ?>
- If you would like to include a widget, but customize the input field and the trigger, you may do so like this:
<input type="text" name="date" id="date-target" /> <input type="button" name="button" id="date-trigger" /> <?php echo $calendar->getWidget("date-trigger", "date-target", $default_date = null); ?>
The calendar wrapper class included in ReservesDirect attempts to make inserting widgets as easy as possible, by limiting the calendar functionality and pre-setting common options. Further customization can be accomplished by editing the source.
