From: Dan Scott Date: Mon, 8 Oct 2012 19:08:47 +0000 (-0400) Subject: Checkout: further validation of due date override X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1cb6a1ebb36d44985feca77d10c1848b838bd275;p=evergreen%2Fpines.git Checkout: further validation of due date override The check_past() function failed if given a date that was not strictly in YYYY-mm-dd format; interestingly, a common transposition typo such as "0212-10-20" results in "212-10-20" getting passed to check_past(), and therefore generating an invalid date. Throw an exception in check_past() rather than returning true, because we are not in fact stating that the due date is in the past - and catch the exception and flag the due date override box accordingly in the checkout screen. We could bubble the exception up to the user, but hopefully highlighting the checkout box as being in an invalid state will catch the attention of the users. [LFW: Slightly amended a comment in OpenILS/WWW/EGCatLoader/Util.pm] Signed-off-by: Dan Scott Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index 04360af1dd..470e381118 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -184,7 +184,7 @@ sub init_ro_object_cache { my $date = shift; # Probably an accidental entry like '0212' instead of '2012', - # but 1) the leading 0 gets stripped in CStoreEditor and + # but 1) the leading 0 may get stripped in cstore and # 2) DateTime::Format::ISO8601 returns an error as years # must be 2 or 4 digits if ($date =~ m/^\d{3}-/) { diff --git a/Open-ILS/xul/staff_client/chrome/content/util/date.js b/Open-ILS/xul/staff_client/chrome/content/util/date.js index fb95bee5a9..47c3e2152f 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/date.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/date.js @@ -24,8 +24,16 @@ util.date.check = function(format,date) { util.date.check_past = function(format,date) { if (format != 'YYYY-MM-DD') { throw('I only understand YYYY-MM-DD. Fix me if you want.'); } - var yyyy = date.substr(0,4); var mm = date.substr(5,2); var dd = date.substr(8,2); + var yyyy = date.substr(0,4); + var mm = date.substr(5,2); + var dd = date.substr(8,2); var test_date = new Date( yyyy, mm - 1, dd ); + + /* Ensure our date is valid */ + if (isNaN(test_date.getTime())) { + throw('The date "' + date + '" is not valid.'); + } + date = util.date.formatted_date(new Date(),'%F'); yyyy = date.substr(0,4); mm = date.substr(5,2); dd = date.substr(8,2); var today = new Date( yyyy, mm - 1, dd ); diff --git a/Open-ILS/xul/staff_client/server/circ/checkout.js b/Open-ILS/xul/staff_client/server/circ/checkout.js index 87a21153ea..08455c3ac4 100644 --- a/Open-ILS/xul/staff_client/server/circ/checkout.js +++ b/Open-ILS/xul/staff_client/server/circ/checkout.js @@ -120,7 +120,7 @@ circ.checkout.prototype = { ['change'], function(ev) { try { - document.getElementById('checkout_duedate_checkbox').checked = true; + document.getElementById('checkout_duedate_checkbox').checked = true; if (obj.check_date(ev.target)) { ev.target.parentNode.setAttribute('style',''); } else { @@ -348,10 +348,17 @@ circ.checkout.prototype = { obj.controller.view.checkout_barcode_entry_textbox.disabled = false; obj.controller.view.cmd_checkout_submit.setAttribute('disabled','false'); obj.controller.view.cmd_checkout_submit.disabled = false; - if (util.date.check_past('YYYY-MM-DD',node.value) ) { - obj.controller.view.checkout_barcode_entry_textbox.setAttribute('disabled','true'); - obj.controller.view.cmd_checkout_submit.setAttribute('disabled','true'); - return false; + try { + if (util.date.check_past('YYYY-MM-DD',node.value) ) { + obj.controller.view.checkout_barcode_entry_textbox.setAttribute('disabled','true'); + obj.controller.view.cmd_checkout_submit.setAttribute('disabled','true'); + return false; + } + } + catch (E) { + obj.controller.view.checkout_barcode_entry_textbox.setAttribute('disabled','true'); + obj.controller.view.cmd_checkout_submit.setAttribute('disabled','true'); + return false; } return true; } catch(E) {