LP#1691237 Date settings retrieval via egEnv
authorBill Erickson <berickxx@gmail.com>
Fri, 9 Jun 2017 20:01:14 +0000 (16:01 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 19 Jun 2017 16:15:49 +0000 (12:15 -0400)
Avoid multiple .resolve() calls on the main egStartup promise by asking
egEnv to fetch the new date/time org unit settings.  Related, make the
pathway for adding new universally-loaded data functions more obvious
and consistent in egStartup by putting them right up at the top.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/web/js/ui/default/staff/services/startup.js

index 682317b..f268ddb 100644 (file)
@@ -19,6 +19,25 @@ function($q,  $rootScope,  $location,  $window,  egIDL,  egAuth,  egEnv , egOrg
 
     var service = { promise : null }
 
+    // Load date/time format settings on all pages.  Add more .push(...)
+    // calls to add more universal data-loading functions. 
+    // egEnv.loaders functions must return a promise.
+    egEnv.loaders.push(
+        function() {
+            return egOrg.settings([
+                'webstaff.format.dates',
+                'webstaff.format.date_and_time'
+            ]).then(
+                function(set) {
+                    $rootScope.egDateFormat = 
+                        set['webstaff.format.dates'] || 'shortDate';
+                    $rootScope.egDateAndTimeFormat = 
+                        set['webstaff.format.date_and_time'] || 'short';
+                }
+            );
+        },
+    );
+
     // returns true if we are staying on the current page
     // false if we are redirecting to login
     service.expiredAuthHandler = function() {
@@ -67,19 +86,6 @@ function($q,  $rootScope,  $location,  $window,  egIDL,  egAuth,  egEnv , egOrg
                         deferred.reject('egEnv did not resolve')
                     }
                 );
-                egOrg.settings([
-                    'webstaff.format.dates',
-                    'webstaff.format.date_and_time'
-                ]).then(
-                    function(set) {
-                        $rootScope.egDateFormat = set['webstaff.format.dates'] || 'shortDate';
-                        $rootScope.egDateAndTimeFormat = set['webstaff.format.date_and_time'] || 'short';
-                        deferred.resolve();
-                    },
-                    function() {
-                        deferred.reject('egOrg did not resolve');
-                    }
-                );
             },
 
             // testAuthToken rejected