LP#1452950 patron reg code cleanup
authorBill Erickson <berickxx@gmail.com>
Sat, 31 Oct 2015 17:08:02 +0000 (13:08 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 25 Feb 2016 22:31:57 +0000 (17:31 -0500)
Break up one of the bigger chunks by moving new patron defaults to its
own function.

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

index 63ab0c4..8b67bee 100644 (file)
@@ -558,6 +558,33 @@ function PatronRegCtrl($scope, $routeParams,
     $scope.edit_passthru.vis_level = 0; 
     // TODO: add save/clone handlers here
 
+    // Apply default values for new patrons during initial registration
+    // prs is shorthand for patronSvc
+    function set_new_patron_defaults(prs) {
+        $scope.generate_password();
+        $scope.hold_notify_phone = true;
+        $scope.hold_notify_email = true;
+
+        if (prs.org_settings['ui.patron.default_ident_type']) {
+            // $scope.patron needs this field to be an object
+            var id = prs.org_settings['ui.patron.default_ident_type'];
+            var ident_type = $scope.ident_types.filter(
+                function(type) { return type.id() == id })[0];
+            $scope.patron.ident_type = ident_type;
+        }
+        if (prs.org_settings['ui.patron.default_inet_access_level']) {
+            // $scope.patron needs this field to be an object
+            var id = prs.org_settings['ui.patron.default_inet_access_level'];
+            var level = $scope.net_access_levels.filter(
+                function(lvl) { return lvl.id() == id })[0];
+            $scope.patron.net_access_level = level;
+        }
+        if (prs.org_settings['ui.patron.default_country']) {
+            $scope.patron.addresses[0].country = 
+                prs.org_settings['ui.patron.default_country'];
+        }
+    }
+
     $q.all([
 
         $scope.initTab ? // initTab comes from patron app
@@ -597,31 +624,8 @@ function PatronRegCtrl($scope, $routeParams,
         if ($scope.org_settings['ui.patron.edit.default_suggested'])
             $scope.edit_passthru.vis_level = 1;
 
-        if ($scope.patron.isnew) {
-            $scope.generate_password();
-            $scope.hold_notify_phone = true;
-            $scope.hold_notify_email = true;
-
-            if (prs.org_settings['ui.patron.default_ident_type']) {
-                // $scope.patron needs this field to be an object
-                var id = prs.org_settings['ui.patron.default_ident_type'];
-                var ident_type = $scope.ident_types.filter(
-                    function(type) { return type.id() == id })[0];
-                $scope.patron.ident_type = ident_type;
-            }
-            if (prs.org_settings['ui.patron.default_inet_access_level']) {
-                // $scope.patron needs this field to be an object
-                var id = prs.org_settings['ui.patron.default_inet_access_level'];
-                var level = $scope.net_access_levels.filter(
-                    function(lvl) { return lvl.id() == id })[0];
-                $scope.patron.net_access_level = level;
-            }
-            if (prs.org_settings['ui.patron.default_country']) {
-                $scope.patron.addresses[0].country = 
-                    prs.org_settings['ui.patron.default_country'];
-            }
-        }
-            
+        if ($scope.patron.isnew) 
+            set_new_patron_defaults(prs);
     });
 
     // update the currently displayed field documentation