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 */
47 /* create some new vars based on the data we have wherever possible */
52 if( patron && patron.profile )
53 patronProfile = patron.profile.name;
54 if( copy && copy.status )
55 copyStatus = copy.status.name;
56 if( title && title.marc )
57 marcXMLDoc = new XML(title.marc);
61 /* copy the group tree into some other useful data structures */
62 var groupTree = environment.groupTree;
65 flattenGroupTree(groupTree);
72 /* -----------------------------------------------------------------------------
73 Define all of the utility functions
74 ----------------------------------------------------------------------------- */
78 /* useful functions for creating wrappers around system functions */
81 function scratchKey() { return '_' + __scratchKey++; };
82 function scratchPad(key) { return '__SCRATCH.'+ key; }
83 function getScratch(key) { return __SCRATCH[ key ]; }
84 function scratchClear() { for( var o in __SCRATCH ) __SCRATCH[o] = null; }
87 /* note: returns false if the value is 'f' or 'F' ... */
97 /* Utility function for iterating over array */
98 function iterate( arr, callback ) {
99 for( var i = 0; i < arr.length; i++ )
105 * returns a list of items that when passed to the callback
106 * 'func' returned true returns null if none were found
108 function grep( arr, func ) {
116 if(results.length > 0)
123 function flattenGroupTree(node) {
124 if(!node) return null;
125 groupList[node.name] = node;
126 groupIDList[node.id] = node;
127 iterate( node.children,
137 * Returns true if 'child' is equal or descends from 'parent'
138 * @param parent The name of the parent group
139 * @param child The name of the child group
141 function isGroupDescendant( parent, child ) {
142 log_debug("checking descendant p="+parent + " c=" + child);
143 return __isGroupDescendant(
151 * Returns true if 'child' is equal or descends from 'parent'
152 * @param parent The node of the parent group
153 * @param child The node of the child group
155 function __isGroupDescendant( parent, child ) {
156 if (parent.id == child.id) return true;
158 while( (node = groupIDList[node.parent]) ) {
159 if( node.id == parent.id )
166 function getMARCItemType() {
169 copy.circ_as_type != 'undef' )
170 return copy.circ_as_type;
172 return (marcXMLDoc) ? extractFixedField(marcXMLDoc, 'Type') : "";
176 function isOrgDescendent( parentName, childId ) {
177 var key = scratchKey();
178 __OILS_FUNC_isOrgDescendent(scratchPad(key), parentName, childId);
179 var val = getScratch(key);
180 if( val == '1' ) return true;
184 /* returns the number of unfulfilled holds open on this user */
185 function userHoldCount(userid) {
186 var key = scratchKey();
187 __OILS_FUNC_userHoldCount(scratchPad(key), userid);
188 return getScratch(key);
191 function hasCommonAncestor( org1, org2, depth ) {
192 var key = scratchKey();
193 __OILS_FUNC_hasCommonAncestor(scratchPad(key), org1, org2, depth);
194 var val = getScratch(key);
195 if( val == '1' ) return true;
201 /* useful for testing */
203 log_error("die(): "+msg);
204 log_stderr("die(): "+msg);
211 /* logs a load of info */
212 function log_vars( prefix ) {
213 var str = prefix + ' : ';
216 str += ' Patron=' + patron.id;
217 str += ', Patron_Username='+ patron.usrname;
218 str += ', Patron_Profile_Group='+ patronProfile;
219 str += ', Patron_Fines=' + patronFines;
220 str += ', Patron_OverdueCount=' + patronOverdueCount;
221 str += ', Patron_Items_Out=' + patronItemsOut;
224 str += ', Patron_Barcode=' + patron.card.barcode;
225 str += ', Patron_Library=' + patron.home_ou.name;
230 str += ', Copy=' + copy.id;
231 str += ', Copy_Barcode=' + copy.barcode;
232 str += ', Copy_status=' + copyStatus;
233 str += (copy.circ_modifier) ? ', Circ_Mod=' + copy.circ_modifier : '';
236 str += ', Circ_Lib=' + copy.circ_lib.shortname;
237 str += ', Copy_location=' + copy.location.name;
242 str += ', Item_Owning_lib=' + volume.owning_lib;
243 str += ', Volume=' + volume.id;
246 if(title) str += ', Record=' + title.id;
249 str += ', Record_Descriptor=' + recDescriptor.id;
250 str += ', Item_Type=' + recDescriptor.item_type;
251 str += ', Item_Form=' + recDescriptor.item_form;
252 str += ', Item_Lang=' + recDescriptor.item_lang;
253 str += ', Item_Audience=' + recDescriptor.audience;
256 str += ', Is_Renewal: ' + ( (isTrue(isRenewal)) ? "yes" : "no" );
257 str += ', Is_Precat: ' + ( (isTrue(isPrecat)) ? "yes" : "no" );
258 str += (holdRequestLib) ? ', Hold_request_lib=' + holdRequestLib.shortname : '';
259 str += (holdPickupLib) ? ', Hold_Pickup_Lib=' + holdPickupLib : '';
267 * Returns config information for the requested group. If
268 * no config info exists for the requested group, then this
269 * function searches up the tree to find the config info
270 * for the nearest ancestor
271 * @param The name of the group who's config info to return
273 function findGroupConfig(name) {
274 if(!name) return null;
275 var node = groupList[name];
277 if( GROUP_CONFIG[node.name] ) {
278 debugGroupConfig(name, node.name, GROUP_CONFIG[node.name]);
279 return GROUP_CONFIG[node.name];
281 } while( (node = groupIDList[node.parent]) );
286 /** prints out the settings for the given group config **/
287 function debugGroupConfig(name, foundName, config) {
289 var str = "findGroupConfig('"+name+"'): returning config info for '"+ foundName +"': ";
290 for( var i in config )
291 str += i + '=' + config[i] + ' ';