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