From 3d19eb7fef079a71d3d92cbb696d8e94fb8e4ee4 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 10 Feb 2010 08:31:45 -0500 Subject: [PATCH] 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 --- admin/aqcontract.pl | 1 + koha-tmpl/intranet-tmpl/prog/en/js/acq.js | 93 ------------------- .../prog/en/modules/admin/aqcontract.tmpl | 16 ++-- 3 files changed, 10 insertions(+), 100 deletions(-) diff --git a/admin/aqcontract.pl b/admin/aqcontract.pl index f1cc17be0c..81cc640a00 100755 --- a/admin/aqcontract.pl +++ b/admin/aqcontract.pl @@ -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 diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js index 3acab0ce7c..0ec1460567 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js @@ -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))||(yyyyamax)) && (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; -} - - - //======================================================================= //======================================================================= diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl index 62dfae9091..b54d9cf9e9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqcontract.tmpl @@ -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"); } -- 2.20.1