From 1adb00509209c3ebd223701612b1f2692b17e3bc Mon Sep 17 00:00:00 2001
From: Jeff Davis <jdavis@sitka.bclibraries.ca>
Date: Fri, 8 Jun 2018 12:09:54 -0700
Subject: [PATCH] LP#1788680 prevent copy template apply failure on null stat
 cats

Under some circumstances, the current code can result in a JS failure:

Cannot read property 'filter' of undefined

When this happens, the copy template may apply partially or not at all.
This change simply makes sure cp.stat_cat_entries() exists before
attempting to filter it.

Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
---
 Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js
index 507c4cbb10..5923b401b2 100644
--- a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js
+++ b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js
@@ -1302,11 +1302,13 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                         // trim out all deleted ones; the API used to
                         // do the update doesn't actually consult
                         // isdeleted for stat cat entries
-                        cp.stat_cat_entries(
-                            cp.stat_cat_entries().filter(function (e) {
-                                return !Boolean(e.isdeleted());
-                            })
-                        );
+                        if (cp.stat_cat_entries()) {
+                            cp.stat_cat_entries(
+                                cp.stat_cat_entries().filter(function (e) {
+                                    return !Boolean(e.isdeleted());
+                                })
+                            );
+                        }
    
                         cp.ischanged(1);
                     }
-- 
2.11.0