Bug 14544: QA fixes - some minor bug fixes
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / includes / calendar.inc
1 [% USE Koha %]
2 <script type="text/javascript">
3     //<![CDATA[
4         var debug    = "[% debug %]";
5         var dformat  = "[% dateformat %]";
6         var sentmsg = 0;
7         if (debug > 1) {alert("dateformat: " + dformat + "\ndebug is on (level " + debug + ")");}
8
9         function Date_from_syspref(dstring) {
10                 var dateX = dstring.split(/[-/]/);
11                 if (debug > 1 && sentmsg < 1) {sentmsg++; alert("Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n"));}
12                 if (dformat === "iso") {
13                         return new Date(dateX[0], (dateX[1] - 1), dateX[2]);  // YYYY-MM-DD to (YYYY,m(0-11),d)
14                 } else if (dformat === "us") {
15                         return new Date(dateX[2], (dateX[0] - 1), dateX[1]);  // MM/DD/YYYY to (YYYY,m(0-11),d)
16                 } else if (dformat === "metric") {
17                         return new Date(dateX[2], (dateX[1] - 1), dateX[0]);  // DD/MM/YYYY to (YYYY,m(0-11),d)
18                 } else {
19                         if (debug > 0) {alert("KOHA ERROR - Unrecognized date format: " +dformat);}
20                         return 0;
21                 }
22         }
23
24         /* Instead of including multiple localization files as you would normally see with
25            jQueryUI we expose the localization strings in the default configuration */
26         jQuery(function($){
27             $.datepicker.regional[''] = {
28                 closeText: _("Done"),
29                 prevText: _("Prev"),
30                 nextText: _("Next"),
31                 currentText: _("Today"),
32                 monthNames: [_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),
33                 _("July"),_("August"),_("September"),_("October"),_("November"),_("December")],
34                 monthNamesShort: [_("Jan"), _("Feb"), _("Mar"), _("Apr"), _("May"), _("Jun"),
35                 _("Jul"), _("Aug"), _("Sep"), _("Oct"), _("Nov"), _("Dec")],
36                 dayNames: [_("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday")],
37                 dayNamesShort: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")],
38                 dayNamesMin: [_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa")],
39                 weekHeader: _("Wk"),
40                 dateFormat: '[% IF ( dateformat == "us" ) %]mm/dd/yy[% ELSIF ( dateformat == "metric" ) %]dd/mm/yy[% ELSE %]yy-mm-dd[% END %]',
41                 firstDay: [% Koha.Preference('CalendarFirstDayOfWeek') %],
42                 isRTL: [% IF ( bidi ) %]true[% ELSE %]false[% END %],
43                 showMonthAfterYear: false,
44                 yearSuffix: ''};
45             $.datepicker.setDefaults($.datepicker.regional['']);
46         });
47
48         $(document).ready(function(){
49
50         $.datepicker.setDefaults({
51                 showOn: "both",
52                 changeMonth: true,
53                 changeYear: true,
54                 buttonImage: '[% interface %]/lib/famfamfam/silk/calendar.png',
55                 buttonImageOnly: true,
56                 showButtonPanel: true,
57                 showOtherMonths: true
58             });
59
60             $( ".datepicker" ).datepicker();
61             // http://jqueryui.com/demos/datepicker/#date-range
62             var dates = $( ".datepickerfrom, .datepickerto" ).datepicker({
63                 changeMonth: true,
64                 numberOfMonths: 1,
65                 onSelect: function( selectedDate ) {
66                     var option = this.id == "from" ? "minDate" : "maxDate",
67                         instance = $( this ).data( "datepicker" );
68                         date = $.datepicker.parseDate(
69                             instance.settings.dateFormat ||
70                             $.datepicker._defaults.dateFormat,
71                             selectedDate, instance.settings );
72                     dates.not( this ).datepicker( "option", option, date );
73                 }
74             });
75         });
76     //]]>
77 </script>