LP#1796971 Wait for call number and copy before loading locations
authorDan Wells <dbw2@calvin.edu>
Thu, 11 Oct 2018 13:21:05 +0000 (09:21 -0400)
committerCesar Velez <cesardv@protonmail.ch>
Tue, 16 Oct 2018 22:16:48 +0000 (18:16 -0400)
In cases where add a copy to a call number, we fetch the original
call number via async, then attach the new copy to it.  Before this
commit, however, we were not waiting for the call number fetch
promise to resolve, so the copy wasn't there to use for limiting the
location load.

Since the async request is internal to a loop, one way out is to
capture that promise, then make sure it resolves before loading the
locations.

(We previously returned the copies from the internal function, but that
value wasn't being used anyway, so we don't worry about unwrapping the
$q.all() when it resolves.)

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: John Amundson <jamundson@cwmars.org>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Cesar Velez <cesar.velez@equinoxinitiative.org>

Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js

index 04b1963..ae42674 100644 (file)
@@ -1525,12 +1525,13 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                      * All can be left out and a completely empty vol/copy combo will be vivicated.
                      */
 
+                    var promises = [];
                     angular.forEach(
                         data.raw,
                         function (proto) {
                             if (proto.fast_add) $scope.is_fast_add = true;
                             if (proto.callnumber) {
-                                return egCore.pcrud.retrieve('acn', proto.callnumber)
+                                promises.push(egCore.pcrud.retrieve('acn', proto.callnumber)
                                 .then(function(cn) {
                                     var cp = new itemSvc.generateNewCopy(
                                         cn,
@@ -1545,7 +1546,7 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                                     }
 
                                     itemSvc.addCopy(cp)
-                                });
+                                }));
                             } else {
                                 var cn = new egCore.idl.acn();
                                 cn.id( --itemSvc.new_cn_id );
@@ -1612,7 +1613,7 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                         }
                     });
 
-                    return itemSvc.copies;
+                    return $q.all(promises);
                 }
 
                 if (data.copies && data.copies.length)