From e07e1341cf77cbc2108f03a2485428ba132e5fad Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 13 May 2014 10:40:51 -0400 Subject: [PATCH] patron alerts panel continued Signed-off-by: Bill Erickson --- .../src/templates/staff/circ/patron/t_alerts.tt2 | 27 ++++++ .../web/js/ui/default/staff/circ/patron/app.js | 98 ++++++++++++++++++---- .../js/ui/default/staff/circ/patron/checkout.js | 11 +-- 3 files changed, 112 insertions(+), 24 deletions(-) diff --git a/Open-ILS/src/templates/staff/circ/patron/t_alerts.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_alerts.tt2 index 324c56a496..64996c1fb4 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_alerts.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_alerts.tt2 @@ -3,6 +3,32 @@ +
+ [% l('Holds available: [_1]', '{{patron_stats().holds.ready}}') %] +
+ +
+ [% l('Patron account is EXPIRED.') %] +
+ +
+ [% l('Patron account will expire soon. Please renew.') %] +
+ +
+ [% l('Patron account is BARRED') %] +
+ +
+ [% l('Patron account is INACTIVE') %] +
+ + + +
@@ -16,6 +42,7 @@
+
diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js index 1526516d04..9c172ad71b 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js @@ -147,7 +147,10 @@ function($q , $timeout , egCore, egUser) { service.holds = []; service.hold_ids = []; service.checkout_overrides = {}; + service.hasAlerts = false; service.alertsShown = false; + service.patronExpired = false; + service.patronExpiresSoon = false; } service.resetPatronLists(); // initialize @@ -155,13 +158,13 @@ function($q , $timeout , egCore, egUser) { service.setDefault = function(id, user, force) { if (user) { if (!force && service.current && - service.current.id() == user.id()) return; + service.current.id() == user.id()) + return $q.when(); service.resetPatronLists(); service.current = user; service.localFlesh(user); - service.fetchUserStats(); - return $q.when(); + return service.fetchUserStats(); } else if (id) { if (!force && service.current && service.current.id() == id) @@ -173,7 +176,7 @@ function($q , $timeout , egCore, egUser) { function(user) { service.current = user; service.localFlesh(user); - service.fetchUserStats(); + return service.fetchUserStats(); }, function(err) { console.error( @@ -203,9 +206,63 @@ function($q , $timeout , egCore, egUser) { ); } + // resolves to true if the patron account has expired or will + // expire soon, based on YAOUS circ.patron_expires_soon_warning + service.testExpire = function() { + + var expire = Date.parse(service.current.expire_date()); + if (expire < new Date()) { + return $q.when(service.patronExpired = true); + } + + // account not yet expired, see if it will expire soon + return egCore.org.settings('circ.patron_expires_soon_warning') + .then(function(set) { + + var soon = set['circ.patron_expires_soon_warning']; + if (Number(soon)) { + var preExpire = new Date(); + preExpire.setDate(preExpire.getDate() + Number(soon)); + if (expire < preExpire) + return service.patronExpiresSoon = true; + } + + return false; + }); + } + + // resolves to true if there is any aspect of the patron account + // which should produce a message in the alerts panel + service.checkAlerts = function() { + var deferred = $q.defer(); + if (service.hasAlerts) return $q.when(true); + + var p = service.current; + + if (p.standing_penalties().length || + p.alert_message() || + p.active() == 'f' || + p.barred() == 't' || + service.patron_stats.holds.ready) { + + service.hasAlerts = true; + } + + + // regardless of whether we know of alerts, we still need + // to test/fetch the expire data for display + service.testExpire().then(function(bool) { + if (bool) service.hasAlerts = true; + deferred.resolve(service.hasAlerts); + }); + + return deferred.promise; + } + + // grab additional circ info service.fetchUserStats = function() { - egCore.net.request( + return egCore.net.request( 'open-ils.actor', 'open-ils.actor.user.opac.vital_stats', egCore.auth.token(), service.current.id() @@ -229,8 +286,8 @@ function($q , $timeout , egCore, egUser) { * Manages tabbed patron view * */ .controller('PatronCtrl', - ['$scope','$q','$filter','egCore','egUser','patronSvc', -function($scope, $q, $filter, egCore, egUser, patronSvc) { + ['$scope','$q','$location','$filter','egCore','egUser','patronSvc', +function($scope, $q, $location , $filter, egCore, egUser, patronSvc) { // called after each route-specified controller is instantiated. // this doubles as a way to inform the top-level controller that @@ -242,7 +299,20 @@ function($scope, $q, $filter, egCore, egUser, patronSvc) { $scope.aous = egCore.env.aous; if (patron_id) { $scope.patron_id = patron_id - return patronSvc.setDefault($scope.patron_id); + return patronSvc.setDefault($scope.patron_id) + .then(function() {return patronSvc.checkAlerts()}) + .then(function() { + console.log("patron has alerts = " + patronSvc.hasAlerts); + + // if the patron has any unshown alerts, show them now + if (!patronSvc.alertsShown && + patronSvc.hasAlerts && + !$location.path().match(/\/alerts$/)) { + patronSvc.alertsShown = true; + $location.path('/circ/patron/' + + patronSvc.current.id() + '/alerts'); + } + }); } return $q.when(); } @@ -699,12 +769,12 @@ function($scope, $routeParams , $location , egCore) { ['$scope','$routeParams','$location','egCore','patronSvc', function($scope, $routeParams , $location , egCore , patronSvc) { - // called with a patron, pre-populate the form args - $scope.initTab('other', $routeParams.id).then( - function() { - patronSvc.alertsShown = true; - } - ); + $scope.initTab('other', $routeParams.id) + .then(function() { + $scope.patronExpired = patronSvc.patronExpired; + $scope.patronExpiresSoon = patronSvc.patronExpiresSoon; + }); + }]) diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js b/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js index 2ae0301d0f..d52b3a4c17 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js @@ -10,16 +10,7 @@ angular.module('egPatronApp').controller('PatronCheckoutCtrl', function($scope , $q , $modal , $routeParams , egCore , egUser , patronSvc , egGridDataProvider , $location) { - $scope.initTab('checkout', $routeParams.id).then( - function() { - var p = $scope.patron(); - if (!patronSvc.alertsShown && - (p.standing_penalties().length || p.alert_message())) { - $location.path('/circ/patron/' + p.id() + '/alerts'); - } - } - ); - + $scope.initTab('checkout', $routeParams.id); $scope.focusMe = true; $scope.checkouts = patronSvc.checkouts; $scope.checkoutArgs = {noncat_type : 'barcode'}; -- 2.11.0