[open-ils-commits] [GIT] Evergreen ILS branch master updated. 5dadc54f88e5ef3771664bded5312fb5d9131c4f

Evergreen Git git at git.evergreen-ils.org
Mon Oct 21 09:39:02 EDT 2019


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  5dadc54f88e5ef3771664bded5312fb5d9131c4f (commit)
      from  332588c6c8ef7e19d45ad8036d23303272db5c74 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5dadc54f88e5ef3771664bded5312fb5d9131c4f
Author: Suzanne Paterno <paterno at noblenet.org>
Date:   Tue Aug 6 10:25:05 2019 -0400

    LP 985957 Prevent hold activation date being in the past
    
    Created a new JS function isValidDate. Checks that the date is in the future, is a valid date within the month/year given. Also makes sure the date is in the proper format D/m/Y.
    
    Signed-off-by: Jason Etheridge <jason at EquinoxInitiative.org>

diff --git a/Open-ILS/src/templates/opac/i18n_strings.tt2 b/Open-ILS/src/templates/opac/i18n_strings.tt2
index 1617e29684..7d3b831d64 100644
--- a/Open-ILS/src/templates/opac/i18n_strings.tt2
+++ b/Open-ILS/src/templates/opac/i18n_strings.tt2
@@ -18,6 +18,7 @@ to js source files, via js blob.
     var eg_opac_i18n = {};
 
     eg_opac_i18n.EG_MISSING_REQUIRED_INPUT = "[% l('Please fill out all required fields') %]";
+    eg_opac_i18n.EG_INVALID_DATE = "[% l('That is not a valid date in the future.') %]";
     // For multiple holds placement confirmation dialog. {0} is replaced by number of copies requested.
     eg_opac_i18n.EG_MULTIHOLD_MESSAGE = "[% l('Do you really want to place {0} holds for this title?') %]";
 </script>
diff --git a/Open-ILS/web/js/ui/default/opac/holds-validation.js b/Open-ILS/web/js/ui/default/opac/holds-validation.js
index 688d5dad93..c4f21cbdd4 100644
--- a/Open-ILS/web/js/ui/default/opac/holds-validation.js
+++ b/Open-ILS/web/js/ui/default/opac/holds-validation.js
@@ -13,10 +13,10 @@ function resetBackgrounds(names){
 function validateMethodSelections (alertMethodCboxes) {
     var needsPhone = false;
     var hasPhone = false;
-    
+
     var needsEmail = false;
     var hasEmail = false;
-    
+
     var needsSms = false;
     var hasSms = false;
     var inputNames = { e: "email_address", ph: "phone_notify", sms: "sms_notify", carrier: "sms_carrier"};
@@ -43,19 +43,19 @@ function validateMethodSelections (alertMethodCboxes) {
             }
         }
     }
-    
+
     var culprits = [];
     var emailOK = (needsEmail && hasEmail) || (!needsEmail);
     var phoneOK = needsPhone && hasPhone || (!needsPhone);
     var smsOK = needsSms && hasSms || (!needsSms);
-    
+
     if (!phoneOK) {
         culprits.push("phone_notify");
     }
     if (!smsOK) {
         culprits.push("sms_notify", "sms_carrier");
     }
-    
+
     var isFormOK = emailOK && phoneOK && smsOK;
     return { isValid: isFormOK, culpritNames : culprits };
 }
@@ -72,8 +72,56 @@ function confirmMultipleHolds() {
     return result;
 }
 
+function isValidDate(dateString){
+    // First check for the pattern
+    if(!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(dateString))
+        return false;
+
+    // Parse the date parts to integers
+    var parts = dateString.split("/");
+    var day = parseInt(parts[1], 10);
+    var month = parseInt(parts[0], 10);
+    var year = parseInt(parts[2], 10);
+
+    var today = new Date();
+
+    if (today.getFullYear() > year){
+      return false;
+    }
+    else if (today.getFullYear() == year ) {
+      if(today.getMonth() +1 > month) {
+         return false;
+      }
+      else if (today.getMonth() +1 == month) {
+         if (today.getDate() > day) return false;
+      }
+   }
+
+    // Check the ranges of month and year
+    if(year < 2000 || year > 3000 || month == 0 || month > 12) return false;
+
+    var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
+
+    // Adjust for leap years
+    if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))  monthLength[1] = 29;
+
+    // Check the range of the day
+    return day > 0 && day <= monthLength[month - 1];
+}
+
 function validateHoldForm() {
     var res = validateMethodSelections(document.getElementsByClassName("hold-alert-method"));
+
+    if (document.getElementById('hold_suspend').checked && document.getElementById('thaw_date').value.length > 0){
+       //check that the date is not in the past
+       if(!isValidDate(document.getElementById('thaw_date').value)) {
+          alert(eg_opac_i18n.EG_INVALID_DATE);
+          document.getElementById('thaw_date').style.backgroundColor  = "yellow";
+          return false;
+       }
+    }
+
+
     if (res.isValid) {
         var result = confirmMultipleHolds();
         if (result) {

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/src/templates/opac/i18n_strings.tt2       |  1 +
 .../web/js/ui/default/opac/holds-validation.js     | 58 ++++++++++++++++++++--
 2 files changed, 54 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list