(no commit message)
[openafs-wiki.git] / TWiki / JSCalendarContrib.mdwn
1 # <a name="%TOPIC%"></a><a name=" %TOPIC%"></a> %TOPIC%
2
3 ![](http://www.dementia.org/twiki//view/screenshot.gif)
4
5 %SHORTDESCRIPTION%
6
7 <div>
8   <ul>
9     <li><a href="#Summary of Contents"> Summary of Contents</a></li>
10     <li><a href="#Detailed Documentation"> Detailed Documentation</a><ul>
11         <li><a href="#TWiki::Contrib::_JSCalendarContr"> TWiki::Contrib::JSCalendarContrib::renderDateForEdit($name, $value, $format [, \%cssClass]) -&gt; $html</a></li>
12         <li><a href="#TWiki::Contrib::_JSCalendarContr"> TWiki::Contrib::JSCalendarContrib::addHEAD($setup)</a></li>
13         <li><a href="#Using the Calendar in user forms"> Using the Calendar in user forms</a></li>
14         <li><a href="#Installation Instructions"> Installation Instructions</a></li>
15         <li><a href="#Contrib Info"> Contrib Info</a></li>
16       </ul>
17     </li>
18   </ul>
19 </div>
20
21 ## <a name="Summary of Contents"></a> Summary of Contents
22
23 This module packages the [Mishoo JSCalendar](http://dynarch.com/mishoo/calendar.epl) Javascript in a form suitable for use with TWiki.
24
25 ## <a name="Detailed Documentation"></a> Detailed Documentation
26
27 Read [the Mishoo documentation](http://www.dementia.org/twiki//view/doc/html/reference.html) or [visit the demo page](http://www.dementia.org/twiki//view) for detailed information on using the calendar widget.
28
29 This package also includes a small Perl module to make using the calendar easier from TWiki plugins. This module includes the functions:
30
31 ### <a name="TWiki::Contrib::_JSCalendarContr"></a> TWiki::Contrib::JSCalendarContrib::renderDateForEdit($name, $value, $format [, \\%cssClass]) -&gt; $html
32
33 This is the simplest way to use calendars from a plugin.
34
35 - `$name` is the name of the CGI parameter for the calendar (it should be unique),
36 - `$value` is the current value of the parameter (may be undef)
37 - `$format` is the format to use (optional; the default is set in `configure`). The HTML returned will display a date field and a drop-down calendar.
38 - `\%options` is an optional hash containing base options for the textfield.
39
40 Example:
41
42     use TWiki::Contrib::JSCalendarContrib;
43     ...
44     my $fromDate = TWiki::Contrib::JSCalendarContrib::renderDateForEdit(
45        'from', '1 April 1999');
46     my $toDate = TWiki::Contrib::JSCalendarContrib::renderDateForEdit(
47        'to', undef, '%Y');
48
49 ### <a name="TWiki::Contrib::_JSCalendarContr"></a> TWiki::Contrib::JSCalendarContrib::addHEAD($setup)
50
51 This function will automatically add the headers for the calendar to the page being rendered. It's intended for use when you want more control over the formatting of your calendars than `renderDateForEdit` affords. `$setup` is the name of the calendar setup module; it can either be omitted, in which case the method described in the Mishoo documentation can be used to create calendars, or it can be `'twiki'`, in which case a Javascript helper function called 'showCalendar' is added that simplifies using calendars to set a value in a text field. For example, say we wanted to display the date with the calendar icon _before_ the text field, using the format `%Y %b %e`
52
53     # Add styles and javascript for the calendar
54     use TWiki::Contrib::JSCalendarContrib;
55     ...
56
57     sub commonTagsHandler {
58       ....
59       # Enable 'showCalendar'
60       TWiki::Contrib::JSCalendarContrib::addHEAD( 'twiki' );
61
62       my $cal = CGI::image_button(
63           -name => 'img_datefield',
64           -onclick =>
65            "return showCalendar('id_datefield','%Y %b %e')",
66           -src=> TWiki::Func::getPubUrlPath() . '/' .
67                  TWiki::Func::getTwikiWebname() .
68                  '/JSCalendarContrib/img.gif',
69           -alt => 'Calendar',
70           -align => 'middle' )
71         . CGI::textfield(
72           { name => 'date', id => "id_datefield" });
73       ....
74     }
75
76 The first parameter to `showCalendar` is the id of the textfield, and the second parameter is the date format. Default format is '%e %B %Y'.
77
78 All available date specifiers:
79
80     %a - abbreviated weekday name
81     %A - full weekday name
82     %b - abbreviated month name
83     %B - full month name
84     %C - century number
85     %d - the day of the month ( 00 .. 31 )
86     %e - the day of the month ( 0 .. 31 )
87     %H - hour ( 00 .. 23 )
88     %I - hour ( 01 .. 12 )
89     %j - day of the year ( 000 .. 366 )
90     %k - hour ( 0 .. 23 )
91     %l - hour ( 1 .. 12 )
92     %m - month ( 01 .. 12 )
93     %M - minute ( 00 .. 59 )
94     %n - a newline character
95     %p - "PM" or "AM"
96     %P - "pm" or "am"
97     %S - second ( 00 .. 59 )
98     %s - number of seconds since Epoch (since Jan 01 1970 00:00:00 UTC)
99     %t - a tab character
100     %U, %W, %V - the week number
101        The week 01 is the week that has the Thursday in the current year,
102        which is equivalent to the week that contains the fourth day of January.
103        Weeks start on Monday.
104     %u - the day of the week ( 1 .. 7, 1 = MON )
105     %w - the day of the week ( 0 .. 6, 0 = SUN )
106     %y - year without the century ( 00 .. 99 )
107     %Y - year including the century ( ex. 1979 )
108     %% - a literal % character
109
110 `addHEAD` can be called from `commonTagsHandler` for adding the header to all pages, or from `beforeEditHandler` just for edit pages etc.
111
112 ### <a name="Using the Calendar in user forms"></a> Using the Calendar in user forms
113
114 You can also use the calendar directly in your own hand-built forms, without having to write any code. Just add this inline in the topic text:
115
116     %INCLUDE{"%TWIKIWEB%/JSCalendarContribInline"}%
117
118 Then, to display a calendar icon next to a text input field:
119
120     <input type="text" id="cal_val_here" />
121     <input type="image" src="%PUBURL%/%TWIKIWEB%/JSCalendarContrib/img.gif" onclick="javascript: return showCalendar('cal_val_here','%e %B %Y')" />
122
123 If the contrib is installed, you will see such a field here:
124
125 <input id="cal_val_here" type="text" />
126  <input onclick="javascript: return showCalendar('cal_val_here','%e %B %Y')" src="http://www.dementia.org/twiki//view/TWiki/JSCalendarContrib/img.gif" type="image" />
127
128 ### <a name="Installation Instructions"></a> Installation Instructions
129
130 You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server where TWiki is running.
131
132 Like many other TWiki extensions, this module is shipped with a fully automatic installer script written using the BuildContrib.
133
134 - If you have TWiki 4.2 or later, you can install from the `configure` interface (Go to Plugins-&gt;Find More Extensions)
135   - See the [installation supplement](http://twiki.org/cgi-bin/view/Plugins/BuildContribInstallationSupplement) on TWiki.org for more information.
136 - If you have any problems, then you can still install manually from the command-line:
137   1. Download one of the `.zip` or `.tgz` archives
138   2. Unpack the archive in the root directory of your TWiki installation.
139   3. Run the installer script ( `perl <module>_installer` )
140   4. Run `configure` and enable the module, if it is a plugin.
141   5. Repeat for any missing dependencies.
142 - If you are **still** having problems, then instead of running the installer script:
143   1. Make sure that the file permissions allow the webserver user to access all files.
144   2. Check in any installed files that have existing `,v` files in your existing install (take care **not** to lock the files when you check in)
145   3. Manually edit LocalSite.cfg to set any configuration variables.
146
147 <div class="twikiAlert">%X% WARNING: SYSTEMWEB is not defined in this TWiki. Please add these definitions to your [[Main/TWikiPreferences]], if they are not already there:<br /><pre>   * Set SYSTEMWEB = %TWIKIWEB%<br />   * Set USERSWEB = %MAINWEB%</pre></div>
148
149 - An administrator can customize the appearance of the calendar by setting the following in `LocalSite.cfg`<table border="1" cellpadding="0" cellspacing="0">
150   <tr>
151     <th bgcolor="#99CCCC"><strong> Setting </strong></th>
152     <th bgcolor="#99CCCC"><strong> Default </strong></th>
153   </tr>
154   <tr>
155     <td><code>$TWiki::cfg{JSCalendarContrib}{style}</code></td>
156     <td><code>'blue'</code></td>
157   </tr>
158   <tr>
159     <td><code>$TWiki::cfg{JSCalendarContrib}{lang}</code></td>
160     <td><code>'en'</code></td>
161   </tr>
162   <tr>
163     <td><code>$TWiki::cfg{JSCalendarContrib}{format}</code></td>
164     <td><code>'%e %b %Y'</code></td>
165   </tr>
166 </table>
167
168 ### <a name="Contrib Info"></a> Contrib Info
169
170 Another great TWiki extension from the [![](http://www.dementia.org/twiki//view/wikiringlogo20x20.png) **WikiRing** ](http://wikiring.com) - working together to improve your wiki experience!
171
172 <table border="1" cellpadding="0" cellspacing="0">
173   <tr>
174     <td align="right"> Author: </td>
175     <td> TWiki:Main/CrawfordCurrie <a href="http://c-dot.co.uk" target="_top">http://c-dot.co.uk</a></td>
176   </tr>
177   <tr>
178     <td align="right"> Version: </td>
179     <td> 17492 (30 Mar 2009) of the Mishoo calendar </td>
180   </tr>
181   <tr>
182     <td align="right"> Copyright ©: </td>
183     <td> See <a href="http://www.dementia.org/twiki//view/doc/html/reference.html" target="_top">the Mishoo documentation</a></td>
184   </tr>
185   <tr>
186     <td align="right"> License: </td>
187     <td> GPL (<a href="http://www.gnu.org/copyleft/gpl.html" target="_top">GNU General Public License</a>) </td>
188   </tr>
189   <tr>
190     <td align="right"> Dependencies: </td>
191     <td> None </td>
192   </tr>
193   <tr>
194     <td> Change History: </td>
195     <td>   </td>
196   </tr>
197   <tr>
198     <td align="right"> 10 Sep 2008 </td>
199     <td> Bugs:Item5991 Applied patch to fix rendering on IE7 . </td>
200   </tr>
201   <tr>
202     <td align="right"> 06 Sep 2007 </td>
203     <td> Bugs:Item4030 Added doc for using the calendar in user forms </td>
204   </tr>
205   <tr>
206     <td align="right"> 13603 </td>
207     <td> Bugs:Item2982 cleaned up the interface to the contrib, re-added a date rendering function with a more generic interface </td>
208   </tr>
209   <tr>
210     <td align="right"> 11594 </td>
211     <td> Allow format to be configured. </td>
212   </tr>
213   <tr>
214     <td align="right"> 11415 </td>
215     <td> Add a <code>renderFormFieldForEditHandler</code> so other plugins can forward to this handler to add the date field to the [[Main/TWikiForms]]. (TWiki:Main.ThomasWeigert) </td>
216   </tr>
217   <tr>
218     <td align="right"> 10247 </td>
219     <td> Bugs:Item2054 put the calendar at z-index 2000, way above pattern skin divs. </td>
220   </tr>
221   <tr>
222     <td align="right"> 6634 </td>
223     <td> Bugs:Item453 removed [[Main/EditTablePlugins]] private copy of the Mishoo JS calendar, and made sure it works with [[Main/JSCalendarContrib]]. Improved the documentation of the JSCalendar while I was there. </td>
224   </tr>
225   <tr>
226     <td align="right"> 6626 </td>
227     <td> Bugs:Item468 updated docs for Dakar release </td>
228   </tr>
229   <tr>
230     <td align="right"> 5048 </td>
231     <td> Cairo readiness </td>
232   </tr>
233   <tr>
234     <td align="right"> 5039 </td>
235     <td> Split from SharedCode </td>
236   </tr>
237   <tr>
238     <td align="right"> 27 Dec 2005 </td>
239     <td> updated to calendar version 1.0; set style for Safari to win2k-1 </td>
240   </tr>
241   <tr>
242     <td align="right"> 14 Aug 2004 </td>
243     <td> Separated out from SharedCode module </td>
244   </tr>
245   <tr>
246     <td align="right"> Home: </td>
247     <td><a href="http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%" target="_top">http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%</a></td>
248   </tr>
249   <tr>
250     <td align="right"> Feedback: </td>
251     <td><a href="http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Dev" target="_top">http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Dev</a></td>
252   </tr>
253   <tr>
254     <td align="right"> Appraisal: </td>
255     <td><a href="http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Appraisal" target="_top">http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Appraisal</a></td>
256   </tr>
257 </table>
258
259 **_Related Topics:_** [[TWikiPreferences]]