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