1 load_lib('catalog/record_type.js');
2 load_lib('circ/circ_groups.js');
4 /* -----------------------------------------------------------------------------
5 Collect all of the global variables
6 ----------------------------------------------------------------------------- */
8 /* the global result object. Any data returned to the
9 caller must be put into this object. */
10 var result = environment.result = {};
11 result.event = 'SUCCESS';
13 result.fatalEvents = [];
14 result.infoEvents = [];
17 /* Pull in any variables passed in from the calling process */
18 var copy = environment.copy;
19 var volume = environment.volume;
20 var title = environment.title;
21 var recDescriptor = environment.titleDescriptor;
22 var patron = environment.patron;
23 var isRenewal = environment.isRenewal;
24 var patronItemsOut = environment.patronItemsOut;
25 var patronOverdueCount = environment.patronOverdueCount;
26 var patronFines = environment.patronFines;
30 /* create some new vars based on the data we have wherever possible */
35 if( patron && patron.profile )
36 patronProfile = patron.profile.name;
37 if( copy && copy.status )
38 copyStatus = copy.status.name;
39 if( title && title.marc )
40 marcXMLDoc = new XML(title.marc);
45 /* copy the group tree into some other useful data structures */
46 var groupTree = environment.groupTree;
49 flattenGroupTree(groupTree);
57 /* -----------------------------------------------------------------------------
58 Define all of the utility functions
59 ----------------------------------------------------------------------------- */
63 /* useful functions for creating wrappers around system functions */
66 function scratchKey() { return '_' + __scratchKey++; };
67 function scratchPad(key) { return '__SCRATCH.'+ key; }
68 function getScratch(key) { return __SCRATCH[ key ]; }
69 function scratchClear() { for( var o in __SCRATCH ) __SCRATCH[o] = null; }
72 /* note: returns false if the value is 'f' or 'F' ... */
82 /* Utility function for iterating over array */
83 function iterate( arr, callback ) {
84 for( var i = 0; i < arr.length; i++ )
90 * returns a list of items that when passed to the callback
91 * 'func' returned true returns null if none were found
93 function grep( arr, func ) {
101 if(results.length > 0)
108 function flattenGroupTree(node) {
109 if(!node) return null;
110 groupList[node.name] = node;
111 groupIDList[node.id] = node;
112 iterate( node.children,
122 * Returns true if 'child' is equal or descends from 'parent'
123 * @param parent The name of the parent group
124 * @param child The name of the child group
126 function isGroupDescendant( parent, child ) {
127 return __isGroupDescendant(
135 * Returns true if 'child' is equal or descends from 'parent'
136 * @param parent The node of the parent group
137 * @param child The node of the child group
139 function __isGroupDescendant( parent, child ) {
140 if (parent.id == child.id) return true;
142 while( (node = groupIDList[node.parent]) ) {
143 if( node.id == parent.id )
150 function getMARCItemType() {
154 copy.circ_as_type != 'undef' )
155 return copy.circ_as_type;
157 return (marcXMLDoc) ? extractFixedField(marcXMLDoc, 'Type') : "";
161 function isOrgDescendent( parentName, childId ) {
162 var key = scratchKey();
163 __OILS_FUNC_isOrgDescendent(scratchPad(key), parentName, childId);
164 var val = getScratch(key);
165 if( val == '1' ) return true;
173 - at some point we should add a library of objects that map
174 codes to names (item_form, item_type, etc.)
175 load_lib('item_form_map.js');
176 var form_name = item_form_map[env.record_descriptor.item_form];
181 /* logs a load of info */
182 function log_vars( prefix ) {
183 var str = prefix + ' : ';
186 str += ' Patron=' + patron.id;
187 str += ', Patron Barcode=' + patron.card.barcode;
188 str += ', Patron Username='+ patron.usrname;
189 str += ', Patron Profile Group='+ patronProfile;
190 str += ', Patron Library=' + patron.home_ou.name;
191 str += ', Patron Fines=' + patronFines;
192 str += ', Patron OverdueCount=' + patronOverdueCount;
193 str += ', Patron Items Out=' + patronItemsOut;
197 str += ', Copy=' + copy.id;
198 str += ', Copy Barcode=' + copy.barcode;
199 str += ', Copy status=' + copyStatus;
200 str += ', Copy location=' + copy.location.name;
201 str += ', Circ Lib=' + copy.circ_lib.shortname;
204 if(volume) str += ', Volume=' + volume.id;
205 if(title) str += ', Record=' + title.id;
208 str += ', Record Descriptor=' + recDescriptor.id;
209 str += ', Item Type=' + recDescriptor.item_type;
210 str += ', Item Form=' + recDescriptor.item_form;
211 str += ', Item Lang=' + recDescriptor.item_lang;
212 str += ', Item Audience=' + recDescriptor.audience;
215 str += ' Is Renewal: ' + ( (isTrue(isRenewal)) ? "yes" : "no" );