limiting pickup location to where item available
authorartunit <artunit@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 10 Sep 2010 01:41:38 +0000 (01:41 +0000)
committerartunit <artunit@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 10 Sep 2010 01:41:38 +0000 (01:41 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/branches/rel_1_6_1@980 6d9bc8c9-1ec2-4278-b937-99fde70a366f

web/opac/skin/uwin/js/holds.js

index 0a7370c..eb3bbd7 100644 (file)
@@ -1,3 +1,4 @@
+var holdLocs = [109,122];
 var holdsOrgSelectorBuilt = false;
 var holdArgs;
 
@@ -11,6 +12,32 @@ item_form is specified, use item_type(s)--language
 var noEmailMessage;
 var noEmailMessageXUL;
 
+function checkLoc(search){
+  for (var i=0; i<holdLocs.length; i++)
+    if (holdLocs[i] == search) return true;
+               
+  return false;
+} 
+
+/*
+       inefficient to check this again but need to go beyond search location 
+*/
+function holdsCheckOk(loc_id, rec_id) {
+        var req = new Request( 'open-ils.search:open-ils.search.biblio.record.copy_count', loc_id, rec_id );
+        req.send(true);
+       if (req) {
+               var ccDepths =  req.result();
+               if (
+                       (parseInt(ccDepths[(ccDepths.length - 1)].available) == 0) && 
+                       (parseInt(ccDepths[(ccDepths.length - 1)].count) > 0)) 
+               {
+                       return loc_id;
+               }//if
+       }
+       return 0;
+}
+
+
 function holdsHandleStaff() {
 
     // if we know the recipient's barcode, use it
@@ -56,6 +83,8 @@ function _holdsHandleStaff() {
                return
        }
 
+       grabUserPrefs(user);
+
        holdArgs.recipient = user;
        holdsDrawEditor();
 }
@@ -343,7 +372,21 @@ function __holdsDrawWindow() {
        rec = (rec) ? rec : mr;
 
        if(!holdsOrgSelectorBuilt) {
-               holdsBuildOrgSelector(null,0);
+
+               //give preference to home location
+               var holdLoc = holdsCheckOk(holdArgs.recipient.home_ou(),rec.doc_id());
+               for (var i=0; i<holdLocs.length && holdLoc == 0; i++) {
+                       if (holdLoc != holdArgs.recipient.home_ou())
+                               holdLoc = holdsCheckOk(holdLocs[i], rec.doc_id())
+               }//for
+
+               //this should be rare, but if someone from another library was using
+               //the skin, it could happen, in which case we block it here
+               if (holdLoc == 0) {
+                       alert("Sorry, this material is not available for hold.");
+                       return;
+               }
+               holdsBuildOrgSelector(holdLoc,null,0);
                holdsOrgSelectorBuilt = true;
                var selector = $('holds_org_selector');
 
@@ -445,15 +488,21 @@ function __holdsDrawWindow() {
        $('holds_phone').value = holdArgs.recipient.day_phone();
        appendClear( $('holds_email'), text(holdArgs.recipient.email()));
 
-       var pref = G.user.prefs[PREF_HOLD_NOTIFY];
+       var pref = holdArgs.recipient.prefs[PREF_HOLD_NOTIFY];
 
        if(pref) {
-               if( ! pref.match(/email/i) ) 
+               if( ! pref.match(/email/i) ) {
                        $('holds_enable_email').checked = false;
+               } else {
+                       $('holds_enable_email').checked = true;
+               }
 
                if( ! pref.match(/phone/i) ) {
                        $('holds_phone').disabled = true;
                        $('holds_enable_phone').checked = false;
+               } else {
+                       $('holds_phone').disabled = false;
+                       $('holds_enable_phone').checked = true;
                }
        }
 
@@ -652,8 +701,7 @@ function holdsCheckPossibility(pickuplib, hold, recurse) {
        }
 }
 
-
-function holdsBuildOrgSelector(node) {
+function holdsBuildOrgSelector(holdLoc,node) {
 
        if(!node) node = globalOrgTree;
     if(!isTrue(node.opac_visible())) return;
@@ -663,15 +711,20 @@ function holdsBuildOrgSelector(node) {
 
        var type = findOrgType(node.ou_type());
        var indent = type.depth() - 1;
-       var opt = setSelectorVal( selector, index, node.name(), node.id(), null, indent );
-       if(!type.can_have_users()) {
-               opt.disabled = true;
-               addCSSClass(opt, 'disabled_option');
-       }
+       /*
+       pick up location is only ever one option for uwin
+       */
+       if (node.id() == holdLoc) {
+               var opt = setSelectorVal( selector, index, node.name(), node.id(), null, indent );
+               if(!type.can_have_users()) {
+                       opt.disabled = true;
+                       addCSSClass(opt, 'disabled_option');
+               }//if
+       }//if
        
        for( var i in node.children() ) {
                var child = node.children()[i];
-               if(child) holdsBuildOrgSelector(child);
+               if(child) holdsBuildOrgSelector(holdLoc,child);
        }
 }
 
@@ -744,8 +797,9 @@ function holdsBuildHoldFromWindow() {
     if($('holds_frozen_chkbox').checked) {
         hold.frozen('t');
         unHideMe($('hold_frozen_thaw_row'));
-        thawDate = dojo.date.stamp.toISOString(dijit.byId('holds_frozen_thaw_input').getValue());
+        var thawDate = dijit.byId('holds_frozen_thaw_input').attr('value');
         if(thawDate) {
+            thawDate = dojo.date.stamp.toISOString(thawDate);
             thawDate = holdsVerifyThawDate(thawDate); 
             if(thawDate) 
                 hold.thaw_date(thawDate);