Bug 21885: Calendar to-date starts before end-date
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / holidays.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Branches %]
4 [% SET footerjs = 1 %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Koha &rsaquo; Tools &rsaquo; [% Branches.GetName( branch ) | html %] calendar</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 [% Asset.css("css/datatables.css") | $raw %]
9 <style> .key { padding : 3px; white-space:nowrap; line-height:230%; }
10 .ui-datepicker { font-size : 150%; }
11 .ui-datepicker th, .ui-datepicker .ui-datepicker-title select { font-size : 80%; }
12 .ui-datepicker td a { padding : .5em; }
13 .ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current { font-size : 80%; }
14 .key { padding : 3px; white-space:nowrap; line-height:230%; }
15 .normalday { background-color :  #EDEDED; color :  Black; border : 1px solid #BCBCBC; }
16 .exception { background-color :  #b3d4ff; color :  Black; border : 1px solid #BCBCBC; }
17 .holiday {  background-color :  #ffaeae; color :  Black;  border : 1px solid #BCBCBC; }
18 .repeatableweekly {  background-color :  #FFFF99; color :  Black;  border : 1px solid #BCBCBC; }
19 .repeatableyearly {  background-color :  #FFCC66; color :  Black;  border : 1px solid #BCBCBC; }
20 td.exception a.ui-state-default { background:  #b3d4ff none; color :  Black; border : 1px solid #BCBCBC; }
21 td.holiday a.ui-state-default {  background:  #ffaeae none; color :  Black;  border : 1px solid #BCBCBC; }
22 td.repeatableweekly a.ui-state-default {  background:  #FFFF99 none; color :  Black;  border : 1px solid #BCBCBC; }
23 td.repeatableyearly a.ui-state-default {  background:  #FFCC66 none; color :  Black;  border : 1px solid #BCBCBC; }
24 .information { z-index : 1; background-color :  #DCD2F1; width : 300px; display : none; border : 1px solid #000000; color :  #000000; font-size :  8pt; font-weight :  bold; background-color :  #FFD700; cursor :  pointer; padding : 2px; }
25 .panel { z-index : 1; display : none; border : 3px solid #CCC; padding : 3px; margin-top: .3em;  background-color: #FEFEFE; } fieldset.brief { border : 0; margin-top: 0; }
26 #showHoliday { margin : .5em 0; } h1 select { width: 20em; } fieldset.brief ol { font-size:100%; } fieldset.brief li, fieldset.brief li.radio  { padding:0.2em 0; } .help { margin:.3em 0;border:1px solid #EEE;padding:.3em .7em; font-size : 90%; } #holidayweeklyrepeatable, #holidaysyearlyrepeatable, #holidaysunique, #holidayexceptions { font-size : 90%; margin-bottom : 1em;} .calendar td, .calendar th, .calendar .button, .calendar tbody .day { padding : .7em; font-size: 110%; } .calendar { width: auto; border : 0; }
27 </style>
28 </head>
29 <body id="tools_holidays" class="tools">
30 [% INCLUDE 'header.inc' %]
31 [% INCLUDE 'cat-search.inc' %]
32
33 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; [% Branches.GetName( branch ) | html %] calendar</div>
34
35 <div class="main container-fluid">
36     <div class="row">
37         <div class="col-sm-10 col-sm-push-2">
38             <main>
39
40     <h2>[% Branches.GetName( branch ) | html %] calendar</h2>
41
42     <div class="row">
43     <div class="col-sm-6">
44         <label for="branch">Define the holidays for:</label>
45             <select id="branch" name="branch">
46                 [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
47             </select>
48     
49     <!-- ******************************** FLAT PANELS ******************************************* -->
50     <!-- *****           Makes all the flat panel to deal with holidays                     ***** -->
51     <!-- **************************************************************************************** -->
52
53     <!-- ********************** Panel for showing already loaded holidays *********************** -->
54     <div class="panel" id="showHoliday">
55          <form action="/cgi-bin/koha/tools/exceptionHolidays.pl" method="post">
56              <input type="hidden" id="showHolidayType" name="showHolidayType" value="" />
57             <fieldset class="brief">
58             <h3>Edit this holiday</h3>
59             <span id="holtype"></span>
60             <ol>
61             <li>
62                 <strong>Library:</strong> <span id="showBranchNameOutput"></span>
63                 <input type="hidden" id="showBranchName" name="showBranchName" />
64             </li>
65             <li>
66                 <strong>From date:</strong>
67                 <span id="showDaynameOutput"></span>, 
68                 
69                                 [% IF ( dateformat == "us" ) %]<span id="showMonthOutput"></span>/<span id="showDayOutput"></span>/<span id="showYearOutput"></span>[% ELSIF ( dateformat == "metric") %]<span id="showDayOutput"></span>/<span id="showMonthOutput"></span>/<span id="showYearOutput"></span>[% ELSIF ( dateformat == "dmydot") %]<span id="showDayOutput"></span>.<span id="showMonthOutput"></span>.<span id="showYearOutput"></span>[% ELSE %]<span id="showYearOutput"></span>/<span id="showMonthOutput"></span>/<span id="showDayOutput"></span>[% END %]
70
71                 <input type="hidden" id="showDayname" name="showDayname" />
72                 <input type="hidden" id="showWeekday" name="showWeekday" />
73                 <input type="hidden" id="showDay" name="showDay" />
74                 <input type="hidden" id="showMonth" name="showMonth" />
75                 <input type="hidden" id="showYear" name="showYear" />
76             </li>
77             <li class="dateinsert">
78                 <b>To Date : </b>
79                 <input type="text" id="datecancelrange" name="datecancelrange" size="20" value="[% datecancelrange | html %]" class="datepicker"/>
80             </li>
81             <li><label for="showTitle">Title: </label><input type="text" name="showTitle" id="showTitle" size="35" /></li>
82             <!-- showTitle is necessary for exception radio button to work properly -->
83             <li>
84                 <label for="showDescription">Description:</label>
85                 <textarea rows="2" cols="40" id="showDescription" name="showDescription"></textarea>
86             </li>
87             <li class="radio"><div id="exceptionPosibility" style="position:static">
88                 <input type="radio" name="showOperation" id="showOperationExc" value="exception" /> <label for="showOperationExc">Generate an exception for this repeated holiday.</label>
89                 <a href="#" class="helptext">[?]</a>
90                 <div class="hint">You can make an exception for this holiday rule. This means that you will be able to say that for a repeatable holiday there is one day which is going to be an exception.</div>
91             </div></li>
92             <li class="radio"><input type="radio" name="showOperation" id="showOperationExcRange" value="exceptionrange" />
93                 <label for="showOperationExcRange">Generate exceptions on a range of dates.</label>
94                 <a href="#" class="helptext">[?]</a>
95                 <div class="hint">You can make an exception on a range of dates repeated yearly.</div>
96             </li>
97             <li class="radio"><input type="radio" name="showOperation" id="showOperationDel" value="delete" /> <label for="showOperationDel" id="showOperationDelLabel">Delete this holiday</label>
98                 <a href="#" class="helptext">[?]</a>
99                 <div class="hint">This will delete this holiday rule. If it is a repeatable holiday, this option checks for possible exceptions. If an exception exists, this option will remove the exception and set the date to a regular holiday.</div></li>
100             <li class="radio"><input type="radio" name="showOperation" id="showOperationDelRange" value="deleterange" /> <label for="showOperationDelRange" id="showOperationDelLabelRange">Delete the single holidays on a range</label>.
101                 <a href="#" class="helptext">[?]</a>
102                 <div class="hint">This will delete the single holidays rules only. The repeatable holidays and exceptions will not be deleted.</div>
103             </li>
104             <li class="radio"><input type="radio" name="showOperation" id="showOperationDelRangeRepeat" value="deleterangerepeat" /> <label for="showOperationDelRangeRepeat" id="showOperationDelLabelRangeRepeat">Delete the repeated holidays on a range</label>.
105                 <a href="#" class="helptext">[?]</a>
106                 <div class="hint">This will delete the repeated holidays rules only. The repeatable holidays will be deleted but not the exceptions.</div>
107             </li>
108             <li class="radio"><input type="radio" name="showOperation" id="showOperationDelRangeRepeatExcept" value="deleterangerepeatexcept" /> <label for="showOperationDelRangeRepeatExcept" id="showOperationDelLabelRangeRepeatExcept">Delete the exceptions on a range</label>.
109                 <a href="#" class="helptext">[?]</a>
110                 <div class="hint">This will delete the exceptions inside a given range. Be careful about your scope range; if it is oversized you could slow down Koha.</div>
111             </li>
112             <li class="radio"><input type="radio" name="showOperation" id="showOperationEdit" value="edit" checked="checked" /> <label for="showOperationEdit">Edit this holiday</label>
113                 <a href="#" class="helptext">[?]</a>
114                 <div class="hint">This will save changes to the holiday's title and description. If the information for a repeatable holiday is modified, it affects all of the dates on which the holiday is repeated.</div></li>
115             </ol>
116             <fieldset class="action">
117                 <input type="submit" name="submit" value="Save" />
118                 <a href="#" class="cancel hidePanel showHoliday">Cancel</a>
119             </fieldset>
120             </fieldset>
121         </form>
122     </div>
123
124     <!-- ***************************** Panel to deal with new holidays **********************  -->
125     <div class="panel" id="newHoliday">
126          <form action="/cgi-bin/koha/tools/newHolidays.pl" method="post">
127             <fieldset class="brief">
128             <h3>Add new holiday</h3>
129             <ol>
130             <li>
131                 <strong>Library:</strong>
132                 <span id="newBranchNameOutput"></span>
133                 <input type="hidden" id="newBranchName" name="newBranchName" />
134             </li>
135             <li>
136                 <strong>From date:</strong>
137                 <span id="newDaynameOutput"></span>, 
138
139                          [% IF ( dateformat == "us" ) %]<span id="newMonthOutput"></span>/<span id="newDayOutput"></span>/<span id="newYearOutput"></span>[% ELSIF ( dateformat == "metric" ) %]<span id="newDayOutput"></span>/<span id="newMonthOutput"></span>/<span id="newYearOutput"></span>[% ELSIF ( dateformat == "dmydot" ) %]<span id="newDayOutput"></span>.<span id="newMonthOutput"></span>.<span id="newYearOutput"></span>[% ELSE %]<span id="newYearOutput"></span>/<span id="newMonthOutput"></span>/<span id="newDayOutput"></span>[% END %]
140
141                 <input type="hidden" id="newDayname" name="showDayname" />
142                 <input type="hidden" id="newWeekday" name="newWeekday" />
143                 <input type="hidden" id="newDay" name="newDay" />
144                 <input type="hidden" id="newMonth" name="newMonth" />
145                 <input type="hidden" id="newYear" name="newYear" />
146             </li>
147             <li class="dateinsert">
148                 <b>To date: </b>
149                 <input type="text" id="dateofrange" name="dateofrange" size="20" value="[% dateofrange | html %]" class="datepicker" />
150             </li>
151             <li><label for="title">Title: </label><input type="text" name="newTitle" id="title" size="35" /></li>
152             <li><label for="newDescription">Description:</label>
153                 <textarea rows="2" cols="40" id="newDescription" name="newDescription"></textarea>
154             </li>
155             <li class="radio"><input type="radio" name="newOperation" id="newOperationOnce" value="holiday" checked="checked" />
156             <label for="newOperationOnce">Holiday only on this day</label>.
157             <a href="#" class="helptext">[?]</a>
158             <div class="hint">Make a single holiday. For example, selecting August 1, 2012 will make it a holiday, but will not affect August 1 in other years.</div>
159             </li>
160             <li class="radio"><input type="radio" name="newOperation" id="newOperationDay" value="weekday" />
161                             <label for="newOperationDay">Holiday repeated every same day of the week</label>.
162                             <a href="#" class="helptext">[?]</a>
163                             <div class="hint">Make this weekday a holiday, every week. For example, if your library is closed on Saturdays, use this option to make every Saturday a holiday.</div>
164                             </li>
165             <li class="radio"><input type="radio" name="newOperation" id="newOperationYear" value="repeatable" />
166                             <label for="newOperationYear">Holiday repeated yearly on the same date</label>.
167                             <a href="#" class="helptext">[?]</a>
168                             <div class="hint">This will take this day and month as a reference to make it a holiday. Through this option, you can repeat this rule for every year. For example, selecting August 1 will make August 1 a holiday every year.</div>
169                             </li>
170             <li class="radio"><input type="radio" name="newOperation" id="newOperationField" value="holidayrange" />
171                             <label for="newOperationField">Holidays on a range</label>.
172                             <a href="#" class="helptext">[?]</a>
173                             <div class="hint">Make a single holiday on a range. For example, selecting August 1, 2012  and August 10, 2012 will make all days between August 1 and 10 a holiday, but will not affect August 1-10 in other years.</div>
174                             </li>
175             <li class="radio"><input type="radio" name="newOperation" id="newOperationFieldyear" value="holidayrangerepeat" />
176                             <label for="newOperationFieldyear">Holidays repeated yearly on a range</label>.
177                             <a href="#" class="helptext">[?]</a>
178                             <div class="hint">Make a single holiday on a range repeated yearly. For example, selecting August 1, 2012  and August 10, 2012 will make all days between August 1 and 10 a holiday, and will affect August 1-10 in other years.</div>
179                             </li>
180                 <li class="checkbox">
181                 <input type="checkbox" name="allBranches" id="allBranches" />
182                 <label for="allBranches">Copy to all libraries</label>.
183                 <a href="#" class="helptext">[?]</a>
184                 <div class="hint">If checked, this holiday will be copied to all libraries. If the holiday already exists for a library, no change is made.</div>
185                 </li></ol>
186                 <fieldset class="action">
187                     <input type="submit" name="submit" value="Save" />
188                     <a href="#" class="cancel hidePanel newHoliday">Cancel</a>
189                 </fieldset>
190                 </fieldset>
191          </form>
192     </div>
193
194     <!-- *************************************************************************************** -->
195     <!-- ******                          END OF FLAT PANELS                               ****** -->
196     <!-- *************************************************************************************** -->
197
198 <!-- ************************************************************************************** -->
199 <!-- ******                              MAIN SCREEN CODE                            ****** -->
200 <!-- ************************************************************************************** -->
201 <h3>Calendar information</h3>
202 <div id="jcalendar-container"></div>
203
204 <div style="margin-top: 2em;">
205 <form action="copy-holidays.pl" method="post">
206     <input type="hidden" name="from_branchcode" value="[% branch | html %]" />
207   <label for="branchcode">Copy holidays to:</label>
208   <select id="branchcode" name="branchcode">
209     <option value=""></option>
210     [% FOREACH l IN Branches.all() %]
211     <option value="[% l.branchcode | html %]">[% l.branchname | html %]</option>
212     [% END %]
213   </select>
214     <input type="submit" value="Copy" />
215 </form>
216 </div>
217
218 </div>
219 <div class="col-sm-6">
220 <div class="help">
221 <h4>Hints</h4>
222     <ul>
223         <li>Search in the calendar the day you want to set as holiday.</li>
224         <li>Click the date to add or edit a holiday.</li>
225         <li>Enter a title and description for the holiday.</li>
226         <li>Specify how the holiday should repeat.</li>
227         <li>Click Save to finish.</li>
228     </ul>
229 <h4>Key</h4>
230     <p>
231         <span class="key normalday">Working day</span>
232         <span class="key holiday">Unique holiday</span>
233         <span class="key repeatableweekly">Holiday repeating weekly</span>
234         <span class="key repeatableyearly">Holiday repeating yearly</span>
235         <span class="key exception">Holiday exception</span>
236     </p>
237 </div>
238 <div id="holiday-list">
239 <!-- Exceptions First -->
240 <!--   this will probably always have the least amount of data -->
241 [% IF ( EXCEPTION_HOLIDAYS_LOOP ) %]
242 <h3>Exceptions</h3>
243   <table id="holidayexceptions">
244 <thead><tr>
245   <th class="exception">Date</th>
246   <th class="exception">Title</th>
247   <th class="exception">Description</th>
248 </tr>
249 </thead>
250 <tbody>
251   [% FOREACH EXCEPTION_HOLIDAYS_LOO IN EXCEPTION_HOLIDAYS_LOOP %]
252   <tr>
253   <td><a href="/cgi-bin/koha/tools/holidays.pl?branch=[% branch | uri %]&amp;calendardate=[% EXCEPTION_HOLIDAYS_LOO.DATE | uri %]"><span title="[% EXCEPTION_HOLIDAYS_LOO.DATE_SORT | html %]">[% EXCEPTION_HOLIDAYS_LOO.DATE | html %]</span></a></td>
254   <td>[% EXCEPTION_HOLIDAYS_LOO.TITLE | html %]</td>
255   <td>[% EXCEPTION_HOLIDAYS_LOO.DESCRIPTION | html %]</td>
256   </tr>
257   [% END %] 
258 </tbody>
259 </table>
260 [% END %]
261
262 [% IF ( WEEK_DAYS_LOOP ) %]
263 <h3>Weekly - Repeatable holidays</h3>
264 <table id="holidayweeklyrepeatable">
265 <thead>
266 <tr>
267   <th class="repeatableweekly">Day of week</th>
268   <th class="repeatableweekly">Title</th>
269   <th class="repeatableweekly">Description</th>
270 </tr>
271 </thead>
272 <tbody>
273   [% FOREACH WEEK_DAYS_LOO IN WEEK_DAYS_LOOP %]
274   <tr>
275   <td>[% WEEK_DAYS_LOO.KEY | html %]</td>
276   </td> 
277   <td>[% WEEK_DAYS_LOO.TITLE | html %]</td>
278   <td>[% WEEK_DAYS_LOO.DESCRIPTION | html %]</td>
279   </tr>
280   [% END %] 
281 </tbody>
282 </table>
283 [% END %]
284
285 [% IF ( DAY_MONTH_HOLIDAYS_LOOP ) %]
286 <h3>Yearly - Repeatable holidays</h3>
287 <table id="holidaysyearlyrepeatable">
288 <thead>
289 <tr>
290   [% IF ( dateformat == "metric" ) %]
291   <th class="repeatableyearly">Day/month</th>
292   [% ELSE %]
293   <th class="repeatableyearly">Month/day</th>
294   [% END %]
295   <th class="repeatableyearly">Title</th>
296   <th class="repeatableyearly">Description</th>
297 </tr>
298 </thead>
299 <tbody>
300   [% FOREACH DAY_MONTH_HOLIDAYS_LOO IN DAY_MONTH_HOLIDAYS_LOOP %]
301   <tr>
302   <td><span title="[% DAY_MONTH_HOLIDAYS_LOO.DATE_SORT | html %]">[% DAY_MONTH_HOLIDAYS_LOO.DATE | html %]</span></td>
303   <td>[% DAY_MONTH_HOLIDAYS_LOO.TITLE | html %]</td>
304   <td>[% DAY_MONTH_HOLIDAYS_LOO.DESCRIPTION | html %]</td>
305   </tr>
306   [% END %] 
307 </tbody>
308 </table>
309 [% END %]
310
311 [% IF ( HOLIDAYS_LOOP ) %]
312 <h3>Unique holidays</h3>
313 <table id="holidaysunique">
314 <thead>
315 <tr>
316   <th class="holiday">Date</th>
317   <th class="holiday">Title</th>
318   <th class="holiday">Description</th>
319 </tr>
320 </thead>
321 <tbody>
322     [% FOREACH HOLIDAYS_LOO IN HOLIDAYS_LOOP %]
323 <tr>
324   <td><a href="/cgi-bin/koha/tools/holidays.pl?branch=[% branch | uri %]&amp;calendardate=[% HOLIDAYS_LOO.DATE | uri %]"><span title="[% HOLIDAYS_LOO.DATE_SORT | html %]">[% HOLIDAYS_LOO.DATE | html %]</span></a></td>
325   <td>[% HOLIDAYS_LOO.TITLE | html %]</td>
326   <td>[% HOLIDAYS_LOO.DESCRIPTION.replace('\\\r\\\n', '<br />') | html %]</td>
327 </tr>
328   [% END %] 
329 </tbody>
330 </table>
331 [% END %]
332 </div>
333 </div>
334 </div>
335
336             </main>
337         </div> <!-- /.col-sm-10.col-sm-push-2 -->
338
339         <div class="col-sm-2 col-sm-pull-10">
340             <aside>
341                 [% INCLUDE 'tools-menu.inc' %]
342             </aside>
343         </div> <!-- .col-sm-2.col-sm-pull-10 -->
344      </div> <!-- /.row -->
345
346 [% MACRO jsinclude BLOCK %]
347     [% INCLUDE 'calendar.inc' %]
348     [% INCLUDE 'datatables.inc' %]
349     [% Asset.js("js/tools-menu.js") | $raw %]
350     <script>
351         var weekdays = new Array(_("Sundays"),_("Mondays"),_("Tuesdays"),_("Wednesdays"),_("Thursdays"),_("Fridays"),_("Saturdays"));
352
353         /* Creates all the structures to deal with all different kinds of holidays */
354         var week_days = new Array();
355         var holidays = new Array();
356         var holidates = new Array();
357         var exception_holidays = new Array();
358         var day_month_holidays = new Array();
359         var hola= "[% code | html %]";
360         [% FOREACH WEEK_DAYS_LOO IN WEEK_DAYS_LOOP %]
361         week_days["[% WEEK_DAYS_LOO.KEY | html %]"] = {title:"[% WEEK_DAYS_LOO.TITLE | replace('"','\"') | html %]", description:"[% WEEK_DAYS_LOO.DESCRIPTION | replace('"','\"') | html %]"};
362         [% END %]
363         [% FOREACH HOLIDAYS_LOO IN HOLIDAYS_LOOP %]
364         holidates.push("[% HOLIDAYS_LOO.KEY | html %]");
365         holidays["[% HOLIDAYS_LOO.KEY | html %]"] = {title:"[% HOLIDAYS_LOO.TITLE | replace('"','\"') | html %]", description:"[% HOLIDAYS_LOO.DESCRIPTION | replace('"','\"') | html %]"};
366         [% END %]
367         [% FOREACH EXCEPTION_HOLIDAYS_LOO IN EXCEPTION_HOLIDAYS_LOOP %]
368         exception_holidays["[% EXCEPTION_HOLIDAYS_LOO.KEY | html %]"] = {title:"[% EXCEPTION_HOLIDAYS_LOO.TITLE | replace('"','\"') | html %]", description:"[% EXCEPTION_HOLIDAYS_LOO.DESCRIPTION | replace('"','\"') | html %]"};
369         [% END %]
370         [% FOREACH DAY_MONTH_HOLIDAYS_LOO IN DAY_MONTH_HOLIDAYS_LOOP %]
371         day_month_holidays["[% DAY_MONTH_HOLIDAYS_LOO.KEY | html %]"] = {title:"[% DAY_MONTH_HOLIDAYS_LOO.TITLE | replace('"','\"') | html %]", description:"[% DAY_MONTH_HOLIDAYS_LOO.DESCRIPTION | replace('"','\"') | html %]"};
372         [% END %]
373
374         function holidayOperation(formObject, opType) {
375             var op = document.getElementsByName('operation');
376             op[0].value = opType;
377             formObject.submit();
378         }
379
380         // This function shows the "Show Holiday" panel //
381         function showHoliday (exceptionPosibility, dayName, day, month, year, weekDay, title, description, holidayType) {
382             $("#newHoliday").slideUp("fast");
383             $("#showHoliday").slideDown("fast");
384             $('#showDaynameOutput').html(dayName);
385             $('#showDayname').val(dayName);
386             $('#showBranchNameOutput').html($("#branch :selected").text());
387             $('#showBranchName').val($("#branch").val());
388             $('#showDayOutput').html(day);
389             $('#showDay').val(day);
390             $('#showMonthOutput').html(month);
391             $('#showMonth').val(month);
392             $('#showYearOutput').html(year);
393             $('#showYear').val(year);
394             $('#showDescription').val(description);
395             $('#showWeekday:first').val(weekDay);
396             $('#showTitle').val(title);
397             $('#showHolidayType').val(holidayType);
398
399             if (holidayType == 'exception') {
400                 $("#showOperationDelLabel").html(_("Delete this exception."));
401                 $("#holtype").attr("class","key exception").html(_("Holiday exception"));
402             } else if(holidayType == 'weekday') {
403                 $("#showOperationDelLabel").html(_("Delete this holiday."));
404                 $("#holtype").attr("class","key repeatableweekly").html(_("Holiday repeating weekly"));
405             } else if(holidayType == 'daymonth') {
406                 $("#showOperationDelLabel").html(_("Delete this holiday."));
407                 $("#holtype").attr("class","key repeatableyearly").html(_("Holiday repeating yearly"));
408             } else {
409                 $("#showOperationDelLabel").html(_("Delete this holiday."));
410                 $("#holtype").attr("class","key holiday").html(_("Unique holiday"));
411             }
412
413             if (exceptionPosibility == 1) {
414                 $("#exceptionPosibility").parent().show();
415             } else {
416                 $("#exceptionPosibility").parent().hide();
417             }
418         }
419
420         // This function shows the "Add Holiday" panel //
421         function newHoliday (dayName, day, month, year, weekDay) {
422             $("#showHoliday").slideUp("fast");
423             $("#newHoliday").slideDown("fast");
424             $("#newDaynameOutput").html(dayName);
425             $("#newDayname").val(dayName);
426             $("#newBranchNameOutput").html($('#branch :selected').text());
427             $("#newBranchName").val($('#branch').val());
428             $("#newDayOutput").html(day);
429             $("#newDay").val(day);
430             $("#newMonthOutput").html(month);
431             $("#newMonth").val(month);
432             $("#newYearOutput").html(year);
433             $("#newYear").val(year);
434             $("#newWeekday:first").val(weekDay);
435         }
436
437         function hidePanel(aPanelName) {
438             $("#"+aPanelName).slideUp("fast");
439         }
440
441         function changeBranch () {
442             var branch = $("#branch option:selected").val();
443             location.href='/cgi-bin/koha/tools/holidays.pl?branch=' + branch + '&calendardate=' + "[% calendardate | html %]";
444         }
445
446         function Help() {
447             newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes');
448         }
449
450         /* This function gives css clases to each kind of day */
451         function dateStatusHandler(date) {
452             date = new Date(date);
453             var day = date.getDate();
454             var month = date.getMonth() + 1;
455             var year = date.getFullYear();
456             var weekDay = date.getDay();
457             var dayMonth = month + '/' + day;
458             var dateString = year + '/' + month + '/' + day;
459             if (exception_holidays[dateString] != null) {
460                 return [true, "exception", _("Exception: %s").format(exception_holidays[dateString].title)];
461             } else if ( week_days[weekDay] != null ){
462                 return [true, "repeatableweekly", _("Weekly holiday: %s").format(week_days[weekDay].title)];
463             } else if ( day_month_holidays[dayMonth] != null ) {
464                 return [true, "repeatableyearly", _("Yearly holiday: %s").format(day_month_holidays[dayMonth].title)];
465             } else if (holidays[dateString] != null) {
466                 return [true, "holiday", _("Single holiday: %s").format(holidays[dateString].title)];
467             } else {
468                 return [true, "normalday", _("Normal day")];
469             }
470         }
471
472         /* This function is in charge of showing the correct panel considering the kind of holiday */
473         function dateChanged(calendar) {
474             calendar = new Date(calendar);
475             var day = calendar.getDate();
476             var month = calendar.getMonth() + 1;
477             var year = calendar.getFullYear();
478             var weekDay = calendar.getDay();
479             var dayName = weekdays[weekDay];
480             var dayMonth = month + '/' + day;
481             var dateString = year + '/' + month + '/' + day;
482                 if (holidays[dateString] != null) {
483                     showHoliday(0, dayName, day, month, year, weekDay, holidays[dateString].title,     holidays[dateString].description, 'ymd');
484                 } else if (exception_holidays[dateString] != null) {
485                     showHoliday(0, dayName, day, month, year, weekDay, exception_holidays[dateString].title, exception_holidays[dateString].description, 'exception');
486                 } else if (week_days[weekDay] != null) {
487                     showHoliday(1, dayName, day, month, year, weekDay, week_days[weekDay].title,     week_days[weekDay].description, 'weekday');
488                 } else if (day_month_holidays[dayMonth] != null) {
489                     showHoliday(1, dayName, day, month, year, weekDay, day_month_holidays[dayMonth].title, day_month_holidays[dayMonth].description, 'daymonth');
490                 } else {
491                     newHoliday(dayName, day, month, year, weekDay);
492                 }
493         };
494
495         $(document).ready(function() {
496
497             $(".hint").hide();
498             $("#branch").change(function(){
499                 changeBranch();
500             });
501             $("#holidayweeklyrepeatable>tbody>tr").each(function(){
502                 var first_td = $(this).find('td').first();
503                 first_td.html(weekdays[first_td.html()]);
504             });
505             $("#holidayweeklyrepeatable").dataTable($.extend(true, {}, dataTablesDefaults, {
506                 "sDom": 't',
507                 "bPaginate": false
508             }));
509             $("#holidayexceptions,#holidaysyearlyrepeatable,#holidaysunique").dataTable($.extend(true, {}, dataTablesDefaults, {
510                 "sDom": 't',
511                 "aoColumns": [
512                     { "sType": "title-string" },null,null
513                 ],
514                 "bPaginate": false
515             }));
516             $("a.helptext").click(function(){
517                 $(this).parent().find(".hint").toggle(); return false;
518             });
519             $("#dateofrange").datepicker({
520               beforeShow: function() {
521                 var startdate = $("#jcalendar-container").datepicker("getDate");
522                 if (startdate !== null) {
523                    var sd = new Date(startdate);
524                    var ed = new Date($(this).datepicker("getDate"));
525                    if (ed < sd) {
526                      $(this).datepicker("setDate", startdate);
527                      $(this).datepicker("option", "defaultDate", startdate);
528                    }
529                 }
530               }
531             });
532             $("#datecancelrange").datepicker();
533             $("#dateofrange").each(function () { this.value = "" });
534             $("#datecancelrange").each(function () { this.value = "" });
535             $("#jcalendar-container").datepicker({
536               beforeShowDay: function(thedate) {
537                 var day = thedate.getDate();
538                 var month = thedate.getMonth() + 1;
539                 var year = thedate.getFullYear();
540                 var dateString = year + '/' + month + '/' + day;
541                 return dateStatusHandler(dateString);
542                 },
543             onSelect: function(dateText, inst) {
544                 dateChanged($(this).datepicker("getDate"));
545                 var enddate = $("#dateofrange").datepicker("getDate");
546                 $("#dateofrange").datepicker("option", "defaultDate", $(this).datepicker("getDate"));
547                 if (enddate !== null) {
548                    var ed = new Date(enddate);
549                    var sd = new Date($(this).datepicker("getDate"));
550                    if (ed < sd) {
551                      $("#dateofrange").datepicker("setDate", $(this).datepicker("getDate"));
552                      $("#dateofrange").datepicker("option", "defaultDate", enddate);
553                    }
554                 }
555             },
556             defaultDate: new Date("[% keydate | html %]")
557             });
558             $(".hidePanel").on("click",function(){
559                 if( $(this).hasClass("showHoliday") ){
560                     hidePanel("showHoliday");
561                 } else {
562                     hidePanel("newHoliday");
563                 }
564             })
565         });
566     </script>
567 [% END %]
568
569 [% INCLUDE 'intranet-bottom.inc' %]