6b111a078ff2fd2ceedf64abc6a85205f335917b
[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 . See the Mishoo documentation for details of the '$e %B %Y' parameter.
77
78 `addHEAD` can be called from `commonTagsHandler` for adding the header to all pages, or from `beforeEditHandler` just for edit pages etc.
79
80 ### <a name="Using the Calendar in user forms"></a> Using the Calendar in user forms
81
82 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:
83
84     %INCLUDE{"%SYSTEMWEB%/JSCalendarContribInline"}%
85
86 Then, to display a calendar icon next to a text input field:
87
88     <input type="text" id="cal_val_here" />
89     <input type="image" src="%PUBURL%/%SYSTEMWEB%/JSCalendarContrib/img.gif" onclick="javascript: return showCalendar('cal_val_here','%e %B %Y')" />
90
91 If the contrib is installed, you will see such a field here:
92
93 <input id="cal_val_here" type="text" />
94  <input onclick="javascript: return showCalendar('cal_val_here','%e %B %Y')" src="http://www.dementia.org/twiki//view/%SYSTEMWEB%/JSCalendarContrib/img.gif" type="image" />
95
96 ### <a name="Installation Instructions"></a> Installation Instructions
97
98 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.
99
100 Like many other TWiki extensions, this module is shipped with a fully automatic installer script written using the BuildContrib.
101
102 - If you have TWiki 4.2 or later, you can install from the `configure` interface (Go to Plugins-&gt;Find More Extensions)
103   - See the [installation supplement](http://twiki.org/cgi-bin/view/Plugins/BuildContribInstallationSupplement) on TWiki.org for more information.
104 - If you have any problems, then you can still install manually from the command-line:
105   1. Download one of the `.zip` or `.tgz` archives
106   2. Unpack the archive in the root directory of your TWiki installation.
107   3. Run the installer script ( `perl <module>_installer` )
108   4. Run `configure` and enable the module, if it is a plugin.
109   5. Repeat for any missing dependencies.
110 - If you are **still** having problems, then instead of running the installer script:
111   1. Make sure that the file permissions allow the webserver user to access all files.
112   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)
113   3. Manually edit LocalSite.cfg to set any configuration variables.
114
115 <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>
116
117 - An administrator can customize the appearance of the calendar by setting the following in `LocalSite.cfg`<table border="1" cellpadding="0" cellspacing="0">
118   <tr>
119     <th bgcolor="#99CCCC"><strong> Setting </strong></th>
120     <th bgcolor="#99CCCC"><strong> Default </strong></th>
121   </tr>
122   <tr>
123     <td><code>$TWiki::cfg{JSCalendarContrib}{style}</code></td>
124     <td><code>'blue'</code></td>
125   </tr>
126   <tr>
127     <td><code>$TWiki::cfg{JSCalendarContrib}{lang}</code></td>
128     <td><code>'en'</code></td>
129   </tr>
130   <tr>
131     <td><code>$TWiki::cfg{JSCalendarContrib}{format}</code></td>
132     <td><code>'%e %b %Y'</code></td>
133   </tr>
134 </table>
135
136 ### <a name="Contrib Info"></a> Contrib Info
137
138 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!
139
140 <table border="1" cellpadding="0" cellspacing="0">
141   <tr>
142     <td align="right"> Author: </td>
143     <td> TWiki:Main/CrawfordCurrie <a href="http://c-dot.co.uk" target="_top">http://c-dot.co.uk</a></td>
144   </tr>
145   <tr>
146     <td align="right"> Version: </td>
147     <td> 16236 (22 Jan 2008) of the Mishoo calendar </td>
148   </tr>
149   <tr>
150     <td align="right"> Copyright ©: </td>
151     <td> See <a href="http://www.dementia.org/twiki//view/doc/html/reference.html" target="_top">the Mishoo documentation</a></td>
152   </tr>
153   <tr>
154     <td align="right"> License: </td>
155     <td> GPL (<a href="http://www.gnu.org/copyleft/gpl.html" target="_top">GNU General Public License</a>) </td>
156   </tr>
157   <tr>
158     <td align="right"> Dependencies: </td>
159     <td> None </td>
160   </tr>
161   <tr>
162     <td> Change History: </td>
163     <td>   </td>
164   </tr>
165   <tr>
166     <td align="right"> 6 Sep 2007 </td>
167     <td> Bugs:Item4030 Added doc for using the calendar in user forms </td>
168   </tr>
169   <tr>
170     <td align="right"> 13603 </td>
171     <td> Bugs:Item2982 cleaned up the interface to the contrib, re-added a date rendering function with a more generic interface </td>
172   </tr>
173   <tr>
174     <td align="right"> 11594 </td>
175     <td> Allow format to be configured. </td>
176   </tr>
177   <tr>
178     <td align="right"> 11415 </td>
179     <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>
180   </tr>
181   <tr>
182     <td align="right"> 10247 </td>
183     <td> Bugs:Item2054 put the calendar at z-index 2000, way above pattern skin divs. </td>
184   </tr>
185   <tr>
186     <td align="right"> 6634 </td>
187     <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>
188   </tr>
189   <tr>
190     <td align="right"> 6626 </td>
191     <td> Bugs:Item468 updated docs for Dakar release </td>
192   </tr>
193   <tr>
194     <td align="right"> 5048 </td>
195     <td> Cairo readiness </td>
196   </tr>
197   <tr>
198     <td align="right"> 5039 </td>
199     <td> Split from [[Main/SharedCode]]</td>
200   </tr>
201   <tr>
202     <td align="right"> 27 Dec 2005 </td>
203     <td> updated to calendar version 1.0; set style for Safari to win2k-1 </td>
204   </tr>
205   <tr>
206     <td align="right"> 14 Aug 2004 </td>
207     <td> Separated out from [[Main/SharedCode]] module </td>
208   </tr>
209   <tr>
210     <td align="right"> Home: </td>
211     <td><a href="http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%" target="_top">http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%</a></td>
212   </tr>
213   <tr>
214     <td align="right"> Feedback: </td>
215     <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>
216   </tr>
217   <tr>
218     <td align="right"> Appraisal: </td>
219     <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>
220   </tr>
221 </table>
222
223 **_Related Topics:_** %SYSTEMWEB%.TWikiPreferences