bugs 3912, 4144: can now add contracts if dataformat is not metric

Fixed bug in date validation that prevented adding new contracts
if the dateformat syspref was set to something other than 'metric'.

In process, also removed three hand-written date validation routines
in favor of using JavaScript Date objects and the Date_from_syspref
function provided in calendar.inc.

This fixes bug 3912, and partially addresses bug 4144.

Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
This commit is contained in:
Galen Charlton 2010-02-10 08:31:45 -05:00
parent 89fab00e99
commit 3d19eb7fef
3 changed files with 10 additions and 100 deletions

View File

@ -52,6 +52,7 @@ $template->param(
booksellerid => $booksellerid,
booksellername => $bookseller[0]->{name},
DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
dateformat => C4::Context->preference("dateformat"),
);
#ADD_FORM: called if $op is 'add_form'. Used to create form to add or modify a record

View File

@ -55,99 +55,6 @@ function isNum(v,maybenull) {
return true;
}
// this function checks if date is like DD/MM/YYYY
function CheckDate(field) {
var d = field.value;
if (d!="") {
var amin = 1900;
var amax = 2100;
var date = d.split("/");
var ok=1;
var msg;
if ( (date.length < 2) && (ok==1) ) {
msg = _("Separator must be /");
alert(msg); ok=0; field.focus();
return false;
}
var dd = date[0];
var mm = date[1];
var yyyy = date[2];
// checking days
if ( ((isNaN(dd))||(dd<1)||(dd>31)) && (ok==1) ) {
msg = _("day not correct.");
alert(msg); ok=0; field.focus();
return false;
}
// checking months
if ( ((isNaN(mm))||(mm<1)||(mm>12)) && (ok==1) ) {
msg = _("month not correct.");
alert(msg); ok=0; field.focus();
return false;
}
// checking years
if ( ((isNaN(yyyy))||(yyyy<amin)||(yyyy>amax)) && (ok==1) ) {
msg = _("years not correct.");
alert(msg); ok=0; field.focus();
return false;
}
// check day/month combination
if ((mm==4 || mm==6 || mm==9 || mm==11) && dd==31) {
msg = _("Invalid Day/Month combination. Please ensure that you have a valid day/month combination.");
alert(msg); ok=0; field.focus();
return false;
}
// check for february 29th
if (mm == 2) {
var isleap = (yyyy % 4 == 0 && (yyyy % 100 != 0 || yyyy % 400 == 0));
if (dd>29 || (dd==29 && !isleap)) {
msg = _("Invalid Day. This year is not a leap year. Please enter a value less than 29 for the day.");
alert(msg); ok=0; field.focus();
return false
}
}
}
return true;
}
// Checks wether start date is greater than end date
function CompareDate(startdate, enddate) {
startdate=startdate.split("/");
syear = startdate[2];
smonth = startdate[1];
sday = startdate[0];
enddate=enddate.split("/");
eyear = enddate[2];
emonth = enddate[1];
eday = enddate[0];
var sdate = new Date(syear,smonth-1,sday);
var edate = new Date(eyear,emonth-1,eday);
if (sdate > edate) {
msg = _("Start date after end date, please check the dates!");
alert(msg); ok=0; field.focus();
return false;
}
return true;
}
// checks wether end date is before today, returns false if it is
function CheckEndDate(enddate) {
enddate=enddate.split("/");
eyear = enddate[2];
emonth = enddate[1];
eday = enddate[0];
var edate = new Date(eyear,emonth-1,eday);
var today = new Date( );
if (today > edate) {
msg = _("End date before today, Invalid end date!");
alert(msg); ok=0; field.focus();
return false;
}
return true;
}
//=======================================================================
//=======================================================================

View File

@ -21,20 +21,22 @@ function Check(ff) {
ok=1;
_alertString += _("- Name missing\n");
}
if (!(CheckDate(ff.contractstartdate))){
var startDate = Date_from_syspref($("#contractstartdate").val());
var endDate = Date_from_syspref($("#contractenddate").val());
if (!parseInt(startDate.getTime())) {
ok=1;
_alertString += _("- Start date missing\n");
_alertString += _("- Start date missing or invalid.\n");
}
if (!(CheckDate(ff.contractenddate))){
if (!parseInt(endDate.getTime())) {
ok=1;
_alertString += _("- End date missing\n");
_alertString += _("- End date missing or invalid.\n");
}
if (!CompareDate(ff.contractstartdate.value, ff.contractenddate.value)) {
if (startDate > endDate) {
ok=1;
_alertString += _("Wrong date! start date can not be after end date.\n");
_alertString += _("Wrong date! start date cannot be after end date.\n");
}
if (! CheckEndDate(ff.contractenddate.value)) {
if (endDate < (new Date)) {
ok=1;
_alertString += _("End date before today, Invalid end date!\n");
}