From b9a2c3bc7c192a05caab921ee28318bf6e3b2e5d Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Fri, 23 Jun 2017 09:32:28 -0400 Subject: [PATCH] offline: enhance egDateInput range validation for checkout and renew, and provide a fast path to logging out for offline work Signed-off-by: Mike Rylander --- Open-ILS/src/templates/staff/offline-interface.tt2 | 11 +++++--- Open-ILS/src/templates/staff/share/t_datetime.tt2 | 4 +++ Open-ILS/web/js/ui/default/staff/offline.js | 29 ++++++++++++++++------ Open-ILS/web/js/ui/default/staff/services/ui.js | 22 +++++++++++++--- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/templates/staff/offline-interface.tt2 b/Open-ILS/src/templates/staff/offline-interface.tt2 index 5f44eaccdf..0cc81fd41b 100644 --- a/Open-ILS/src/templates/staff/offline-interface.tt2 +++ b/Open-ILS/src/templates/staff/offline-interface.tt2 @@ -55,7 +55,10 @@

[% l('Warning') %]

- [% 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.') %] +
+
+
@@ -76,7 +79,7 @@ [% l('Due Date:') %]
- +
@@ -350,7 +353,7 @@ [% l('Checkin Date:') %]
- +
diff --git a/Open-ILS/src/templates/staff/share/t_datetime.tt2 b/Open-ILS/src/templates/staff/share/t_datetime.tt2 index 555afbdd69..635921261e 100644 --- a/Open-ILS/src/templates/staff/share/t_datetime.tt2 +++ b/Open-ILS/src/templates/staff/share/t_datetime.tt2 @@ -38,5 +38,9 @@ + +
+ [% l('Input is out of range.') %] +
diff --git a/Open-ILS/web/js/ui/default/staff/offline.js b/Open-ILS/web/js/ui/default/staff/offline.js index 6797d7e497..8bd3752802 100644 --- a/Open-ILS/web/js/ui/default/staff/offline.js +++ b/Open-ILS/web/js/ui/default/staff/offline.js @@ -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; diff --git a/Open-ILS/web/js/ui/default/staff/services/ui.js b/Open-ILS/web/js/ui/default/staff/services/ui.js index d25b33a5d9..ca59df6189 100644 --- a/Open-ILS/web/js/ui/default/staff/services/ui.js +++ b/Open-ILS/web/js/ui/default/staff/services/ui.js @@ -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) { -- 2.11.0