patron alerts panel continued
authorBill Erickson <berick@esilibrary.com>
Tue, 13 May 2014 14:40:51 +0000 (10:40 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 13 May 2014 14:40:51 +0000 (10:40 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/circ/patron/t_alerts.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/app.js
Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js

index 324c56a..64996c1 100644 (file)
@@ -3,6 +3,32 @@
   <!-- FIXME: move image file -->
   <img src='/xul/server/skin/media/images/stop_sign.png'>
 
+  <div class="alert alert-info" ng-if="patron_stats().holds.ready > 0">
+    [% l('Holds available: [_1]', '{{patron_stats().holds.ready}}') %]
+  </div>
+
+  <div class="alert alert-warning" ng-if="patronExpired">
+    [% l('Patron account is EXPIRED.') %]
+  </div>
+
+  <div class="alert alert-warning" ng-if="patronExpiresSoon">
+    [% l('Patron account will expire soon.  Please renew.') %]
+  </div>
+
+  <div class="alert alert-warning" ng-if="patron().barred() == 't'">
+    [% l('Patron account is BARRED') %]
+  </div>
+
+  <div class="alert alert-warning" ng-if="patron().active() == 'f'">
+    [% l('Patron account is INACTIVE') %]
+  </div>
+
+  <!--
+  TODO:
+  Patron account retrieved with an INACTIVE card.
+  -->
+
+  <!-- alert message -->
   <div class="row" ng-if="patron().alert_message()">
     <div class="col-md-12">
       <div class="panel panel-warning">
@@ -16,6 +42,7 @@
     </div>
   </div>
 
+  <!-- penalties -->
   <div class="row" ng-if="patron().standing_penalties().length">
     <div class="col-md-12">
       <div class="panel panel-warning">
index 1526516..9c172ad 100644 (file)
@@ -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;
+    });
+
 }])
 
 
index 2ae0301..d52b3a4 100644 (file)
@@ -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'};