From eb0c22425d41910be16b405a19bccf9f07b4a54b Mon Sep 17 00:00:00 2001
From: Galen Charlton <gmc@equinoxinitiative.org>
Date: Thu, 25 Jan 2018 14:57:40 -0500
Subject: [PATCH] LP#1745462: avoid trying to validate empty fields

This patch is the belt to the previous patch's suspenders and ensures
that the web staff client does not attempt to authority-validate headings
fields in the MARC editor if they're empty (i.e., no subfield values).

To test
-------
[1] In the web staff client, create a new bib. Ensure that at least one of the
    authority-controlled fields has no subfield values.
[2] Hit the Validate button.
[3] Note that the field(s) with empty headings show the tick
    mark indicating that they've been "validated".
[4] Apply the patch and repeat steps 1 and 2. This time, empty headings
    field should not be checked.
[5] Verify that validating headings that are not empty does continue
    to work.

Patch inspired by Mike Rylander.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
---
 Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js |  1 +
 Open-ILS/web/js/ui/default/staff/cat/services/tagtable.js | 10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js
index 1085e6312e..96a15dd888 100644
--- a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js
+++ b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js
@@ -1327,6 +1327,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                             return;
                         }
                         var auth_match = $scope.controlSet.bibToAuthorities(f);
+                        if (auth_match.length == 0) return;
                         chain = chain.then(function() {
                             var promise = egCore.net.request(
                                 'open-ils.search',
diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/tagtable.js b/Open-ILS/web/js/ui/default/staff/cat/services/tagtable.js
index 85b2e320aa..90d894cb8d 100644
--- a/Open-ILS/web/js/ui/default/staff/cat/services/tagtable.js
+++ b/Open-ILS/web/js/ui/default/staff/cat/services/tagtable.js
@@ -461,10 +461,16 @@ function($q,   egCore,   egAuth) {
                 var sflist = [];                
                 for (var i = 0; i < field.subfields.length; i++) {
                     if (af.sf_list().indexOf(field.subfields[i][0]) > -1) {
-                        sflist.push(field.subfields[i]);
+                        if (typeof(field.subfields[i][1]) != 'undefined'
+                            && field.subfields[i][1] !== null
+                            && field.subfields[i][1].length > 0
+                        ) {
+                                sflist.push(field.subfields[i]);
+                        }
                     }
                 }
-    
+                if (sflist.length == 0) return null;
+
                 var m = new MARC21.Record ({rtype:'AUT'});
                 m.appendFields(
                     new MARC21.Field ({
-- 
2.11.0