Fix rendering of MFHD records when ownership is out of scope
authorDan Scott <dan@coffeecode.net>
Fri, 27 May 2011 17:51:59 +0000 (13:51 -0400)
committerDan Scott <dan@coffeecode.net>
Fri, 27 May 2011 17:51:59 +0000 (13:51 -0400)
Dojo would die with a null reference error when an MFHD record
was retrieved that was outside of the current OU search scope.
For example, if a given bib record had one linked MFHD record
for BR1, and one linked MFHD record for BR4, the details page
would choke trying to draw the MFHD holdings in a scope that
only included BR1 and end up drawing nothing. Ungood.

Moving the ownership check and invoking _holdingsDrawMFHD()
only after ensuring that the record is within our scope resolves
the problem.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/web/opac/skin/default/js/rdetail.js

index c74c385..2e92d0e 100644 (file)
@@ -351,28 +351,28 @@ function loadMarcEditor(recId) {
  * Limited brain power means that I'm brute-forcing it for now
  */
 function _holdingsDraw(h) {
-       holdings = h.getResultObject();
-       if (!holdings) { return null; }
-
-       dojo.forEach(holdings, _holdingsDrawMFHD);
-
-       // Populate XUL menus
-       if (isXUL()) {
-               runEvt('rdetail','MFHDDrawn');
-       }
-}
-
-function _holdingsDrawMFHD(holdings, entryNum) {
+    holdings = h.getResultObject();
+    if (!holdings) { return null; }
 
+    // Only draw holdings within our OU scope
+    dojo.forEach(holdings, function (item) {
         var here = findOrgUnit(getLocation());
         if (getDepth() > 0 || getDepth === 0 ) {
-                while (getDepth() < findOrgDepth(here))
-                here = findOrgUnit( here.parent_ou() );
-               if (!orgIsMine(findOrgUnit(here), findOrgUnit(holdings.owning_lib()))) {
-                       return null;
-               }
+            while (getDepth() < findOrgDepth(here))
+            here = findOrgUnit( here.parent_ou() );
+            if (orgIsMine(findOrgUnit(here), findOrgUnit(item.owning_lib()))) {
+                _holdingsDrawMFHD(item);
+            }
         }
+    });
 
+    // Populate XUL menus
+    if (isXUL()) {
+        runEvt('rdetail','MFHDDrawn');
+    }
+}
+
+function _holdingsDrawMFHD(holdings, entryNum) {
        var hb = holdings.basic_holdings();
        var hba = holdings.basic_holdings_add();
        var hs = holdings.supplement_holdings();