LP#1564685 Avoid referencing out-of-scope stat cats
authorBill Erickson <berickxx@gmail.com>
Fri, 1 Apr 2016 00:35:00 +0000 (20:35 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 4 Apr 2016 20:36:35 +0000 (16:36 -0400)
Fixes a bug in the patron editor where out-of-scope stat cats would be
incorrectly bundled in the patron save operation, resulting in a
server-side error on save.  In short, ignore out-of-scope stat cat
entries for patrons in the editor.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js

index 106bdb0..437c401 100644 (file)
@@ -611,6 +611,19 @@ angular.module('egCoreMod')
         angular.forEach(patron.addresses, 
             function(addr) { service.ingest_address(patron, addr) });
 
+        // Remove stat cat entries that link to out-of-scope stat
+        // cats.  With this, we avoid unnecessarily updating (or worse,
+        // modifying) stat cat values that are not ours to modify.
+        patron.stat_cat_entries = patron.stat_cat_entries.filter(
+            function(map) {
+                return Boolean(
+                    // service.stat_cats only contains in-scope stat cats.
+                    service.stat_cats.filter(function(cat) { 
+                        return (cat.id() == map.stat_cat.id) })[0]
+                );
+            }
+        );
+
         // toss entries for existing stat cat maps into our living 
         // stat cat entry map, which is modified within the template.
         angular.forEach(patron.stat_cat_entries, function(map) {