LP#1732761: Fetch locations immediately for display
authorMike Rylander <mrylander@gmail.com>
Mon, 9 Jul 2018 20:31:50 +0000 (16:31 -0400)
committerJason Stephenson <jason@sigio.com>
Thu, 20 Sep 2018 17:45:37 +0000 (13:45 -0400)
This commit closes a race condition where location labels cannot be rendered
for the "multiple locations" widget because fetching them takes longer than
the initial render of the attribute editor.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js

index 3187d45..2b5f236 100644 (file)
@@ -150,6 +150,20 @@ function(egCore , $q) {
         );
     };
 
+    service.fetch_locations = function(locs) {
+        return egCore.pcrud.search('acpl',
+            {id : locs},
+            {
+                flesh : 1,
+                flesh_fields : {
+                    acpl : ['owning_lib']
+                },
+                order_by : { acpl : 'name' }
+            },
+            {atomic : true}
+        );
+    };
+
     service.get_suffixes = function(org) {
         return egCore.pcrud.search('acns',
             {owning_lib : egCore.org.fullPath(org, true)},
@@ -1493,6 +1507,17 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
         }).then( function() {
             $scope.data = itemSvc;
             $scope.workingGridDataProvider.refresh();
+
+            return itemSvc.fetch_locations(
+                $scope.data.copies.map(function(cp){
+                    return cp.location();
+                }).filter(function(e,i,a){
+                    return a.lastIndexOf(e) === i;
+                })
+            ).then(function(list){
+                $scope.location_list = list;
+            });
+
         });
 
         $scope.can_save = false;
@@ -1734,9 +1759,6 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
         });
 
         $scope.location_list = [];
-        itemSvc.get_locations().then(function(list){
-            $scope.location_list = list;
-        });
         createSimpleUpdateWatcher('location');
 
         $scope.status_list = [];