Checkout: further validation of due date override
authorDan Scott <dan@coffeecode.net>
Mon, 8 Oct 2012 19:08:47 +0000 (15:08 -0400)
committerDan Scott <dscott@laurentian.ca>
Tue, 9 Oct 2012 02:05:12 +0000 (22:05 -0400)
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.

Signed-off-by: Dan Scott <dan@coffeecode.net>
Open-ILS/xul/staff_client/chrome/content/util/date.js
Open-ILS/xul/staff_client/server/circ/checkout.js

index fb95bee..47c3e21 100644 (file)
@@ -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 );
index 87a2115..08455c3 100644 (file)
@@ -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) {