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