Lines 1-212
Link Here
|
|
|
1 |
[% USE Asset %] |
1 |
[% USE Koha %] |
2 |
[% USE Koha %] |
|
|
3 |
[% USE raw %] |
2 |
<!-- calendar.inc --> |
4 |
<!-- calendar.inc --> |
3 |
<script> |
5 |
<script> |
4 |
|
6 |
var debug = "[% debug | html %]"; |
5 |
var debug = "[% debug | html %]"; |
7 |
var dateformat_pref = "[% Koha.Preference('dateformat ') | html %]"; |
6 |
var dformat = "[% dateformat | html %]"; |
8 |
var dateformat_string = [% IF ( dateformat == "us" ) %]"mm/dd/yy"[% ELSIF ( dateformat == "metric" ) %]"dd/mm/yy"[% ELSIF ( dateformat == "dmydot" ) %]"dd.mm.yy"[% ELSE %]"yy-mm-dd"[% END %]; |
7 |
var sentmsg = 0; |
9 |
var sentmsg = 0; |
8 |
if (debug > 1) {alert("dateformat: " + dformat + "\ndebug is on (level " + debug + ")");} |
10 |
var bidi = [% IF(bidi) %] true[% ELSE %] false[% END %]; |
9 |
var MSG_PLEASE_ENTER_A_VALID_DATE = (_("Please enter a valid date (should match %s).")); |
11 |
var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]'; |
10 |
|
|
|
11 |
function is_valid_date(date) { |
12 |
// An empty string is considered as a valid date for convenient reasons. |
13 |
if ( date === '' ) return 1; |
14 |
|
15 |
var dateformat = dateformat_str = '[% Koha.Preference('dateformat') | html %]'; |
16 |
if ( dateformat == 'us' ) { |
17 |
if ( date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1 ) return 0; |
18 |
dateformat = 'mm/dd/yy'; |
19 |
} else if ( dateformat == 'metric' ) { |
20 |
if ( date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1 ) return 0; |
21 |
dateformat = 'dd/mm/yy'; |
22 |
} else if (dateformat == 'iso' ) { |
23 |
if ( date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1 ) return 0; |
24 |
dateformat = 'yy-mm-dd'; |
25 |
} else if ( dateformat == 'dmydot' ) { |
26 |
if ( date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1 ) return 0; |
27 |
dateformat = 'dd.mm.yy'; |
28 |
} |
29 |
try { |
30 |
$.datepicker.parseDate(dateformat, date); |
31 |
} catch (e) { |
32 |
return 0; |
33 |
}; |
34 |
return 1; |
35 |
} |
36 |
|
37 |
function get_dateformat_str(dateformat) { |
38 |
var dateformat_str; |
39 |
if ( dateformat == 'us' ) { |
40 |
dateformat_str = 'mm/dd/yyyy'; |
41 |
} else if ( dateformat == 'metric' ) { |
42 |
dateformat_str = 'dd/mm/yyyy'; |
43 |
} else if (dateformat == 'iso' ) { |
44 |
dateformat_str = 'yyyy-mm-dd'; |
45 |
} else if ( dateformat == 'dmydot' ) { |
46 |
dateformat_str = 'dd.mm.yyyy'; |
47 |
} |
48 |
return dateformat_str; |
49 |
} |
50 |
|
51 |
function validate_date (dateText, inst) { |
52 |
if ( !is_valid_date(dateText) ) { |
53 |
var dateformat_str = get_dateformat_str( '[% Koha.Preference('dateformat') | html %]' ); |
54 |
alert(MSG_PLEASE_ENTER_A_VALID_DATE.format(dateformat_str)); |
55 |
$('#'+inst.id).val(''); |
56 |
} |
57 |
} |
58 |
|
59 |
function Date_from_syspref(dstring) { |
60 |
var dateX = dstring.split(/[-/.]/); |
61 |
if (debug > 1 && sentmsg < 1) {sentmsg++; alert("Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n"));} |
62 |
if (dformat === "iso") { |
63 |
return new Date(dateX[0], (dateX[1] - 1), dateX[2]); // YYYY-MM-DD to (YYYY,m(0-11),d) |
64 |
} else if (dformat === "us") { |
65 |
return new Date(dateX[2], (dateX[0] - 1), dateX[1]); // MM/DD/YYYY to (YYYY,m(0-11),d) |
66 |
} else if (dformat === "metric") { |
67 |
return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD/MM/YYYY to (YYYY,m(0-11),d) |
68 |
} else if (dformat === "dmydot") { |
69 |
return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD.MM.YYYY to (YYYY,m(0-11),d) |
70 |
} else { |
71 |
if (debug > 0) {alert("KOHA ERROR - Unrecognized date format: " +dformat);} |
72 |
return 0; |
73 |
} |
74 |
} |
75 |
|
76 |
function DateTime_from_syspref(date_time) { |
77 |
var parts = date_time.split(" "); |
78 |
var date = parts[0]; |
79 |
var time = parts[1]; |
80 |
parts = time.split(":"); |
81 |
var hour = parts[0]; |
82 |
var minute = parts[1]; |
83 |
|
84 |
if ( hour < 0 || hour > 23 ) { |
85 |
return 0; |
86 |
} |
87 |
if ( minute < 0 || minute > 59 ) { |
88 |
return 0; |
89 |
} |
90 |
|
91 |
var datetime = Date_from_syspref( date ); |
92 |
|
93 |
if ( isNaN( datetime.getTime() ) ) { |
94 |
return 0; |
95 |
} |
96 |
|
97 |
datetime.setHours( hour ); |
98 |
datetime.setMinutes( minute ); |
99 |
|
100 |
return datetime; |
101 |
} |
102 |
|
103 |
|
104 |
/* Instead of including multiple localization files as you would normally see with |
105 |
jQueryUI we expose the localization strings in the default configuration */ |
106 |
jQuery(function($){ |
107 |
$.datepicker.regional[''] = { |
108 |
closeText: _("Done"), |
109 |
prevText: _("Prev"), |
110 |
nextText: _("Next"), |
111 |
currentText: _("Today"), |
112 |
monthNames: [_("January"),_("February"),_("March"),_("April"),_("May"),_("June"), |
113 |
_("July"),_("August"),_("September"),_("October"),_("November"),_("December")], |
114 |
monthNamesShort: [_("Jan"), _("Feb"), _("Mar"), _("Apr"), _("May"), _("Jun"), |
115 |
_("Jul"), _("Aug"), _("Sep"), _("Oct"), _("Nov"), _("Dec")], |
116 |
dayNames: [_("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday")], |
117 |
dayNamesShort: [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat")], |
118 |
dayNamesMin: [_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa")], |
119 |
weekHeader: _("Wk"), |
120 |
dateFormat: "[% IF ( dateformat == "us" ) %]mm/dd/yy[% ELSIF ( dateformat == "metric" ) %]dd/mm/yy[% ELSIF ( dateformat == "dmydot" ) %]dd.mm.yy[% ELSE %]yy-mm-dd[% END %]", |
121 |
firstDay: '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]', |
122 |
isRTL: [% IF ( bidi ) %]true[% ELSE %]false[% END %], |
123 |
showMonthAfterYear: false, |
124 |
yearSuffix: ''}; |
125 |
$.datepicker.setDefaults($.datepicker.regional['']); |
126 |
}); |
127 |
|
128 |
/* jQuery Validator plugin custom method |
129 |
This allows you to check that a given date falls after another. |
130 |
It is required that a message be defined. |
131 |
|
132 |
Syntax: |
133 |
$("#form_id").validate({ |
134 |
rules: { |
135 |
input_name_of_later_date_field: { |
136 |
is_date_after: "#input_id_of_earlier_date_field" |
137 |
}, |
138 |
}, |
139 |
messages: { |
140 |
input_name_of_later_date_field: { |
141 |
is_date_after: _("Validation error to be shown, i.e. End date must come after start date") |
142 |
} |
143 |
} |
144 |
}); |
145 |
*/ |
146 |
|
147 |
jQuery.validator.addMethod("is_date_after", |
148 |
function(value, element, params) { |
149 |
var from = Date_from_syspref( $(params).val() ); |
150 |
var to = Date_from_syspref(value); |
151 |
return to > from; |
152 |
}); |
153 |
|
154 |
jQuery.validator.addMethod("date_on_or_after", |
155 |
function(value, element, params) { |
156 |
var from = Date_from_syspref( $(params).val() ); |
157 |
var to = Date_from_syspref(value); |
158 |
return to >= from; |
159 |
}); |
160 |
|
161 |
$(document).ready(function(){ |
162 |
|
163 |
$.datepicker.setDefaults({ |
164 |
showOn: "both", |
165 |
buttonImage: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAT0lEQVQ4jWNgoAZYd/LVf3IwigGkAuwGLE4hDg9eA4il8RqADVdtLYVjZLVEuwDZAKJcgKxh+zkyXIBuI8lhgG4jOqZdLJACMAygKDNRAgBj9qOB+rWnhAAAAABJRU5ErkJggg==", |
166 |
buttonImageOnly: true, |
167 |
buttonText: _("Select date"), |
168 |
changeMonth: true, |
169 |
changeYear: true, |
170 |
showButtonPanel: true, |
171 |
showOtherMonths: true, |
172 |
selectOtherMonths: true, |
173 |
yearRange: "c-100:c+10" |
174 |
}); |
175 |
|
176 |
$("#dateofbirth").datepicker({ |
177 |
yearRange: "c-100:c" |
178 |
}); |
179 |
|
180 |
$(".futuredate").datepicker({ |
181 |
minDate: 1, // require that hold suspended until date is after today |
182 |
}); |
183 |
|
184 |
$( ".datepicker" ).datepicker({ |
185 |
onClose: function(dateText, inst) { |
186 |
validate_date(dateText, inst); |
187 |
}, |
188 |
}).on("change", function(e, value) { |
189 |
if ( ! is_valid_date( $(this).val() ) ) {$(this).val("");} |
190 |
}); |
191 |
// http://jqueryui.com/demos/datepicker/#date-range |
192 |
var dates = $( ".datepickerfrom, .datepickerto" ).datepicker({ |
193 |
changeMonth: true, |
194 |
numberOfMonths: 1, |
195 |
onSelect: function( selectedDate ) { |
196 |
var option = this.id == "from" ? "minDate" : "maxDate", |
197 |
instance = $( this ).data( "datepicker" ); |
198 |
date = $.datepicker.parseDate( |
199 |
instance.settings.dateFormat || |
200 |
$.datepicker._defaults.dateFormat, |
201 |
selectedDate, instance.settings ); |
202 |
dates.not( this ).datepicker( "option", option, date ); |
203 |
}, |
204 |
onClose: function(dateText, inst) { |
205 |
validate_date(dateText, inst); |
206 |
}, |
207 |
}).on("change", function(e, value) { |
208 |
if ( ! is_valid_date( $(this).val() ) ) {$(this).val("");} |
209 |
}); |
210 |
}); |
211 |
</script> |
12 |
</script> |
212 |
<!-- / calendar.inc --> |
13 |
<!-- / calendar.inc --> |
|
|
14 |
[% Asset.js("js/calendar.js") | $raw %] |