checkin
authorBill Erickson <berick@esilibrary.com>
Tue, 24 Jun 2014 21:25:22 +0000 (17:25 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 24 Jun 2014 21:25:22 +0000 (17:25 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/ui/default/staff/circ/services/circ.js

index 5182527..c027820 100644 (file)
@@ -12,7 +12,6 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
     var service = {
         // auto-override these events after the first override
         auto_override_checkout_events : {},
-        org_addr_cache : {} // TODO: use egEnv
     };
 
     service.reset = function() {
@@ -320,6 +319,7 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
         if (!evt || !(payload = evt.payload)) return $q.when();
 
         promises.push(service.flesh_copy_location(payload.copy));
+        promises.push(service.flesh_copy_status(payload.copy));
 
         // local flesh transit
         if (transit = payload.transit) {
@@ -340,6 +340,18 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
         return $q.all(promises);
     }
 
+    // fetches the full list of copy statuses
+    service.flesh_copy_status = function(copy) {
+        if (egCore.env.ccs) 
+            return $q.when(copy.status(egCore.env.ccs.map[copy.status()]));
+        return egCore.pcrud.retrieveAll('ccs', {}, {atomic : true}, 
+            function(list) {
+                egCore.env.absorbList(list, 'ccs');
+                copy.status(egCore.env.ccs.map[copy.status()]);
+            }
+        );
+    }
+
     // there may be *many* copy locations and we may be handling items
     // for other locations.  Fetch copy locations as-needed and cache.
     service.flesh_copy_location = function(copy) {
@@ -360,20 +372,17 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
     }
 
 
-    // fetch/cache for org unit addresses
-    // TODO: use egEnv instead
+    // fetch org unit addresses as needed.
     service.get_org_addr = function(org_id, addr_type) {
-        if (service.org_addr_cache[org_id]) {
-            if (service.org_addr_cache[org_id][addr_type]) 
-                return $q.when(service.org_addr_cache[org_id][addr_type]);
-        } else {
-            service.org_addr_cache[org_id] = {};
-        }
+        var org = egCore.org.get(org_id);
+        var addr_id = org[addr_type]();
+
+        if (egCore.env.aoa && egCore.env.aoa.map[addr_id]) 
+            return $q.when(egCore.env.aoa.map[addr_id]); 
 
-        return egCore.pcrud.retrieve('aoa', 
-            egCore.org.get(org_id)[addr_type]()
-        ).then(function(addr) {
-            return service.org_addr_cache[org_id][addr_type] = addr;
+        return egCore.pcrud.retrieve('aoa', addr_id).then(function(addr) {
+            egCore.env.absorbList([addr], 'aoa');
+            return egCore.env.aoa.map[addr_id]; 
         });
     }
 
@@ -660,7 +669,7 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
             case 'SUCCESS':
             case 'NO_CHANGE':
 
-                if (copy.status() == 8 // on holds shelf
+                if (copy.status().id() == 8 // on holds shelf
                     && hold 
                     && hold.pickup_lib() == egCore.auth.user().ws_ou()) {
                     // inform user if the item is on the local holds shelf