webstaff: put heading validation lookups in a promise chain
authorGalen Charlton <gmc@esilibrary.com>
Thu, 3 Sep 2015 21:27:25 +0000 (21:27 +0000)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:19 +0000 (15:44 -0400)
Doing this to avoid spamming potentially a couple dozen
authority record lookups all at once.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

index 9d11cd7..119644d 100644 (file)
@@ -995,6 +995,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
 
                 $scope.validateHeadings = function () {
                     if ($scope.record_type != 'bre') return;
+                    var chain = $q.when();
                     angular.forEach($scope.record.fields, function(f) {
                         if (!$scope.controlSet.bibFieldByTag(f.tag)) return;
                         // if heading already has a $0, assume it's good
@@ -1004,25 +1005,28 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                             return;
                         }
                         var auth_match = $scope.controlSet.bibToAuthorities(f);
-                        egCore.net.request(
-                            'open-ils.search',
-                            'open-ils.search.authority.simple_heading.from_xml.batch.atomic',
-                            auth_match[0]
-                        ).then(function (matches) {
-                            f.heading_valid = false;
-                            if (matches[0]) { // probably set
-                                for (var cset in matches[0]) {
-                                    var arr = matches[0][cset];
-                                    if (arr.length) {
-                                        // protect against errant empty string values
-                                        if (arr.length == 1 && arr[0] == '')
-                                            continue;
-                                        f.heading_valid = true;
-                                        break;
+                        chain = chain.then(function() {
+                            var promise = egCore.net.request(
+                                'open-ils.search',
+                                'open-ils.search.authority.simple_heading.from_xml.batch.atomic',
+                                auth_match[0]
+                            ).then(function (matches) {
+                                f.heading_valid = false;
+                                if (matches[0]) { // probably set
+                                    for (var cset in matches[0]) {
+                                        var arr = matches[0][cset];
+                                        if (arr.length) {
+                                            // protect against errant empty string values
+                                            if (arr.length == 1 && arr[0] == '')
+                                                continue;
+                                            f.heading_valid = true;
+                                            break;
+                                        }
                                     }
                                 }
-                            }
-                            f.heading_checked = true;
+                                f.heading_checked = true;
+                            });
+                            return promise;
                         });
                     });
                 }