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;
46 /* create some new vars based on the data we have wherever possible */
51 if( patron && patron.profile )
52 patronProfile = patron.profile.name;
53 if( copy && copy.status )
54 copyStatus = copy.status.name;
55 if( title && title.marc )
56 marcXMLDoc = new XML(title.marc);
60 /* copy the group tree into some other useful data structures */
61 var groupTree = environment.groupTree;
64 flattenGroupTree(groupTree);
71 /* -----------------------------------------------------------------------------
72 Define all of the utility functions
73 ----------------------------------------------------------------------------- */
77 /* useful functions for creating wrappers around system functions */
80 function scratchKey() { return '_' + __scratchKey++; };
81 function scratchPad(key) { return '__SCRATCH.'+ key; }
82 function getScratch(key) { return __SCRATCH[ key ]; }
83 function scratchClear() { for( var o in __SCRATCH ) __SCRATCH[o] = null; }
86 /* note: returns false if the value is 'f' or 'F' ... */
96 /* Utility function for iterating over array */
97 function iterate( arr, callback ) {
98 for( var i = 0; i < arr.length; i++ )
104 * returns a list of items that when passed to the callback
105 * 'func' returned true returns null if none were found
107 function grep( arr, func ) {
115 if(results.length > 0)
122 function flattenGroupTree(node) {
123 if(!node) return null;
124 groupList[node.name] = node;
125 groupIDList[node.id] = node;
126 iterate( node.children,
136 * Returns true if 'child' is equal or descends from 'parent'
137 * @param parent The name of the parent group
138 * @param child The name of the child group
140 function isGroupDescendant( parent, child ) {
141 log_debug("checking descendant p="+parent + " c=" + child);
142 return __isGroupDescendant(
150 * Returns true if 'child' is equal or descends from 'parent'
151 * @param parent The node of the parent group
152 * @param child The node of the child group
154 function __isGroupDescendant( parent, child ) {
155 if (parent.id == child.id) return true;
157 while( (node = groupIDList[node.parent]) ) {
158 if( node.id == parent.id )
165 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 function hasCommonAncestor( org1, org2, depth ) {
185 var key = scratchKey();
186 __OILS_FUNC_hasCommonAncestor(scratchPad(key), org1, org2, depth);
187 var val = getScratch(key);
188 if( val == '1' ) return true;
194 /* useful for testing */
196 log_error("die(): "+msg);
197 log_stderr("die(): "+msg);
205 - at some point we should add a library of objects that map
206 codes to names (item_form, item_type, etc.)
207 load_lib('item_form_map.js');
208 var form_name = item_form_map[env.record_descriptor.item_form];
213 /* logs a load of info */
214 function log_vars( prefix ) {
215 var str = prefix + ' : ';
218 str += ' Patron=' + patron.id;
219 str += ', Patron Username='+ patron.usrname;
220 str += ', Patron Profile Group='+ patronProfile;
221 str += ', Patron Fines=' + patronFines;
222 str += ', Patron OverdueCount=' + patronOverdueCount;
223 str += ', Patron Items Out=' + patronItemsOut;
226 str += ', Patron Barcode=' + patron.card.barcode;
227 str += ', Patron Library=' + patron.home_ou.name;
232 str += ', Copy=' + copy.id;
233 str += ', Copy Barcode=' + copy.barcode;
234 str += ', Copy status=' + copyStatus;
237 str += ', Circ Lib=' + copy.circ_lib.shortname;
238 str += ', Copy location=' + copy.location.name;
242 if(volume) str += ', Volume=' + volume.id;
243 if(title) str += ', Record=' + title.id;
246 str += ', Record Descriptor=' + recDescriptor.id;
247 str += ', Item Type=' + recDescriptor.item_type;
248 str += ', Item Form=' + recDescriptor.item_form;
249 str += ', Item Lang=' + recDescriptor.item_lang;
250 str += ', Item Audience=' + recDescriptor.audience;
253 str += ' Is Renewal: ' + ( (isTrue(isRenewal)) ? "yes" : "no" );
254 str += ' Is Precat: ' + ( (isTrue(isPrecat)) ? "yes" : "no" );
255 str += (holdRequestLib) ? ' Hold request lib is ' + holdRequestLib.shortname : '';