Bug 4985: Edit a calendar entry for all branches
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / holidays.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Branches %]
4 [% SET footerjs = 1 %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Koha &rsaquo; Tools &rsaquo; [% Branches.GetName( branch ) | html %] calendar</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 <style> .key { padding : 3px; white-space:nowrap; line-height:230%; }
9 .ui-datepicker { font-size : 150%; }
10 .ui-datepicker th, .ui-datepicker .ui-datepicker-title select { font-size : 80%; }
11 .ui-datepicker td a { padding : .5em; }
12 .ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current { font-size : 80%; }
13 .key { padding : 3px; white-space:nowrap; line-height:230%; }
14 .normalday { background-color :  #EDEDED; color :  Black; border : 1px solid #BCBCBC; }
15 .exception { background-color :  #b3d4ff; color :  Black; border : 1px solid #BCBCBC; }
16 .holiday {  background-color :  #ffaeae; color :  Black;  border : 1px solid #BCBCBC; }
17 .repeatableweekly {  background-color :  #FFFF99; color :  Black;  border : 1px solid #BCBCBC; }
18 .repeatableyearly {  background-color :  #FFCC66; color :  Black;  border : 1px solid #BCBCBC; }
19 td.exception a.ui-state-default { background:  #b3d4ff none; color :  Black; border : 1px solid #BCBCBC; }
20 td.holiday a.ui-state-default {  background:  #ffaeae none; color :  Black;  border : 1px solid #BCBCBC; }
21 td.repeatableweekly a.ui-state-default {  background:  #FFFF99 none; color :  Black;  border : 1px solid #BCBCBC; }
22 td.repeatableyearly a.ui-state-default {  background:  #FFCC66 none; color :  Black;  border : 1px solid #BCBCBC; }
23 .information { z-index : 1; background-color :  #DCD2F1; width : 300px; display : none; border : 1px solid #000000; color :  #000000; font-size :  8pt; font-weight :  bold; background-color :  #FFD700; cursor :  pointer; padding : 2px; }
24 .panel { z-index : 1; display : none; border : 3px solid #CCC; padding : 3px; margin-top: .3em;  background-color: #FEFEFE; } fieldset.brief { border : 0; margin-top: 0; }
25 #showHoliday { margin : .5em 0; } h1 select { width: 20em; } fieldset.brief ol { font-size:100%; } fieldset.brief li, fieldset.brief li.radio  { padding:0.2em 0; } .help { margin:.3em 0;border:1px solid #EEE;padding:.3em .7em; font-size : 90%; } #holidayweeklyrepeatable, #holidaysyearlyrepeatable, #holidaysunique, #holidayexceptions { font-size : 90%; margin-bottom : 1em;} .calendar td, .calendar th, .calendar .button, .calendar tbody .day { padding : .7em; font-size: 110%; } .calendar { width: auto; border : 0; }
26 </style>
27 </head>
28 <body id="tools_holidays" class="tools">
29 [% INCLUDE 'header.inc' %]
30 [% INCLUDE 'cat-search.inc' %]
31
32 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; [% Branches.GetName( branch ) | html %] calendar</div>
33
34 <div class="main container-fluid">
35     <div class="row">
36         <div class="col-sm-10 col-sm-push-2">
37             <main>
38
39     <h2>[% Branches.GetName( branch ) | html %] calendar</h2>
40
41     <div class="row">
42     <div class="col-sm-6">
43         <label for="branch">Define the holidays for:</label>
44             <select id="branch" name="branch">
45                 [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
46             </select>
47     
48     <!-- ******************************** FLAT PANELS ******************************************* -->
49     <!-- *****           Makes all the flat panel to deal with holidays                     ***** -->
50     <!-- **************************************************************************************** -->
51
52     <!-- ********************** Panel for showing already loaded holidays *********************** -->
53     <div class="panel" id="showHoliday">
54          <form action="/cgi-bin/koha/tools/exceptionHolidays.pl" method="post">
55              <input type="hidden" id="showHolidayType" name="showHolidayType" value="" />
56             <fieldset class="brief">
57             <h3>Edit this holiday</h3>
58             <span id="holtype"></span>
59             <ol>
60             <li>
61                 <strong>Library:</strong> <span id="showBranchNameOutput"></span>
62                 <input type="hidden" id="showBranchName" name="showBranchName" />
63             </li>
64             <li>
65                 <strong>From date:</strong>
66                 <span id="showDaynameOutput"></span>, 
67                 
68                                 [% IF ( dateformat == "us" ) %]<span id="showMonthOutput"></span>/<span id="showDayOutput"></span>/<span id="showYearOutput"></span>[% ELSIF ( dateformat == "metric") %]<span id="showDayOutput"></span>/<span id="showMonthOutput"></span>/<span id="showYearOutput"></span>[% ELSIF ( dateformat == "dmydot") %]<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>[% END %]
69
70                 <input type="hidden" id="showDayname" name="showDayname" />
71                 <input type="hidden" id="showWeekday" name="showWeekday" />
72                 <input type="hidden" id="showDay" name="showDay" />
73                 <input type="hidden" id="showMonth" name="showMonth" />
74                 <input type="hidden" id="showYear" name="showYear" />
75             </li>
76             <li class="dateinsert">
77                 <b>To Date : </b>
78                 <input type="text" id="datecancelrange" name="datecancelrange" size="20" value="[% datecancelrange | html %]" class="datepicker"/>
79             </li>
80             <li><label for="showTitle">Title: </label><input type="text" name="showTitle" id="showTitle" size="35" /></li>
81             <!-- showTitle is necessary for exception radio button to work properly -->
82             <li>
83                 <label for="showDescription">Description:</label>
84                 <textarea rows="2" cols="40" id="showDescription" name="showDescription"></textarea>
85             </li>
86             <li class="radio"><div id="exceptionPosibility" style="position:static">
87                 <input type="radio" name="showOperation" id="showOperationExc" value="exception" /> <label for="showOperationExc">Generate an exception for this repeated holiday.</label>
88                 <a href="#" class="helptext">[?]</a>
89                 <div class="hint">You can make an exception for this holiday rule. This means that you will be able to say that for a repeatable holiday there is one day which is going to be an exception.</div>
90             </div></li>
91             <li class="radio"><input type="radio" name="showOperation" id="showOperationExcRange" value="exceptionrange" />
92                 <label for="showOperationExcRange">Generate exceptions on a range of dates.</label>
93                 <a href="#" class="helptext">[?]</a>
94                 <div class="hint">You can make an exception on a range of dates repeated yearly.</div>
95             </li>
96             <li class="radio"><input type="radio" name="showOperation" id="showOperationDel" value="delete" /> <label for="showOperationDel" id="showOperationDelLabel">Delete this holiday</label>
97                 <a href="#" class="helptext">[?]</a>
98                 <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></li>
99             <li class="radio"><input type="radio" name="showOperation" id="showOperationDelRange" value="deleterange" /> <label for="showOperationDelRange" id="showOperationDelLabelRange">Delete the single holidays on a range</label>.
100                 <a href="#" class="helptext">[?]</a>
101                 <div class="hint">This will delete the single holidays rules only. The repeatable holidays and exceptions will not be deleted.</div>
102             </li>
103             <li class="radio"><input type="radio" name="showOperation" id="showOperationDelRangeRepeat" value="deleterangerepeat" /> <label for="showOperationDelRangeRepeat" id="showOperationDelLabelRangeRepeat">Delete the repeated holidays on a range</label>.
104                 <a href="#" class="helptext">[?]</a>
105                 <div class="hint">This will delete the repeated holidays rules only. The repeatable holidays will be deleted but not the exceptions.</div>
106             </li>
107             <li class="radio"><input type="radio" name="showOperation" id="showOperationDelRangeRepeatExcept" value="deleterangerepeatexcept" /> <label for="showOperationDelRangeRepeatExcept" id="showOperationDelLabelRangeRepeatExcept">Delete the exceptions on a range</label>.
108                 <a href="#" class="helptext">[?]</a>
109                 <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>
110             </li>
111             <li class="radio"><input type="radio" name="showOperation" id="showOperationEdit" value="edit" checked="checked" /> <label for="showOperationEdit">Edit this holiday</label>
112                 <a href="#" class="helptext">[?]</a>
113                 <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>
114             <li class="checkbox">
115                 <input type="checkbox" name="allBranches" id="allBranches" />
116                 <label for="allBranches">Copy changes to all libraries</label>.
117                 <a href="#" class="helptext">[?]</a>
118                 <div class="hint">If checked, changes for this holiday will be copied to all libraries. If the holiday doesn't exists for a library, no change is made.</div>
119             </li>
120             </ol>
121             <fieldset class="action">
122                 <input type="submit" name="submit" value="Save" />
123                 <a href="#" class="cancel hidePanel showHoliday">Cancel</a>
124             </fieldset>
125             </fieldset>
126         </form>
127     </div>
128
129     <!-- ***************************** Panel to deal with new holidays **********************  -->
130     <div class="panel" id="newHoliday">
131          <form action="/cgi-bin/koha/tools/newHolidays.pl" method="post">
132             <fieldset class="brief">
133             <h3>Add new holiday</h3>
134             <ol>
135             <li>
136                 <strong>Library:</strong>
137                 <span id="newBranchNameOutput"></span>
138                 <input type="hidden" id="newBranchName" name="newBranchName" />
139             </li>
140             <li>
141                 <strong>From date:</strong>
142                 <span id="newDaynameOutput"></span>, 
143
144                          [% IF ( dateformat == "us" ) %]<span id="newMonthOutput"></span>/<span id="newDayOutput"></span>/<span id="newYearOutput"></span>[% ELSIF ( dateformat == "metric" ) %]<span id="newDayOutput"></span>/<span id="newMonthOutput"></span>/<span id="newYearOutput"></span>[% ELSIF ( dateformat == "dmydot" ) %]<span id="newDayOutput"></span>.<span id="newMonthOutput"></span>.<span id="newYearOutput"></span>[% ELSE %]<span id="newYearOutput"></span>/<span id="newMonthOutput"></span>/<span id="newDayOutput"></span>[% END %]
145
146                 <input type="hidden" id="newDayname" name="showDayname" />
147                 <input type="hidden" id="newWeekday" name="newWeekday" />
148                 <input type="hidden" id="newDay" name="newDay" />
149                 <input type="hidden" id="newMonth" name="newMonth" />
150                 <input type="hidden" id="newYear" name="newYear" />
151             </li>
152             <li class="dateinsert">
153                 <b>To date: </b>
154                 <input type="text" id="dateofrange" name="dateofrange" size="20" value="[% dateofrange | html %]" class="datepicker" />
155             </li>
156             <li><label for="title">Title: </label><input type="text" name="newTitle" id="title" size="35" /></li>
157             <li><label for="newDescription">Description:</label>
158                 <textarea rows="2" cols="40" id="newDescription" name="newDescription"></textarea>
159             </li>
160             <li class="radio"><input type="radio" name="newOperation" id="newOperationOnce" value="holiday" checked="checked" />
161             <label for="newOperationOnce">Holiday only on this day</label>.
162             <a href="#" class="helptext">[?]</a>
163             <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>
164             </li>
165             <li class="radio"><input type="radio" name="newOperation" id="newOperationDay" value="weekday" />
166                             <label for="newOperationDay">Holiday repeated every same day of the week</label>.
167                             <a href="#" class="helptext">[?]</a>
168                             <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>
169                             </li>
170             <li class="radio"><input type="radio" name="newOperation" id="newOperationYear" value="repeatable" />
171                             <label for="newOperationYear">Holiday repeated yearly on the same date</label>.
172                             <a href="#" class="helptext">[?]</a>
173                             <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>
174                             </li>
175             <li class="radio"><input type="radio" name="newOperation" id="newOperationField" value="holidayrange" />
176                             <label for="newOperationField">Holidays on a range</label>.
177                             <a href="#" class="helptext">[?]</a>
178                             <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>
179                             </li>
180             <li class="radio"><input type="radio" name="newOperation" id="newOperationFieldyear" value="holidayrangerepeat" />
181                             <label for="newOperationFieldyear">Holidays repeated yearly on a range</label>.
182                             <a href="#" class="helptext">[?]</a>
183                             <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>
184                             </li>
185                 <li class="checkbox">
186                 <input type="checkbox" name="allBranches" id="allBranches" />
187                 <label for="allBranches">Copy to all libraries</label>.
188                 <a href="#" class="helptext">[?]</a>
189                 <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>
190                 </li></ol>
191                 <fieldset class="action">
192                     <input type="submit" name="submit" value="Save" />
193                     <a href="#" class="cancel hidePanel newHoliday">Cancel</a>
194                 </fieldset>
195                 </fieldset>
196          </form>
197     </div>
198
199     <!-- *************************************************************************************** -->
200     <!-- ******                          END OF FLAT PANELS                               ****** -->
201     <!-- *************************************************************************************** -->
202
203 <!-- ************************************************************************************** -->
204 <!-- ******                              MAIN SCREEN CODE                            ****** -->
205 <!-- ************************************************************************************** -->
206 <h3>Calendar information</h3>
207 <div id="jcalendar-container"></div>
208
209 <div style="margin-top: 2em;">
210 <form action="copy-holidays.pl" method="post">
211     <input type="hidden" name="from_branchcode" value="[% branch | html %]" />
212   <label for="branchcode">Copy holidays to:</label>
213   <select id="branchcode" name="branchcode">
214     <option value=""></option>
215     [% FOREACH l IN Branches.all() %]
216     <option value="[% l.branchcode | html %]">[% l.branchname | html %]</option>
217     [% END %]
218   </select>
219     <input type="submit" value="Copy" />
220 </form>
221 </div>
222
223 </div>
224 <div class="col-sm-6">
225 <div class="help">
226 <h4>Hints</h4>
227     <ul>
228         <li>Search in the calendar the day you want to set as holiday.</li>
229         <li>Click the date to add or edit a holiday.</li>
230         <li>Enter a title and description for the holiday.</li>
231         <li>Specify how the holiday should repeat.</li>
232         <li>Click Save to finish.</li>
233     </ul>
234 <h4>Key</h4>
235     <p>
236         <span class="key normalday">Working day</span>
237         <span class="key holiday">Unique holiday</span>
238         <span class="key repeatableweekly">Holiday repeating weekly</span>
239         <span class="key repeatableyearly">Holiday repeating yearly</span>
240         <span class="key exception">Holiday exception</span>
241     </p>
242 </div>
243 <div id="holiday-list">
244 <!-- Exceptions First -->
245 <!--   this will probably always have the least amount of data -->
246 [% IF ( EXCEPTION_HOLIDAYS_LOOP ) %]
247 <h3>Exceptions</h3>
248   <table id="holidayexceptions">
249 <thead><tr>
250   <th class="exception">Date</th>
251   <th class="exception">Title</th>
252   <th class="exception">Description</th>
253 </tr>
254 </thead>
255 <tbody>
256   [% FOREACH EXCEPTION_HOLIDAYS_LOO IN EXCEPTION_HOLIDAYS_LOOP %]
257   <tr>
258   <td><a href="/cgi-bin/koha/tools/holidays.pl?branch=[% branch | uri %]&amp;calendardate=[% EXCEPTION_HOLIDAYS_LOO.DATE | uri %]"><span title="[% EXCEPTION_HOLIDAYS_LOO.DATE_SORT | html %]">[% EXCEPTION_HOLIDAYS_LOO.DATE | html %]</span></a></td>
259   <td>[% EXCEPTION_HOLIDAYS_LOO.TITLE | html %]</td>
260   <td>[% EXCEPTION_HOLIDAYS_LOO.DESCRIPTION | html %]</td>
261   </tr>
262   [% END %] 
263 </tbody>
264 </table>
265 [% END %]
266
267 [% IF ( WEEK_DAYS_LOOP ) %]
268 <h3>Weekly - Repeatable holidays</h3>
269 <table id="holidayweeklyrepeatable">
270 <thead>
271 <tr>
272   <th class="repeatableweekly">Day of week</th>
273   <th class="repeatableweekly">Title</th>
274   <th class="repeatableweekly">Description</th>
275 </tr>
276 </thead>
277 <tbody>
278   [% FOREACH WEEK_DAYS_LOO IN WEEK_DAYS_LOOP %]
279   <tr>
280   <td>[% WEEK_DAYS_LOO.KEY | html %]</td>
281   </td> 
282   <td>[% WEEK_DAYS_LOO.TITLE | html %]</td>
283   <td>[% WEEK_DAYS_LOO.DESCRIPTION | html %]</td>
284   </tr>
285   [% END %] 
286 </tbody>
287 </table>
288 [% END %]
289
290 [% IF ( DAY_MONTH_HOLIDAYS_LOOP ) %]
291 <h3>Yearly - Repeatable holidays</h3>
292 <table id="holidaysyearlyrepeatable">
293 <thead>
294 <tr>
295   [% IF ( dateformat == "metric" ) %]
296   <th class="repeatableyearly">Day/month</th>
297   [% ELSE %]
298   <th class="repeatableyearly">Month/day</th>
299   [% END %]
300   <th class="repeatableyearly">Title</th>
301   <th class="repeatableyearly">Description</th>
302 </tr>
303 </thead>
304 <tbody>
305   [% FOREACH DAY_MONTH_HOLIDAYS_LOO IN DAY_MONTH_HOLIDAYS_LOOP %]
306   <tr>
307   <td><span title="[% DAY_MONTH_HOLIDAYS_LOO.DATE_SORT | html %]">[% DAY_MONTH_HOLIDAYS_LOO.DATE | html %]</span></td>
308   <td>[% DAY_MONTH_HOLIDAYS_LOO.TITLE | html %]</td>
309   <td>[% DAY_MONTH_HOLIDAYS_LOO.DESCRIPTION | html %]</td>
310   </tr>
311   [% END %] 
312 </tbody>
313 </table>
314 [% END %]
315
316 [% IF ( HOLIDAYS_LOOP ) %]
317 <h3>Unique holidays</h3>
318 <table id="holidaysunique">
319 <thead>
320 <tr>
321   <th class="holiday">Date</th>
322   <th class="holiday">Title</th>
323   <th class="holiday">Description</th>
324 </tr>
325 </thead>
326 <tbody>
327     [% FOREACH HOLIDAYS_LOO IN HOLIDAYS_LOOP %]
328 <tr>
329   <td><a href="/cgi-bin/koha/tools/holidays.pl?branch=[% branch | uri %]&amp;calendardate=[% HOLIDAYS_LOO.DATE | uri %]"><span title="[% HOLIDAYS_LOO.DATE_SORT | html %]">[% HOLIDAYS_LOO.DATE | html %]</span></a></td>
330   <td>[% HOLIDAYS_LOO.TITLE | html %]</td>
331   <td>[% HOLIDAYS_LOO.DESCRIPTION.replace('\\\r\\\n', '<br />') | html %]</td>
332 </tr>
333   [% END %] 
334 </tbody>
335 </table>
336 [% END %]
337 </div>
338 </div>
339 </div>
340
341             </main>
342         </div> <!-- /.col-sm-10.col-sm-push-2 -->
343
344         <div class="col-sm-2 col-sm-pull-10">
345             <aside>
346                 [% INCLUDE 'tools-menu.inc' %]
347             </aside>
348         </div> <!-- .col-sm-2.col-sm-pull-10 -->
349      </div> <!-- /.row -->
350
351 [% MACRO jsinclude BLOCK %]
352     [% INCLUDE 'calendar.inc' %]
353     [% INCLUDE 'datatables.inc' %]
354     [% Asset.js("js/tools-menu.js") | $raw %]
355     <script>
356         var weekdays = new Array(_("Sundays"),_("Mondays"),_("Tuesdays"),_("Wednesdays"),_("Thursdays"),_("Fridays"),_("Saturdays"));
357
358         /* Creates all the structures to deal with all different kinds of holidays */
359         var week_days = new Array();
360         var holidays = new Array();
361         var holidates = new Array();
362         var exception_holidays = new Array();
363         var day_month_holidays = new Array();
364         var hola= "[% code | html %]";
365         [% FOREACH WEEK_DAYS_LOO IN WEEK_DAYS_LOOP %]
366         week_days["[% WEEK_DAYS_LOO.KEY | html %]"] = {title:"[% WEEK_DAYS_LOO.TITLE | replace('"','\"') | html %]", description:"[% WEEK_DAYS_LOO.DESCRIPTION | replace('"','\"') | html %]"};
367         [% END %]
368         [% FOREACH HOLIDAYS_LOO IN HOLIDAYS_LOOP %]
369         holidates.push("[% HOLIDAYS_LOO.KEY | html %]");
370         holidays["[% HOLIDAYS_LOO.KEY | html %]"] = {title:"[% HOLIDAYS_LOO.TITLE | replace('"','\"') | html %]", description:"[% HOLIDAYS_LOO.DESCRIPTION | replace('"','\"') | html %]"};
371         [% END %]
372         [% FOREACH EXCEPTION_HOLIDAYS_LOO IN EXCEPTION_HOLIDAYS_LOOP %]
373         exception_holidays["[% EXCEPTION_HOLIDAYS_LOO.KEY | html %]"] = {title:"[% EXCEPTION_HOLIDAYS_LOO.TITLE | replace('"','\"') | html %]", description:"[% EXCEPTION_HOLIDAYS_LOO.DESCRIPTION | replace('"','\"') | html %]"};
374         [% END %]
375         [% FOREACH DAY_MONTH_HOLIDAYS_LOO IN DAY_MONTH_HOLIDAYS_LOOP %]
376         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 %]"};
377         [% END %]
378
379         function holidayOperation(formObject, opType) {
380             var op = document.getElementsByName('operation');
381             op[0].value = opType;
382             formObject.submit();
383         }
384
385         // This function shows the "Show Holiday" panel //
386         function showHoliday (exceptionPosibility, dayName, day, month, year, weekDay, title, description, holidayType) {
387             $("#newHoliday").slideUp("fast");
388             $("#showHoliday").slideDown("fast");
389             $('#showDaynameOutput').html(dayName);
390             $('#showDayname').val(dayName);
391             $('#showBranchNameOutput').html($("#branch :selected").text());
392             $('#showBranchName').val($("#branch").val());
393             $('#showDayOutput').html(day);
394             $('#showDay').val(day);
395             $('#showMonthOutput').html(month);
396             $('#showMonth').val(month);
397             $('#showYearOutput').html(year);
398             $('#showYear').val(year);
399             $('#showDescription').val(description);
400             $('#showWeekday:first').val(weekDay);
401             $('#showTitle').val(title);
402             $('#showHolidayType').val(holidayType);
403
404             if (holidayType == 'exception') {
405                 $("#showOperationDelLabel").html(_("Delete this exception."));
406                 $("#holtype").attr("class","key exception").html(_("Holiday exception"));
407             } else if(holidayType == 'weekday') {
408                 $("#showOperationDelLabel").html(_("Delete this holiday."));
409                 $("#holtype").attr("class","key repeatableweekly").html(_("Holiday repeating weekly"));
410             } else if(holidayType == 'daymonth') {
411                 $("#showOperationDelLabel").html(_("Delete this holiday."));
412                 $("#holtype").attr("class","key repeatableyearly").html(_("Holiday repeating yearly"));
413             } else {
414                 $("#showOperationDelLabel").html(_("Delete this holiday."));
415                 $("#holtype").attr("class","key holiday").html(_("Unique holiday"));
416             }
417
418             if (exceptionPosibility == 1) {
419                 $("#exceptionPosibility").parent().show();
420             } else {
421                 $("#exceptionPosibility").parent().hide();
422             }
423         }
424
425         // This function shows the "Add Holiday" panel //
426         function newHoliday (dayName, day, month, year, weekDay) {
427             $("#showHoliday").slideUp("fast");
428             $("#newHoliday").slideDown("fast");
429             $("#newDaynameOutput").html(dayName);
430             $("#newDayname").val(dayName);
431             $("#newBranchNameOutput").html($('#branch :selected').text());
432             $("#newBranchName").val($('#branch').val());
433             $("#newDayOutput").html(day);
434             $("#newDay").val(day);
435             $("#newMonthOutput").html(month);
436             $("#newMonth").val(month);
437             $("#newYearOutput").html(year);
438             $("#newYear").val(year);
439             $("#newWeekday:first").val(weekDay);
440         }
441
442         function hidePanel(aPanelName) {
443             $("#"+aPanelName).slideUp("fast");
444         }
445
446         function changeBranch () {
447             var branch = $("#branch option:selected").val();
448             location.href='/cgi-bin/koha/tools/holidays.pl?branch=' + branch + '&calendardate=' + "[% calendardate | html %]";
449         }
450
451         function Help() {
452             newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes');
453         }
454
455         /* This function gives css clases to each kind of day */
456         function dateStatusHandler(date) {
457             date = new Date(date);
458             var day = date.getDate();
459             var month = date.getMonth() + 1;
460             var year = date.getFullYear();
461             var weekDay = date.getDay();
462             var dayMonth = month + '/' + day;
463             var dateString = year + '/' + month + '/' + day;
464             if (exception_holidays[dateString] != null) {
465                 return [true, "exception", _("Exception: %s").format(exception_holidays[dateString].title)];
466             } else if ( week_days[weekDay] != null ){
467                 return [true, "repeatableweekly", _("Weekly holiday: %s").format(week_days[weekDay].title)];
468             } else if ( day_month_holidays[dayMonth] != null ) {
469                 return [true, "repeatableyearly", _("Yearly holiday: %s").format(day_month_holidays[dayMonth].title)];
470             } else if (holidays[dateString] != null) {
471                 return [true, "holiday", _("Single holiday: %s").format(holidays[dateString].title)];
472             } else {
473                 return [true, "normalday", _("Normal day")];
474             }
475         }
476
477         /* This function is in charge of showing the correct panel considering the kind of holiday */
478         function dateChanged(calendar) {
479             calendar = new Date(calendar);
480             var day = calendar.getDate();
481             var month = calendar.getMonth() + 1;
482             var year = calendar.getFullYear();
483             var weekDay = calendar.getDay();
484             var dayName = weekdays[weekDay];
485             var dayMonth = month + '/' + day;
486             var dateString = year + '/' + month + '/' + day;
487                 if (holidays[dateString] != null) {
488                     showHoliday(0, dayName, day, month, year, weekDay, holidays[dateString].title,     holidays[dateString].description, 'ymd');
489                 } else if (exception_holidays[dateString] != null) {
490                     showHoliday(0, dayName, day, month, year, weekDay, exception_holidays[dateString].title, exception_holidays[dateString].description, 'exception');
491                 } else if (week_days[weekDay] != null) {
492                     showHoliday(1, dayName, day, month, year, weekDay, week_days[weekDay].title,     week_days[weekDay].description, 'weekday');
493                 } else if (day_month_holidays[dayMonth] != null) {
494                     showHoliday(1, dayName, day, month, year, weekDay, day_month_holidays[dayMonth].title, day_month_holidays[dayMonth].description, 'daymonth');
495                 } else {
496                     newHoliday(dayName, day, month, year, weekDay);
497                 }
498         };
499
500         $(document).ready(function() {
501
502             $(".hint").hide();
503             $("#branch").change(function(){
504                 changeBranch();
505             });
506             $("#holidayweeklyrepeatable>tbody>tr").each(function(){
507                 var first_td = $(this).find('td').first();
508                 first_td.html(weekdays[first_td.html()]);
509             });
510             $("#holidayweeklyrepeatable").dataTable($.extend(true, {}, dataTablesDefaults, {
511                 "sDom": 't',
512                 "bPaginate": false
513             }));
514             $("#holidayexceptions,#holidaysyearlyrepeatable,#holidaysunique").dataTable($.extend(true, {}, dataTablesDefaults, {
515                 "sDom": 't',
516                 "aoColumns": [
517                     { "sType": "title-string" },null,null
518                 ],
519                 "bPaginate": false
520             }));
521             $("a.helptext").click(function(){
522                 $(this).parent().find(".hint").toggle(); return false;
523             });
524             $("#dateofrange").datepicker({
525                 beforeShow: function() {
526                     var startdate = $("#jcalendar-container").datepicker("getDate");
527                     if (startdate !== null) {
528                         var sd = new Date(startdate);
529                         var ed = new Date($(this).datepicker("getDate"));
530                         if (ed < sd) {
531                             $(this).datepicker("setDate", startdate);
532                             $(this).datepicker("option", "defaultDate", startdate);
533                         }
534                     }
535                 }
536             });
537             $("#datecancelrange").datepicker();
538             $("#dateofrange").each(function () { this.value = "" });
539             $("#datecancelrange").each(function () { this.value = "" });
540             $("#jcalendar-container").datepicker({
541                 beforeShowDay: function(thedate) {
542                     var day = thedate.getDate();
543                     var month = thedate.getMonth() + 1;
544                     var year = thedate.getFullYear();
545                     var dateString = year + '/' + month + '/' + day;
546                     return dateStatusHandler(dateString);
547                 },
548                 onSelect: function(dateText, inst) {
549                     dateChanged($(this).datepicker("getDate"));
550                     var enddate = $("#dateofrange").datepicker("getDate");
551                     $("#dateofrange").datepicker("option", "defaultDate", $(this).datepicker("getDate"));
552                     $("#dateofrange").datepicker( "option", "minDate", $(this).datepicker("getDate")); //ensure end date can't be before start date
553                     if (enddate !== null) {
554                         var ed = new Date(enddate);
555                         var sd = new Date($(this).datepicker("getDate"));
556                         if (ed < sd) {
557                             $("#dateofrange").datepicker("setDate", $(this).datepicker("getDate"));
558                             $("#dateofrange").datepicker("option", "defaultDate", enddate);
559                         }
560                     }
561                 },
562                 defaultDate: new Date("[% keydate | html %]")
563             });
564             $(".hidePanel").on("click",function(){
565                 if( $(this).hasClass("showHoliday") ){
566                     hidePanel("showHoliday");
567                 } else {
568                     hidePanel("newHoliday");
569                 }
570             })
571         });
572     </script>
573 [% END %]
574
575 [% INCLUDE 'intranet-bottom.inc' %]