From: Mike Rylander <mrylander@gmail.com>
Date: Mon, 11 Dec 2017 21:21:39 +0000 (-0500)
Subject: LP#1736763: Wait until the org tree is there before using it
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ef2655fc88d06334d6f73d6fab8a4661d35b97a1;p=contrib%2FConifer.git

LP#1736763: Wait until the org tree is there before using it

In offline mode, we need to wait for the org tree to be fetched or recreated
before we set the working location dropdown.  This commit adds a function
to loop and wait for that to happen.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Cesar Velez <cesar.velez@equinoxinitiative.org>
---

diff --git a/Open-ILS/web/js/ui/default/staff/offline.js b/Open-ILS/web/js/ui/default/staff/offline.js
index c27360bd5b..1441c3884a 100644
--- a/Open-ILS/web/js/ui/default/staff/offline.js
+++ b/Open-ILS/web/js/ui/default/staff/offline.js
@@ -359,7 +359,9 @@ function($routeProvider , $locationProvider , $compileProvider) {
 
                     if (match) {
                         // requested WS registered on this client
+                        $scope.workstation_obj = match;
                         $scope.workstation = match.id;
+                        $scope.workstation_owner = match.owning_lib;
                     } else {
                         // the requested WS is not registered on this client
                         $scope.wsNotRegistered = true;
@@ -721,6 +723,17 @@ function($routeProvider , $locationProvider , $compileProvider) {
             return check_digit;
         }
 
+        function fetch_org_after_tree_exists () {
+            $timeout(function(){
+                try {
+                    $scope.org = egCore.org.get($scope.current_workstation_owning_lib());
+                } catch(e) {
+                    fetch_org_after_tree_exists();
+                }
+            },100);
+        }
+
+        fetch_org_after_tree_exists();
     }
 ])