webstaff: Teach holdings to re-render when paging through result lists
authorMike Rylander <mrylander@gmail.com>
Thu, 30 Jul 2015 13:50:56 +0000 (09:50 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 17 Aug 2015 22:56:56 +0000 (22:56 +0000)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js

index f328dd8..8658bf6 100644 (file)
@@ -201,6 +201,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         if (match) {
             $scope.record_id = match[1];
             egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
+            $scope.holdings_record_id_changed($scope.record_id);
             init_parts_url();
         } else {
             delete $scope.record_id;
@@ -236,6 +237,21 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         }
     });
 
+    // refresh the list of holdings when the record_id is changed.
+    $scope.holdings_record_id_changed = function(id) {
+        if ($scope.record_id != id) $scope.record_id = id;
+        console.log('record id changed to ' + id + ', loading new holdings');
+        holdingsSvc.fetch({
+            rid : $scope.record_id,
+            org : $scope.holdings_ou,
+            copy: $scope.holdings_show_copies,
+            vol : $scope.holdings_show_vols,
+            empty: $scope.holdings_show_empty
+        }).then(function() {
+            $scope.holdingsGridDataProvider.refresh();
+        });
+    }
+
     // refresh the list of holdings when the filter lib is changed.
     $scope.holdings_ou = egCore.org.get(egCore.auth.user().ws_ou());
     $scope.holdings_ou_changed = function(org) {
@@ -776,26 +792,28 @@ function(egCore , $q) {
                 });
 
                 var flat = egCore.idl.toHash(copies);
-                var owner = egCore.org.get(flat[0].call_number.owning_lib);
+                if (flat[0]) {
+                    var owner = egCore.org.get(flat[0].call_number.owning_lib);
 
-                var owner_name_list = [];
-                while (owner.parent_ou()) { // we're going to skip the top of the tree...
-                    owner_name_list.unshift(owner.name());
-                    owner = egCore.org.get(owner.parent_ou());
-                }
+                    var owner_name_list = [];
+                    while (owner.parent_ou()) { // we're going to skip the top of the tree...
+                        owner_name_list.unshift(owner.name());
+                        owner = egCore.org.get(owner.parent_ou());
+                    }
 
-                angular.forEach(flat, function (cp) {
-                    cp.owner_list = owner_name_list;
-                    cp.id_list = [cp.id];
-                });
+                    angular.forEach(flat, function (cp) {
+                        cp.owner_list = owner_name_list;
+                        cp.id_list = [cp.id];
+                    });
 
-                service.copies = service.copies.concat(flat);
+                    service.copies = service.copies.concat(flat);
 
-                if (empty && flat.length == 0) {
-                    service.copies.push({
-                        owner_list : owner_name_list,
-                        call_number: egCore.idl.toHash(cn)
-                    });
+                    if (empty && flat.length == 0) {
+                        service.copies.push({
+                            owner_list : owner_name_list,
+                            call_number: egCore.idl.toHash(cn)
+                        });
+                    }
                 }
 
                 return cn;