1 load_lib('catalog/record_type.js');
2 load_lib('circ/circ_groups.js');
6 if( environment.copy ) {
7 environment.copy.fetchBestHold = function() {
8 var key = scratchKey();
9 environment.copy.__OILS_FUNC_fetch_best_hold(scratchPad(key));
10 var val = getScratch(key);
11 return (val) ? val : null;
17 /* -----------------------------------------------------------------------------
18 Collect all of the global variables
19 ----------------------------------------------------------------------------- */
21 /* the global result object. Any data returned to the
22 caller must be put into this object. */
23 var result = environment.result = {};
24 result.event = 'SUCCESS';
26 result.fatalEvents = [];
27 result.infoEvents = [];
30 /* Pull in any variables passed in from the calling process */
31 var copy = environment.copy;
32 var volume = environment.volume;
33 var title = environment.title;
34 var recDescriptor = environment.titleDescriptor;
35 var patron = environment.patron;
36 var patronItemsOut = environment.patronItemsOut;
37 var patronOverdueCount = environment.patronOverdueCount;
38 var patronFines = environment.patronFines;
39 var isRenewal = environment.isRenewal;
40 var isPrecat = environment.isPrecat;
41 var currentLocation = environment.location;
42 var holdRequestLib = environment.requestLib;
43 var holdPickupLib = environment.pickupLib; /* hold pickup lib */
44 var requestor = environment.requestor || patron;
48 /* create some new vars based on the data we have wherever possible */
53 if( patron && patron.profile )
54 patronProfile = patron.profile.name;
55 if( copy && copy.status )
56 copyStatus = copy.status.name;
57 if( title && title.marc )
58 marcXMLDoc = new XML(title.marc);
62 /* copy the group tree into some other useful data structures */
63 var groupTree = environment.groupTree;
66 flattenGroupTree(groupTree);
73 /* -----------------------------------------------------------------------------
74 Define all of the utility functions
75 ----------------------------------------------------------------------------- */
79 /* useful functions for creating wrappers around system functions */
82 function scratchKey() { return '_' + __scratchKey++; };
83 function scratchPad(key) { return '__SCRATCH.'+ key; }
84 function getScratch(key) { return __SCRATCH[ key ]; }
85 function scratchClear() { for( var o in __SCRATCH ) __SCRATCH[o] = null; }
88 /* note: returns false if the value is 'f' or 'F' ... */
98 /* Utility function for iterating over array */
99 function iterate( arr, callback ) {
100 for( var i = 0; i < arr.length; i++ )
106 * returns a list of items that when passed to the callback
107 * 'func' returned true returns null if none were found
109 function grep( arr, func ) {
117 if(results.length > 0)
124 function flattenGroupTree(node) {
125 if(!node) return null;
126 groupList[node.name] = node;
127 groupIDList[node.id] = node;
128 iterate( node.children,
138 * Returns true if 'child' is equal or descends from 'parent'
139 * @param parent The name of the parent group
140 * @param child The name of the child group
142 function isGroupDescendant( parent, child ) {
143 log_debug("checking descendant p="+parent + " c=" + child);
144 return __isGroupDescendant(
149 function isGroupDescendantId( parentName, childId ) {
150 log_debug("checking descendant ID p="+parentName + " c=" + childId);
151 return __isGroupDescendant(
152 groupList[parentName],
153 groupIDList[childId]);
158 * Returns true if 'child' is equal or descends from 'parent'
159 * @param parent The node of the parent group
160 * @param child The node of the child group
162 function __isGroupDescendant( parent, child ) {
163 if (parent.id == child.id) return true;
165 while( (node = groupIDList[node.parent]) ) {
166 if( node.id == parent.id )
173 function getMARCItemType() {
176 copy.circ_as_type != 'undef' )
177 return copy.circ_as_type;
179 return (marcXMLDoc) ? extractFixedField(marcXMLDoc, 'Type') : "";
183 function isOrgDescendent( parentName, childId ) {
184 var key = scratchKey();
185 __OILS_FUNC_isOrgDescendent(scratchPad(key), parentName, childId);
186 var val = getScratch(key);
187 if( val == '1' ) return true;
191 /* returns the number of unfulfilled holds open on this user */
192 function userHoldCount(userid) {
193 var key = scratchKey();
194 __OILS_FUNC_userHoldCount(scratchPad(key), userid);
195 return getScratch(key);
198 function hasCommonAncestor( org1, org2, depth ) {
199 var key = scratchKey();
200 __OILS_FUNC_hasCommonAncestor(scratchPad(key), org1, org2, depth);
201 var val = getScratch(key);
202 if( val == '1' ) return true;
208 /* useful for testing */
210 log_error("die(): "+msg);
211 log_stderr("die(): "+msg);
218 /* logs a load of info */
219 function log_vars( prefix ) {
220 var str = prefix + ' : ';
223 str += ' Patron=' + patron.id;
224 str += ', Patron_Username='+ patron.usrname;
225 str += ', Patron_Profile_Group='+ patronProfile;
226 str += ', Patron_Fines=' + patronFines;
227 str += ', Patron_OverdueCount=' + patronOverdueCount;
228 str += ', Patron_Items_Out=' + patronItemsOut;
231 str += ', Patron_Barcode=' + patron.card.barcode;
232 str += ', Patron_Library=' + patron.home_ou.name;
236 if(requestor.id != patron.id)
237 str+= ' Requestor='+requestor.usrname;
240 str += ', Copy=' + copy.id;
241 str += ', Copy_Barcode=' + copy.barcode;
242 str += ', Copy_status=' + copyStatus;
243 str += (copy.circ_modifier) ? ', Circ_Mod=' + copy.circ_modifier : '';
246 str += ', Circ_Lib=' + copy.circ_lib.shortname;
247 str += ', Copy_location=' + copy.location.name;
252 str += ', Item_Owning_lib=' + volume.owning_lib;
253 str += ', Volume=' + volume.id;
256 if(title) str += ', Record=' + title.id;
259 str += ', Record_Descriptor=' + recDescriptor.id;
260 str += ', Item_Type=' + recDescriptor.item_type;
261 str += ', Item_Form=' + recDescriptor.item_form;
262 str += ', Item_Lang=' + recDescriptor.item_lang;
263 str += ', Item_Audience=' + recDescriptor.audience;
266 str += ', Is_Renewal: ' + ( (isTrue(isRenewal)) ? "yes" : "no" );
267 str += ', Is_Precat: ' + ( (isTrue(isPrecat)) ? "yes" : "no" );
268 str += (holdRequestLib) ? ', Hold_request_lib=' + holdRequestLib.shortname : '';
269 str += (holdPickupLib) ? ', Hold_Pickup_Lib=' + holdPickupLib : '';
277 * Returns config information for the requested group. If
278 * no config info exists for the requested group, then this
279 * function searches up the tree to find the config info
280 * for the nearest ancestor
281 * @param The name of the group who's config info to return
283 function findGroupConfig(name) {
284 if(!name) return null;
285 var node = groupList[name];
287 if( GROUP_CONFIG[node.name] ) {
288 debugGroupConfig(name, node.name, GROUP_CONFIG[node.name]);
289 return GROUP_CONFIG[node.name];
291 } while( (node = groupIDList[node.parent]) );
296 /** prints out the settings for the given group config **/
297 function debugGroupConfig(name, foundName, config) {
299 var str = "findGroupConfig('"+name+"'): returning config info for '"+ foundName +"': ";
300 for( var i in config )
301 str += i + '=' + config[i] + ' ';