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