lp1712644 Prevent check out due date in past
authorKatlyn Beck <kbeck@catalyte.io>
Mon, 26 Nov 2018 21:23:48 +0000 (21:23 +0000)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 27 Dec 2019 20:49:31 +0000 (15:49 -0500)
- Prevents selecting past due date when checking out an item
- Prevents saving a due date with hatch when input date is invalid

Signed-off-by: Katlyn Beck <kbeck@catalyte.io>
Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/circ/patron/t_checkout.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js
Open-ILS/web/js/ui/default/staff/services/ui.js

index 65d56fb..7cbe492 100644 (file)
@@ -30,7 +30,8 @@
           id="patron-checkout-barcode" type="text"/> 
 
         <input class="btn btn-default" type="submit" 
-          ng-class="{disabled : disable_checkout()}" value="[% l('Submit') %]"/>
+          ng-disabled="disable_checkout()"
+          value="[% l('Submit') %]"/>
 
       </div>
     </form>
@@ -76,7 +77,9 @@
         </label>
       </div> -->
       <div class="col-md-12 col-lg-6">
-        <eg-date-input ng-model="checkoutArgs.due_date" ng-disabled="!date_options.has_sticky_date" show-time-picker></eg-date-input>
+        <eg-date-input min-date="minDate" out-of-range="outOfRange"
+          ng-model="checkoutArgs.due_date" ng-disabled="!date_options.has_sticky_date" show-time-picker>
+        </eg-date-input>
       </div>
 </div>
     </div>
index d79811c..3d1b60e 100644 (file)
@@ -19,6 +19,8 @@ function($scope , $q , $routeParams , egCore , egUser , patronSvc ,
         due_date : new Date()
     };
 
+    $scope.minDate = new Date();
+    $scope.outOfRange = false;
     $scope.gridDataProvider = egGridDataProvider.instance({
         get : function(offset, count) {
             return this.arrayNotifier($scope.checkouts, offset, count);
@@ -31,7 +33,8 @@ function($scope , $q , $routeParams , egCore , egUser , patronSvc ,
             patronSvc.current.active() == 'f' ||
             patronSvc.current.deleted() == 't' ||
             patronSvc.current.card().active() == 'f' ||
-            patronSvc.fetchedWithInactiveCard()
+            patronSvc.fetchedWithInactiveCard() ||
+            $scope.outOfRange == true
         );
     }
 
@@ -87,8 +90,12 @@ function($scope , $q , $routeParams , egCore , egUser , patronSvc ,
     });
 
     $scope.$watch('checkoutArgs.due_date', function(newval) {
-        if ( $scope.date_options.is_until_logout ) {
-            egCore.hatch.setSessionItem('eg.circ.checkout.due_date', newval);
+        if ( $scope.date_options.is_until_logout && !isNaN(newval)) {
+            if (!$scope.outOfRange) {
+                egCore.hatch.setSessionItem('eg.circ.checkout.due_date', newval);
+            } else {
+                egCore.hatch.setSessionItem('eg.circ.checkout.due_date', $scope.checkoutArgs.due_date);
+            }
         }
     });
 
index 0fe9918..f8f7cd1 100644 (file)
@@ -1356,13 +1356,12 @@ https://stackoverflow.com/questions/24764802/angular-js-automatically-focus-inpu
 
                 if ($scope.outOfRange !== undefined && (maxDateObj || minDateObj)) {
                     $scope.$watch('ngModel', function (n,o) {
-                        if (n && n != o) {
-                            var bad = false;
-                            var newdate = new Date(n);
-                            if (maxDateObj && newdate.getTime() > maxDateObj.getTime()) bad = true;
-                            if (minDateObj && newdate.getTime() < minDateObj.getTime()) bad = true;
-                            $scope.outOfRange = bad;
-                        }
+                        var bad = false;
+                        var newdate = new Date(n);
+                        if (isNaN(newdate.getTime())) bad = true;
+                        if (maxDateObj && newdate.getTime() > maxDateObj.getTime()) bad = true;
+                        if (minDateObj && newdate.getTime() < minDateObj.getTime()) bad = true;
+                        $scope.outOfRange = bad;
                     });
                 }
             }],