improved stat cat handling
authorBill Erickson <berick@esilibrary.com>
Wed, 11 Jun 2014 21:43:37 +0000 (17:43 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 11 Jun 2014 21:43:37 +0000 (17:43 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/ui/default/staff/circ/patron/app.js

index 809301b..29ccfac 100644 (file)
@@ -248,28 +248,27 @@ function($q , $timeout , $location , egCore,  egUser , $locale) {
 
     // flesh some additional user fields locally
     service.localFlesh = function(user) {
-        if (typeof user.home_ou() != 'object')
+        if (!angular.isObject(typeof user.home_ou()))
             user.home_ou(egCore.org.get(user.home_ou()));
 
         angular.forEach(
             user.standing_penalties(),
             function(penalty) {
-                if (typeof penalty.org_unit() != 'object')
+                if (!angular.isObject(penalty.org_unit()))
                     penalty.org_unit(egCore.org.get(penalty.org_unit()));
             }
         );
 
-        service.summary_stat_cats = [];
-
         // stat_cat_entries == stat_cat_entry_user_map
         angular.forEach(user.stat_cat_entries(), function(map) {
-            // flesh the stat cat
-            map.stat_cat(egCore.env.actsc.map[map.stat_cat()]);
-            // flesh the owner
-            map.stat_cat().owner(egCore.org.get(map.stat_cat().owner()));
-
-            if (map.stat_cat().usr_summary() == 't')
-                service.summary_stat_cats.push(map);
+            if (angular.isObject(map.stat_cat())) return;
+            // At page load, we only retrieve org-visible stat cats.
+            // For the common case, ignore entries for remote stat cats.
+            var cat = egCore.env.actsc.map[map.stat_cat()];
+            if (cat) {
+                map.stat_cat(cat);
+                cat.owner(egCore.org.get(cat.owner()));
+            }
         });
     }
 
@@ -380,6 +379,17 @@ function($q , $timeout , $location , egCore,  egUser , $locale) {
                 .filter(function(pen) { 
                 return pen.standing_penalty().staff_alert() == 't' 
             });
+
+            service.summary_stat_cats = [];
+            angular.forEach(service.current.stat_cat_entries(), 
+                function(map) {
+                    if (angular.isObject(map.stat_cat()) &&
+                        map.stat_cat().usr_summary() == 't') {
+                        service.summary_stat_cats.push(map);
+                    }
+                }
+            );
+
             return service.fetchGroupFines();
         });
     }
@@ -1273,8 +1283,27 @@ function($scope,  $routeParams , $q , $location , egCore ,
 .controller('PatronStatCatsCtrl',
        ['$scope','$routeParams','$q','egCore','patronSvc',
 function($scope,  $routeParams , $q , egCore , patronSvc) {
-    $scope.initTab('other', $routeParams.id);
-    // nothing to do.  Stat cats are already fleshed and patron is
-    // already accessible from the scope.
+    $scope.initTab('other', $routeParams.id)
+    .then(function(redirect) {
+        // Entries for org-visible stat cats are fleshed.  Any others
+        // have to be fleshed within.
+
+        var to_flesh = {};
+        angular.forEach(patronSvc.current.stat_cat_entries(), 
+            function(entry) {
+                if (!angular.isObject(entry.stat_cat())) {
+                    to_flesh[entry.stat_cat()] = entry;
+                }
+            }
+        );
+
+        if (!Object.keys(to_flesh).length) return;
+
+        egCore.pcrud.search('actsc', {id : Object.keys(to_flesh)})
+        .then(null, null, function(cat) { // stream
+            cat.owner(egCore.org.get(cat.owner())); // owner flesh
+            to_flesh[cat.id()].stat_cat(cat);
+        });
+    });
 }])