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