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;
44 /* create some new vars based on the data we have wherever possible */
49 if( patron && patron.profile )
50 patronProfile = patron.profile.name;
51 if( copy && copy.status )
52 copyStatus = copy.status.name;
53 if( title && title.marc )
54 marcXMLDoc = new XML(title.marc);
58 /* copy the group tree into some other useful data structures */
59 var groupTree = environment.groupTree;
62 flattenGroupTree(groupTree);
69 /* -----------------------------------------------------------------------------
70 Define all of the utility functions
71 ----------------------------------------------------------------------------- */
75 /* useful functions for creating wrappers around system functions */
78 function scratchKey() { return '_' + __scratchKey++; };
79 function scratchPad(key) { return '__SCRATCH.'+ key; }
80 function getScratch(key) { return __SCRATCH[ key ]; }
81 function scratchClear() { for( var o in __SCRATCH ) __SCRATCH[o] = null; }
84 /* note: returns false if the value is 'f' or 'F' ... */
94 /* Utility function for iterating over array */
95 function iterate( arr, callback ) {
96 for( var i = 0; i < arr.length; i++ )
102 * returns a list of items that when passed to the callback
103 * 'func' returned true returns null if none were found
105 function grep( arr, func ) {
113 if(results.length > 0)
120 function flattenGroupTree(node) {
121 if(!node) return null;
122 groupList[node.name] = node;
123 groupIDList[node.id] = node;
124 iterate( node.children,
134 * Returns true if 'child' is equal or descends from 'parent'
135 * @param parent The name of the parent group
136 * @param child The name of the child group
138 function isGroupDescendant( parent, child ) {
139 return __isGroupDescendant(
147 * Returns true if 'child' is equal or descends from 'parent'
148 * @param parent The node of the parent group
149 * @param child The node of the child group
151 function __isGroupDescendant( parent, child ) {
152 if (parent.id == child.id) return true;
154 while( (node = groupIDList[node.parent]) ) {
155 if( node.id == parent.id )
162 function getMARCItemType() {
166 copy.circ_as_type != 'undef' )
167 return copy.circ_as_type;
169 return (marcXMLDoc) ? extractFixedField(marcXMLDoc, 'Type') : "";
173 function isOrgDescendent( parentName, childId ) {
174 var key = scratchKey();
175 __OILS_FUNC_isOrgDescendent(scratchPad(key), parentName, childId);
176 var val = getScratch(key);
177 if( val == '1' ) return true;
181 /* useful for testing */
183 log_error("die(): "+msg);
184 log_stderr("die(): "+msg);
192 - at some point we should add a library of objects that map
193 codes to names (item_form, item_type, etc.)
194 load_lib('item_form_map.js');
195 var form_name = item_form_map[env.record_descriptor.item_form];
200 /* logs a load of info */
201 function log_vars( prefix ) {
202 var str = prefix + ' : ';
205 str += ' Patron=' + patron.id;
206 str += ', Patron Username='+ patron.usrname;
207 str += ', Patron Profile Group='+ patronProfile;
208 str += ', Patron Fines=' + patronFines;
209 str += ', Patron OverdueCount=' + patronOverdueCount;
210 str += ', Patron Items Out=' + patronItemsOut;
213 str += ', Patron Barcode=' + patron.card.barcode;
214 str += ', Patron Library=' + patron.home_ou.name;
219 str += ', Copy=' + copy.id;
220 str += ', Copy Barcode=' + copy.barcode;
221 str += ', Copy status=' + copyStatus;
224 str += ', Circ Lib=' + copy.circ_lib.shortname;
225 str += ', Copy location=' + copy.location.name;
229 if(volume) str += ', Volume=' + volume.id;
230 if(title) str += ', Record=' + title.id;
233 str += ', Record Descriptor=' + recDescriptor.id;
234 str += ', Item Type=' + recDescriptor.item_type;
235 str += ', Item Form=' + recDescriptor.item_form;
236 str += ', Item Lang=' + recDescriptor.item_lang;
237 str += ', Item Audience=' + recDescriptor.audience;
240 str += ' Is Renewal: ' + ( (isTrue(isRenewal)) ? "yes" : "no" );