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