patron alert panel : inactive card retrieval
authorBill Erickson <berick@esilibrary.com>
Tue, 13 May 2014 15:19:04 +0000 (11:19 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 13 May 2014 15:19:04 +0000 (11:19 -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

index 64996c1..e9a0adf 100644 (file)
     [% l('Patron account is INACTIVE') %]
   </div>
 
-  <!--
-  TODO:
-  Patron account retrieved with an INACTIVE card.
-  -->
+  <div class="alert alert-warning" ng-if="retrievedWithInactive">
+    [% l('Patron account retrieved with an INACTIVE card.') %]
+  </div>
 
   <!-- alert message -->
   <div class="row" ng-if="patron().alert_message()">
index 9c172ad..ed4f143 100644 (file)
@@ -36,10 +36,12 @@ angular.module('egPatronApp', ['ngRoute', 'ui.bootstrap',
 
         // app-globally modify the default flesh fields for 
         // fleshed user retrieval
-        egUser.defaultFleshFields.push('profile');
-        egUser.defaultFleshFields.push('net_access_level');
-        egUser.defaultFleshFields.push('ident_type');
-        egUser.defaultFleshFields.push('ident_type2');
+        egUser.defaultFleshFields = egUser.defaultFleshFields.concat([
+            'net_access_level',
+            'ident_type',
+            'ident_type2',
+            'cards'
+        ]);
 
         return egCore.startup.go()
     }]};
@@ -119,8 +121,8 @@ angular.module('egPatronApp', ['ngRoute', 'ui.bootstrap',
  * Patron service
  */
 .factory('patronSvc',
-       ['$q','$timeout','egCore','egUser',
-function($q , $timeout , egCore,  egUser) {
+       ['$q','$timeout','$location','egCore','egUser',
+function($q , $timeout , $location , egCore,  egUser) {
 
     var service = {
         // cached patron search results
@@ -151,6 +153,7 @@ function($q , $timeout , egCore,  egUser) {
         service.alertsShown = false;
         service.patronExpired = false;
         service.patronExpiresSoon = false;
+        service.retrievedWithInactive = false;
     }
     service.resetPatronLists();  // initialize
 
@@ -234,9 +237,11 @@ function($q , $timeout , egCore,  egUser) {
     // 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);
 
+        if (service.hasAlerts) // already checked
+            return $q.when(true); 
+
+        var deferred = $q.defer();
         var p = service.current;
 
         if (p.standing_penalties().length ||
@@ -248,6 +253,16 @@ function($q , $timeout , egCore,  egUser) {
             service.hasAlerts = true;
         }
 
+        // see if the user was retrieved with an inactive card
+        if (bc = $location.search().card) {
+            var card = p.cards().filter(
+                function(c) { return c.barcode() == bc })[0];
+
+            if (card && card.active() == 'f') {
+                service.hasAlerts = true;
+                service.retrievedWithInactive = true;
+            }
+        }
 
         // regardless of whether we know of alerts, we still need 
         // to test/fetch the expire data for display
@@ -283,12 +298,28 @@ function($q , $timeout , egCore,  egUser) {
 }])
 
 /**
- * Manages tabbed patron view
+ * Manages tabbed patron view.
+ * This is the parent scope of all patron tab scopes.
+ *
  * */
 .controller('PatronCtrl',
        ['$scope','$q','$location','$filter','egCore','egUser','patronSvc',
 function($scope,  $q,  $location , $filter,  egCore,  egUser,  patronSvc) {
 
+    function redirectToAlertPanel() {
+        if (patronSvc.alertsShown) return;
+        patronSvc.alertsShown = true;
+
+        // if the patron has any unshown alerts, show them now
+        if (patronSvc.hasAlerts && 
+            !$location.path().match(/alerts$/)) {
+
+            $location
+                .path('/circ/patron/' + patronSvc.current.id() + '/alerts')
+                .search('card', null);
+        }
+    }
+
     // called after each route-specified controller is instantiated.
     // this doubles as a way to inform the top-level controller that
     // egStartup.go() has completed, which means we are clear to 
@@ -297,22 +328,12 @@ function($scope,  $q,  $location , $filter,  egCore,  egUser,  patronSvc) {
         console.log('init tab ' + tab);
         $scope.tab = tab;
         $scope.aous = egCore.env.aous;
+
         if (patron_id) {
-            $scope.patron_id = patron_id
+            $scope.patron_id = 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');
-                }
-            });
+            .then(redirectToAlertPanel);
         }
         return $q.when();
     }
@@ -329,7 +350,9 @@ function($scope , $location , egCore , egConfirmDialog , egUser , patronSvc) {
 
     // jump to the patron checkout UI
     function loadPatron(user_id) {
-        $location.path('/circ/patron/' + user_id + '/checkout');
+        $location
+        .path('/circ/patron/' + user_id + '/checkout')
+        .search('card', $scope.args.barcode);
     }
 
     // create an opt-in=yes response for the loaded user
@@ -773,6 +796,7 @@ function($scope,  $routeParams , $location , egCore , patronSvc) {
     .then(function() {
         $scope.patronExpired = patronSvc.patronExpired;
         $scope.patronExpiresSoon = patronSvc.patronExpiresSoon;
+        $scope.retrievedWithInactive = patronSvc.retrievedWithInactive;
     });
 
 }])