offline: enhance egDateInput range validation for checkout and renew, and provide...
authorMike Rylander <mrylander@gmail.com>
Fri, 23 Jun 2017 13:32:28 +0000 (09:32 -0400)
committerMike Rylander <mrylander@gmail.com>
Fri, 23 Jun 2017 13:32:28 +0000 (09:32 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/staff/offline-interface.tt2
Open-ILS/src/templates/staff/share/t_datetime.tt2
Open-ILS/web/js/ui/default/staff/offline.js
Open-ILS/web/js/ui/default/staff/services/ui.js

index 5f44eac..0cc81fd 100644 (file)
 <div class="row col-md-offset-3 col-md-6 pad-vert">
   <div ng-show="logged_in && active_tab != 'session'" class="alert alert-danger">
     <h2>[% l('Warning') %]</h2>
-    [% l('You are currently logged in while attempting to use the offline interface.  If use of this interface is intended, or if you were redirected here due to an internet or server outage, please use the Log Out action in the above-right menu and then select Offline Circulation from the Circulation menu') %]
+    [% l('You are about to enter offline mode. If you proceed, you will be logged out.') %]
+    <br/>
+    <br/>
+    <button class="btn btn-danger" ng-click="logout()">[% l('Proceed') %]</button>
   </div>
 </div>
 
@@ -76,7 +79,7 @@
                 [% l('Due Date:') %]
               </div>
               <div class="col-md-4">
-                <eg-date-input id="co_duedate" ng-model="shared.due_date" min-date="minDate"></eg-date-input>
+                <eg-date-input id="co_duedate" ng-model="shared.due_date" out-of-range="shared.outOfRange" min-date="minDate"></eg-date-input>
               </div>
               <div class="col-md-3">
                 <select class="form-control" ng-model="shared.due_date_offset" ng-change="resetDueDate()">
                 [% l('Due Date:') %]
               </div>
               <div class="col-md-4">
-                <eg-date-input ng-model="shared.due_date" min-date="minDate"></eg-date-input>
+                <eg-date-input ng-model="shared.due_date" out-of-range="shared.outOfRange" min-date="minDate"></eg-date-input>
               </div>
               <div class="col-md-3">
                 <select class="form-control" ng-model="shared.due_date_offset" ng-change="resetDueDate()">
                 [% l('Checkin Date:') %]
               </div>
               <div class="col-md-6">
-                <eg-date-input ng-model="checkin.backdate" min-date="minDate"></eg-date-input>
+                <eg-date-input ng-model="checkin.backdate"></eg-date-input>
               </div>
             </div>
 
index 555afbd..6359212 100644 (file)
@@ -38,5 +38,9 @@
       </uib-timepicker>
     </span>
   </div>
+
+  <div>
+    <span ng-show="outOfRange" class="label label-danger">[% l('Input is out of range.') %]</span>
+  </div>
 </div>
 
index 6797d7e..8bd3752 100644 (file)
@@ -250,16 +250,22 @@ function($routeProvider , $locationProvider , $compileProvider) {
 ])
 
 .controller('OfflineCtrl', 
-           ['$q','$scope','$location','$rootScope','egCore','egLovefield','$routeParams','$timeout','$http','ngToast','egConfirmDialog',
-    function($q , $scope , $location , $rootScope , egCore , egLovefield , $routeParams , $timeout , $http , ngToast , egConfirmDialog) {
+           ['$q','$scope','$window','$location','$rootScope','egCore','egLovefield','$routeParams','$timeout','$http','ngToast','egConfirmDialog',
+    function($q , $scope , $window , $location , $rootScope , egCore , egLovefield , $routeParams , $timeout , $http , ngToast , egConfirmDialog) {
         $scope.active_tab = $routeParams.tab || 'checkout';
 
-        $scope.minDate = new Date();
+        var today = new Date();
+        today.setHours(0);
+        today.setMinutes(0);
+        today.setSeconds(0);
+        today.setMilliseconds(0);
+
+        $scope.minDate = today;
         $scope.blocked_patron = null;
         $scope.bad_barcode = null;
         $scope.barcode_type = 'barcode';
         $scope.focusMe = true;
-        $scope.shared = { due_date : null, due_date_offset : '' };
+        $scope.shared = { outOfRange : false, due_date : null, due_date_offset : '' };
         $scope.workstation_obj = null;
         $scope.workstation = '';
         $scope.workstation_owner = '';
@@ -410,8 +416,9 @@ function($routeProvider , $locationProvider , $compileProvider) {
         }
 
         $scope.save = function () {
+            var promises = [$q.when()];
             angular.forEach($scope.all_xact, function (x) {
-                egLovefield.addOfflineXact(x);
+                promises.push(egLovefield.addOfflineXact(x));
             });
 
             var prints = [$q.when()];
@@ -429,7 +436,7 @@ function($routeProvider , $locationProvider , $compileProvider) {
                 });
             }
 
-            return $q.all(prints).finally(function() {
+            return $q.all(promises.concat(prints)).finally(function() {
                 if (prints.length > 1) $scope.printed = true;
                 $scope.all_xact = [];
                 $scope.xact_page = { checkin:[], checkout:[], renew:[], in_house_use:[] };
@@ -443,6 +450,11 @@ function($routeProvider , $locationProvider , $compileProvider) {
         $rootScope.save_offline_xacts = function () { return $scope.save() };
         $rootScope.active_tab = function (t) { $scope.active_tab = t };
 
+        $scope.logout = function () {
+            egCore.auth.logout();
+            $window.location.href = location.href;
+        }
+
         $scope.clear_pending = function (skip_confirm) {
             if (skip_confirm) {
                 return egLovefield.destroyPendingOfflineXacts().then(function () {
@@ -497,7 +509,9 @@ function($routeProvider , $locationProvider , $compileProvider) {
         }
 
         $scope.notEnough = function (xtype) {
+
             if (xtype == 'checkout') {
+                if ($scope.shared.outOfRange) return true;
                 if (
                     $scope.checkout.patron_barcode &&
                     ($scope.shared.due_date || $scope.shared.due_date_offset) &&
@@ -507,6 +521,7 @@ function($routeProvider , $locationProvider , $compileProvider) {
             }
 
             if (xtype == 'renew') {
+                if ($scope.shared.outOfRange) return true;
                 if (
                     $scope.renew.barcode &&
                     ($scope.shared.due_date || $scope.shared.due_date_offset)
@@ -1422,7 +1437,7 @@ function($scope , $routeParams , $q , $uibModal , $window , egCore ,
          egWorkLog , $timeout , egLovefield , $rootScope) {
 
     $scope.rs = $rootScope;
-    patronRegSvc.org = $scope.workstation_obj.owning_lib;
+    if ($scope.workstation_obj) patronRegSvc.org = $scope.workstation_obj.owning_lib;
     $scope.offline = true;
 
     $scope.page_data_loaded = false;
index d25b33a..ca59df6 100644 (file)
@@ -707,12 +707,13 @@ function($window , egStrings) {
                 ngModel : '=',
                 ngChange : '=',
                 ngBlur : '=',
-                minDate : '=',
-                maxDate : '=',
+                minDate : '=?',
+                maxDate : '=?',
                 ngDisabled : '=',
                 ngRequired : '=',
                 hideDatePicker : '=',
-                dateFormat : '=?'
+                dateFormat : '=?',
+                outOfRange : '=?'
             },
             require: 'ngModel',
             templateUrl: './share/t_datetime',
@@ -721,6 +722,21 @@ function($window , egStrings) {
                 $scope.options = {
                     minDate : $scope.minDate,
                     maxDate : $scope.maxDate
+                };
+
+                var maxDateObj = $scope.maxDate ? new Date($scope.maxDate) : null;
+                var minDateObj = $scope.minDate ? new Date($scope.minDate) : null;
+
+                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;
+                        }
+                    });
                 }
             }],
             link : function(scope, elm, attrs) {