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);
51 /* copy the org list into some other useful data structures */
52 var orgList = environment.orgList;
58 /* -----------------------------------------------------------------------------
59 Define all of the utility functions
60 ----------------------------------------------------------------------------- */
64 /* useful functions for creating wrappers around system functions */
67 function scratchKey() { return '_' + __scratchKey++; };
68 function scratchPad(key) { return '__SCRATCH.'+ key; }
69 function getScratch(key) { return __SCRATCH[ key ]; }
70 function scratchClear() { for( var o in __SCRATCH ) __SCRATCH[o] = null; }
73 /* note: returns false if the value is 'f' or 'F' ... */
83 /* Utility function for iterating over array */
84 function iterate( arr, callback ) {
85 for( var i = 0; i < arr.length; i++ )
91 * returns a list of items that when passed to the callback
92 * 'func' returned true returns null if none were found
94 function grep( arr, func ) {
102 if(results.length > 0)
109 function flattenGroupTree(node) {
110 if(!node) return null;
111 groupList[node.name] = node;
112 groupIDList[node.id] = node;
113 iterate( node.children,
123 * Returns true if 'child' is equal or descends from 'parent'
124 * @param parent The name of the parent group
125 * @param child The name of the child group
127 function isGroupDescendant( parent, child ) {
128 return __isGroupDescendant(
136 * Returns true if 'child' is equal or descends from 'parent'
137 * @param parent The node of the parent group
138 * @param child The node of the child group
140 function __isGroupDescendant( parent, child ) {
141 if (parent.id == child.id) return true;
143 while( (node = groupIDList[node.parent]) ) {
144 if( node.id == parent.id )
151 function getMARCItemType() {
155 copy.circ_as_type != 'undef' )
156 return copy.circ_as_type;
158 return (marcXMLDoc) ? extractFixedField(marcXMLDoc, 'Type') : "";
161 function __is_org_descendant( parent, child ) {
162 while( child = grep( function(x){ x.id == child.parent_ou }, orgList ) ) {
163 if (child[0].id == parent.id) return true;
168 function isOrgDescendent( parentName, childId ) {
169 var parent = grep( function(x){ x.shortname == parentName }, orgList );
170 var child = grep( function(x){ x.id == childId }, orgList );
172 if (parent) parent = parent[0];
173 if (child) child = child[0];
175 if (!child || !parent) return false;
176 if (child.id == parent.id) return true;
178 return __is_org_descendant( parent, child );
181 function old_isOrgDescendent( parentName, childId ) {
182 var key = scratchKey();
183 __OILS_FUNC_isOrgDescendent(scratchPad(key), parentName, childId);
184 var val = getScratch(key);
185 if( val == '1' ) return true;
193 - at some point we should add a library of objects that map
194 codes to names (item_form, item_type, etc.)
195 load_lib('item_form_map.js');
196 var form_name = item_form_map[env.record_descriptor.item_form];
201 /* logs a load of info */
202 function log_vars( prefix ) {
203 var str = prefix + ' : ';
206 str += ' Patron=' + patron.id;
207 str += ', Patron Barcode=' + patron.card.barcode;
208 str += ', Patron Username='+ patron.usrname;
209 str += ', Patron Profile Group='+ patronProfile;
210 str += ', Patron Library=' + patron.home_ou.name;
211 str += ', Patron Fines=' + patronFines;
212 str += ', Patron OverdueCount=' + patronOverdueCount;
213 str += ', Patron Items Out=' + patronItemsOut;
217 str += ', Copy=' + copy.id;
218 str += ', Copy Barcode=' + copy.barcode;
219 str += ', Copy status=' + copyStatus;
220 str += ', Copy location=' + copy.location.name;
221 str += ', Circ Lib=' + copy.circ_lib.shortname;
224 if(volume) str += ', Volume=' + volume.id;
225 if(title) str += ', Record=' + title.id;
228 str += ', Record Descriptor=' + recDescriptor.id;
229 str += ', Item Type=' + recDescriptor.item_type;
230 str += ', Item Form=' + recDescriptor.item_form;
231 str += ', Item Lang=' + recDescriptor.item_lang;
232 str += ', Item Audience=' + recDescriptor.audience;
235 str += ' Is Renewal: ' + ( (isTrue(isRenewal)) ? "yes" : "no" );