[open-ils-commits] r693 - conifer/trunk/circ (artunit)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Sep 30 23:34:31 EDT 2009


Author: artunit
Date: 2009-09-30 23:34:28 -0400 (Wed, 30 Sep 2009)
New Revision: 693

Modified:
   conifer/trunk/circ/circ_duration.js
   conifer/trunk/circ/circ_duration_OSTMA.js
   conifer/trunk/circ/circ_duration_OWA.js
   conifer/trunk/circ/circ_duration_OWAL.js
   conifer/trunk/circ/circ_lib.js
Log:
remove date stamp in logging, leave for development, no luck on opening script file error

Modified: conifer/trunk/circ/circ_duration.js
===================================================================
--- conifer/trunk/circ/circ_duration.js	2009-09-30 18:12:51 UTC (rev 692)
+++ conifer/trunk/circ/circ_duration.js	2009-10-01 03:34:28 UTC (rev 693)
@@ -1,84 +1,87 @@
-function go(){
-
-load_lib('circ/circ_item_config.js');
-load_lib('JSON_v1.js');
-log_vars('circ_duration');
-
-var currentTime = new Date();
-var debugStamp = "circ" + (currentTime.getMonth() + 1) + "" +
-	"" + currentTime.getDate() + "" + currentTime.getFullYear() +
-	": ";
-
-
-log_info(debugStamp + "location identified as " + currentLocation.shortname);
-
-try {   
-	/* load circ rules for specific institutions */
-	var circ_duration_institution_file = 'circ/circ_duration_' + currentLocation.shortname + '.js';
-	load_lib(circ_duration_institution_file);
-
-	log_error(circ_duration_institution_file);
-
-	/* if an institution specific script was loaded, then stop */
-	if (result.durationRule) return;
-} catch (e) {
-	// fall through to system-wide defaults
-	log_info("circ0814: error loading " + e);
-}
-
-/* treat pre-cat copies like vanilla books */
-if( isTrue(isPrecat) ) {
-	log_info("pre-cat copy getting duration defaults...");
-	result.durationRule			= 'default';
-	result.recurringFinesRule	= 'default';
-	result.maxFine	   			= 'default'
-	return;
-}
-
-
-/* grab the config from the config script */
-var config = getItemConfig();
-var itemForm	= (marcXMLDoc) ? extractFixedField(marcXMLDoc,'Form') : "";
-
-
-/* ----------------------------------------------------------------------------- 
-	Now set the rule values based on the config.  If there is no configured info
-	on this copy, fall back on defaults.
-	----------------------------------------------------------------------------- */
-if( config ) {
-
-	log_info("config exists");
-	log_debug("circ_duration found a config for the copy");
-	result.durationRule			= config.durationRule;
-	result.recurringFinesRule	= config.recurringFinesRule;
-	result.maxFine			    = config.maxFine;
-
-} else {
-	log_info("falling back to default");
-
-	result.durationRule = 'default';
-	result.recurringFinesRule = 'default';
-	result.maxFine = 'default';
-}
-
-if (patronProfile == 'Faculty') {
-	result.durationRule = '120_days_2_renew';
-}
-if (patronProfile == 'Graduate') {
-	result.durationRule = '120_days_2_renew';
-}
-if (patronProfile == 'Undergraduate') {
-	result.durationRule = '3_weeks_2_renew';
-}
-if (patronProfile == 'Staff members') {
-	result.durationRule = '3_weeks_2_renew';
-}
-if (patronProfile == 'Readers') {
-	result.durationRule = '3_weeks_2_renew';
-}
-
-
-log_info('final duration results: ' + 
-    result.durationRule + ' : ' + result.recurringFinesRule + ' : ' + result.maxFine );
-
-} go();
+function go(){
+
+load_lib('circ/circ_item_config.js');
+load_lib('JSON_v1.js');
+log_vars('circ_duration');
+
+/*
+var currentTime = new Date();
+var debugStamp = "circ" + (currentTime.getMonth() + 1) + "" +
+	"" + currentTime.getDate() + "" + currentTime.getFullYear() +
+	": ";
+*/
+
+
+//log_info(debugStamp + "location identified as " + currentLocation.shortname);
+
+try {   
+	/* load circ rules for specific institutions */
+	var circ_duration_institution_file = 'circ/circ_duration_' + currentLocation.shortname + '.js';
+	log_info('loading ' + circ_duration_institution_file);
+	load_lib(circ_duration_institution_file);
+
+	log_error(circ_duration_institution_file);
+
+	/* if an institution specific script was loaded, then stop */
+	if (result.durationRule) return;
+} catch (e) {
+	// fall through to system-wide defaults
+	log_info("error loading " + e);
+}
+
+/* treat pre-cat copies like vanilla books */
+if( isTrue(isPrecat) ) {
+	//log_info("pre-cat copy getting duration defaults...");
+	result.durationRule			= 'default';
+	result.recurringFinesRule	= 'default';
+	result.maxFine	   			= 'default'
+	return;
+}
+
+
+/* grab the config from the config script */
+var config = getItemConfig();
+var itemForm	= (marcXMLDoc) ? extractFixedField(marcXMLDoc,'Form') : "";
+
+
+/* ----------------------------------------------------------------------------- 
+	Now set the rule values based on the config.  If there is no configured info
+	on this copy, fall back on defaults.
+	----------------------------------------------------------------------------- */
+if( config ) {
+
+	//log_info("config exists");
+	log_debug("circ_duration found a config for the copy");
+	result.durationRule			= config.durationRule;
+	result.recurringFinesRule	= config.recurringFinesRule;
+	result.maxFine			    = config.maxFine;
+
+} else {
+	//log_info("falling back to default");
+
+	result.durationRule = 'default';
+	result.recurringFinesRule = 'default';
+	result.maxFine = 'default';
+}
+
+if (patronProfile == 'Faculty') {
+	result.durationRule = '120_days_2_renew';
+}
+if (patronProfile == 'Graduate') {
+	result.durationRule = '120_days_2_renew';
+}
+if (patronProfile == 'Undergraduate') {
+	result.durationRule = '3_weeks_2_renew';
+}
+if (patronProfile == 'Staff members') {
+	result.durationRule = '3_weeks_2_renew';
+}
+if (patronProfile == 'Readers') {
+	result.durationRule = '3_weeks_2_renew';
+}
+
+
+log_info('final duration results: ' + 
+    result.durationRule + ' : ' + result.recurringFinesRule + ' : ' + result.maxFine );
+
+} go();

Modified: conifer/trunk/circ/circ_duration_OSTMA.js
===================================================================
--- conifer/trunk/circ/circ_duration_OSTMA.js	2009-09-30 18:12:51 UTC (rev 692)
+++ conifer/trunk/circ/circ_duration_OSTMA.js	2009-10-01 03:34:28 UTC (rev 693)
@@ -1,3 +1,4 @@
+/*
 var currentTime = new Date();
 var debugStamp = "circ_duraction_test" + (currentTime.getMonth() + 1) + "" +
         "" + currentTime.getDate() + "" + currentTime.getFullYear() +
@@ -2,4 +3,5 @@
         ": ";
+*/
 
-log_info(debugStamp + "here for OSTMA");
+log_info("here for OSTMA");
 

Modified: conifer/trunk/circ/circ_duration_OWA.js
===================================================================
--- conifer/trunk/circ/circ_duration_OWA.js	2009-09-30 18:12:51 UTC (rev 692)
+++ conifer/trunk/circ/circ_duration_OWA.js	2009-10-01 03:34:28 UTC (rev 693)
@@ -1,97 +1,99 @@
-// circ duration rules for Windsor Leddy (OWA)
-
-/* we use a date based identifier to pick up values in the log */
-var currentTime = new Date();
-var debugStamp = "circ" + (currentTime.getMonth() + 1) + "" +
-        "" + currentTime.getDate() + "" + currentTime.getFullYear() +
-        ": ";
-
-/* set item type defaults - if the either the patron group or the circ modifier
-   is missing or invalid, these settings will be used */
-
-// do these first two have any significance for us?
-result.SIPMediaType = '001';
-result.magneticMedia = 'f';
-
-/* if result.durationRule is not modified for a patron group, set default
- * this value will be used for all circ overrides! */
-result.durationRule = 'non_circ';
-
-// for fines, set the most common value here
-result.recurringFinesRule = 'OWA_daily';
-result.maxFine = 'OWA_normal';
-
-/* adjust rules by patron group and circ modifier */
-
-log_info(debugStamp + 'patronProfile is ' + patronProfile + ' - modifier ' + copy.circ_modifier);
-
-if (isValidPatron(patronProfile)) {
-    var temp_array = patronProfile.split(" ");
-    var profileFirst = temp_array[0];
-    
-    switch(copy.circ_modifier) {
-        case 'CD MUSIC':
-            result.durationRule = 'OWA_audiovisual';
-            break;
-        case 'CIRC':
-            result.durationRule = 'OWA_' + profileFirst;
-            break;
-        case 'CIRC SHORT':
-            result.durationRule = 'OWA_short';
-            result.recurringFinesRule = 'OWA_daily_short';
-            result.maxFine = 'OWA_short';
-            break;
-        case 'CRC MEDIA':
-            result.durationRule = 'OWA_sevenday';
-            break;
-        case 'CRC SPEC':
-            result.durationRule = 'OWA_' + profileFirst;
-            break;
-        case 'CRC TEXT':
-            result.durationRule = 'OWA_' + profileFirst;
-            break;
-        case 'DOC':
-            result.durationRule = 'OWA_' + profileFirst;
-            break;
-        case 'DVD VIDEO':
-            result.durationRule = 'OWA_audiovisual';
-            break;
-        case 'MEDIA':
-            result.durationRule = 'OWA_' + profileFirst;
-            break;
-        case 'MFORM':
-            result.durationRule = 'OWA_' + profileFirst;
-            break;
-        case 'REF':
-            result.durationRule = 'OWA_sevenday';
-            break;
-        case 'RSV1':
-            result.durationRule = 'OWA_rsv_oneday';
-            result.recurringFinesRule = 'OWA_daily_rsv';
-            result.maxFine = 'OWA_rsv';
-            break;
-        case 'RSV2':
-            result.durationRule = 'OWA_rsv_twohour';
-            result.recurringFinesRule = 'OWA_hourly_rsv';
-            result.maxFine = 'OWA_rsv';
-            break;
-        case 'RSV3':
-            result.durationRule = 'OWA_rsv_threeday';
-            result.recurringFinesRule = 'OWA_daily_rsv';
-            result.maxFine = 'OWA_rsv';
-            break;
-        case 'RSV7':
-            result.durationRule = 'OWA_rsv_sevenday';
-            result.recurringFinesRule = 'OWA_daily_rsv';
-            result.maxFine = 'OWA_rsv';
-            break;
-        case 'SER':
-            result.durationRule = 'OWA_serials';
-            result.recurringFinesRule = 'OWA_daily_serials';
-            break;
-        case 'THESIS':
-            result.durationRule = 'OWA_' + profileFirst;
-            break;
-    }
-}
-log_info("circ0814 - results: " + result.durationRule);
+// circ duration rules for Windsor Leddy (OWA)
+
+/* we use a date based identifier to pick up values in the log */
+/*
+var currentTime = new Date();
+var debugStamp = "circ" + (currentTime.getMonth() + 1) + "" +
+        "" + currentTime.getDate() + "" + currentTime.getFullYear() +
+        ": ";
+*/
+
+/* set item type defaults - if the either the patron group or the circ modifier
+   is missing or invalid, these settings will be used */
+
+// do these first two have any significance for us?
+result.SIPMediaType = '001';
+result.magneticMedia = 'f';
+
+/* if result.durationRule is not modified for a patron group, set default
+ * this value will be used for all circ overrides! */
+result.durationRule = 'non_circ';
+
+// for fines, set the most common value here
+result.recurringFinesRule = 'OWA_daily';
+result.maxFine = 'OWA_normal';
+
+/* adjust rules by patron group and circ modifier */
+
+log_info('patronProfile is ' + patronProfile + ' - modifier ' + copy.circ_modifier);
+
+if (isValidPatron(patronProfile)) {
+    var temp_array = patronProfile.split(" ");
+    var profileFirst = temp_array[0];
+    
+    switch(copy.circ_modifier) {
+        case 'CD MUSIC':
+            result.durationRule = 'OWA_audiovisual';
+            break;
+        case 'CIRC':
+            result.durationRule = 'OWA_' + profileFirst;
+            break;
+        case 'CIRC SHORT':
+            result.durationRule = 'OWA_short';
+            result.recurringFinesRule = 'OWA_daily_short';
+            result.maxFine = 'OWA_short';
+            break;
+        case 'CRC MEDIA':
+            result.durationRule = 'OWA_sevenday';
+            break;
+        case 'CRC SPEC':
+            result.durationRule = 'OWA_' + profileFirst;
+            break;
+        case 'CRC TEXT':
+            result.durationRule = 'OWA_' + profileFirst;
+            break;
+        case 'DOC':
+            result.durationRule = 'OWA_' + profileFirst;
+            break;
+        case 'DVD VIDEO':
+            result.durationRule = 'OWA_audiovisual';
+            break;
+        case 'MEDIA':
+            result.durationRule = 'OWA_' + profileFirst;
+            break;
+        case 'MFORM':
+            result.durationRule = 'OWA_' + profileFirst;
+            break;
+        case 'REF':
+            result.durationRule = 'OWA_sevenday';
+            break;
+        case 'RSV1':
+            result.durationRule = 'OWA_rsv_oneday';
+            result.recurringFinesRule = 'OWA_daily_rsv';
+            result.maxFine = 'OWA_rsv';
+            break;
+        case 'RSV2':
+            result.durationRule = 'OWA_rsv_twohour';
+            result.recurringFinesRule = 'OWA_hourly_rsv';
+            result.maxFine = 'OWA_rsv';
+            break;
+        case 'RSV3':
+            result.durationRule = 'OWA_rsv_threeday';
+            result.recurringFinesRule = 'OWA_daily_rsv';
+            result.maxFine = 'OWA_rsv';
+            break;
+        case 'RSV7':
+            result.durationRule = 'OWA_rsv_sevenday';
+            result.recurringFinesRule = 'OWA_daily_rsv';
+            result.maxFine = 'OWA_rsv';
+            break;
+        case 'SER':
+            result.durationRule = 'OWA_serials';
+            result.recurringFinesRule = 'OWA_daily_serials';
+            break;
+        case 'THESIS':
+            result.durationRule = 'OWA_' + profileFirst;
+            break;
+    }
+}
+log_info("circ0814 - results: " + result.durationRule);

Modified: conifer/trunk/circ/circ_duration_OWAL.js
===================================================================
--- conifer/trunk/circ/circ_duration_OWAL.js	2009-09-30 18:12:51 UTC (rev 692)
+++ conifer/trunk/circ/circ_duration_OWAL.js	2009-10-01 03:34:28 UTC (rev 693)
@@ -1,78 +1,80 @@
-// circ duration rules for Windsor Law (OWAL)
-
-/* we use a date based identifier to pick up values in the log */
-var currentTime = new Date();
-var debugStamp = "circ" + (currentTime.getMonth() + 1) + "" +
-        "" + currentTime.getDate() + "" + currentTime.getFullYear() +
-        ": ";
-
-/* set item type defaults - if the either the patron group or the circ modifier
- * is missing or invalid, these settings will be used */
-
-// do these first two have any significance for us?
-result.SIPMediaType = '001';
-result.magneticMedia = 'f';
-
-/* if result.durationRule is not modified for a patron group, set default
- * this value will be used for all circ overrides! */
-result.durationRule = 'non_circ';
-
-// for fines, set the most common value here
-result.recurringFinesRule = 'OWAL_daily';
-result.maxFine = 'OWAL_normal';
-
-/* adjust rules by patron group and circ modifier */
-
-log_info(debugStamp + 'patronProfile is ' + patronProfile + ' - modifier ' + copy.circ_modifier);
-
-if (isValidPatron(patronProfile)) {
-    var temp_array = patronProfile.split(" ");
-    var profileFirst = temp_array[0];
-
-    if (patronProfile == 'Readers' && patron.home_ou.shortname != 'OWAL') {
-        // use override value - Non-Law Readers can borrow nothing
-    } else if (patronProfile == 'Readers' && copy.circ_modifier == 'LAW_MONO') {
-        result.durationRule = 'OWAL_' + profileFirst;  // Law Readers can only borrow LAW_MONO items
-    } else {
-        switch(copy.circ_modifier) {
-            case 'LAW MONO':
-                result.durationRule = 'OWAL_' + profileFirst;
-                break;
-            case 'LAW NOCIRC':
-                // use override value
-                break;
-            case 'LAW RES1D':
-                result.durationRule = 'OWAL_rsv_oneday';
-                result.recurringFinesRule = 'OWAL_hourly';
-                break;
-            case 'LAW RES3D':
-                result.durationRule = 'OWAL_rsv_threeday';
-                result.recurringFinesRule = 'OWAL_hourly';
-                break;
-            case 'LAW RES3H':
-                result.durationRule = 'OWAL_rsv_threehour';
-                result.recurringFinesRule = 'OWAL_hourly';
-                break;
-            case 'LAW RES5H':
-                result.durationRule = 'OWAL_rsv_fivehour';
-                result.recurringFinesRule = 'OWAL_hourly';
-                break;
-            case 'LAW SERIAL':
-                // Faculty exceptions handled below
-                break;
-        }
-    }
-    //exceptions for Faculty
-    if (patronProfile == "Faculty") {
-        if (copy.circ_modifier == 'LAW SERIAL') {
-            result.durationRule = 'OWAL_Faculty_serials';       // all Faculty can borrow serials
-        }
-        if (patron.home_ou.shortname == 'OWAL') {
-            result.recurringFinesRule = 'free';                // Law Faculty pay no fines
-            if (copy.circ_modifier.slice(0, 6) == 'LAW RES') { 
-                result.durationRule = 'OWAL_rsv_threeday';      // Law Faculty get all reserve items for three days
-            }
-        }
-    }
-}
-log_info("circ0814 - results: " + result.durationRule);
+// circ duration rules for Windsor Law (OWAL)
+
+/* we use a date based identifier to pick up values in the log */
+/*
+var currentTime = new Date();
+var debugStamp = "circ" + (currentTime.getMonth() + 1) + "" +
+        "" + currentTime.getDate() + "" + currentTime.getFullYear() +
+        ": ";
+*/
+
+/* set item type defaults - if the either the patron group or the circ modifier
+ * is missing or invalid, these settings will be used */
+
+// do these first two have any significance for us?
+result.SIPMediaType = '001';
+result.magneticMedia = 'f';
+
+/* if result.durationRule is not modified for a patron group, set default
+ * this value will be used for all circ overrides! */
+result.durationRule = 'non_circ';
+
+// for fines, set the most common value here
+result.recurringFinesRule = 'OWAL_daily';
+result.maxFine = 'OWAL_normal';
+
+/* adjust rules by patron group and circ modifier */
+
+log_info('patronProfile is ' + patronProfile + ' - modifier ' + copy.circ_modifier);
+
+if (isValidPatron(patronProfile)) {
+    var temp_array = patronProfile.split(" ");
+    var profileFirst = temp_array[0];
+
+    if (patronProfile == 'Readers' && patron.home_ou.shortname != 'OWAL') {
+        // use override value - Non-Law Readers can borrow nothing
+    } else if (patronProfile == 'Readers' && copy.circ_modifier == 'LAW_MONO') {
+        result.durationRule = 'OWAL_' + profileFirst;  // Law Readers can only borrow LAW_MONO items
+    } else {
+        switch(copy.circ_modifier) {
+            case 'LAW MONO':
+                result.durationRule = 'OWAL_' + profileFirst;
+                break;
+            case 'LAW NOCIRC':
+                // use override value
+                break;
+            case 'LAW RES1D':
+                result.durationRule = 'OWAL_rsv_oneday';
+                result.recurringFinesRule = 'OWAL_hourly';
+                break;
+            case 'LAW RES3D':
+                result.durationRule = 'OWAL_rsv_threeday';
+                result.recurringFinesRule = 'OWAL_hourly';
+                break;
+            case 'LAW RES3H':
+                result.durationRule = 'OWAL_rsv_threehour';
+                result.recurringFinesRule = 'OWAL_hourly';
+                break;
+            case 'LAW RES5H':
+                result.durationRule = 'OWAL_rsv_fivehour';
+                result.recurringFinesRule = 'OWAL_hourly';
+                break;
+            case 'LAW SERIAL':
+                // Faculty exceptions handled below
+                break;
+        }
+    }
+    //exceptions for Faculty
+    if (patronProfile == "Faculty") {
+        if (copy.circ_modifier == 'LAW SERIAL') {
+            result.durationRule = 'OWAL_Faculty_serials';       // all Faculty can borrow serials
+        }
+        if (patron.home_ou.shortname == 'OWAL') {
+            result.recurringFinesRule = 'free';                // Law Faculty pay no fines
+            if (copy.circ_modifier.slice(0, 6) == 'LAW RES') { 
+                result.durationRule = 'OWAL_rsv_threeday';      // Law Faculty get all reserve items for three days
+            }
+        }
+    }
+}
+log_info("circ0814 - results: " + result.durationRule);

Modified: conifer/trunk/circ/circ_lib.js
===================================================================
--- conifer/trunk/circ/circ_lib.js	2009-09-30 18:12:51 UTC (rev 692)
+++ conifer/trunk/circ/circ_lib.js	2009-10-01 03:34:28 UTC (rev 693)
@@ -1,326 +1,326 @@
-load_lib('catalog/record_type.js');
-load_lib('circ/circ_groups.js');
-load_lib('JSON_v1.js');
-
-
-try {
-	if( environment.copy ) {
-		environment.copy.fetchBestHold = function() {
-			var key = scratchKey();
-			environment.copy.__OILS_FUNC_fetch_best_hold(scratchPad(key));
-			var val = getScratch(key);
-			return (val) ? val : null;
-		}
-	}
-} catch(e) {}
-
-
-/* ----------------------------------------------------------------------------- 
-	Collect all of the global variables
-	----------------------------------------------------------------------------- */
-
-/* the global result object.  Any data returned to the 
-	caller must be put into this object.  */
-var result				= environment.result = {};
-result.event			= 'SUCCESS';
-result.events			= [];
-result.fatalEvents	= [];
-result.infoEvents		= [];
-
-
-/* Pull in any variables passed in from the calling process */
-var copy					= environment.copy;
-var volume				= environment.volume;
-var title				= environment.title;
-var recDescriptor		= environment.titleDescriptor;
-var patron				= environment.patron;
-var patronItemsOut	= environment.patronItemsOut;
-var patronOverdueCount	= environment.patronOverdueCount;
-var patronFines		= environment.patronFines;
-var isRenewal			= environment.isRenewal;
-var isPrecat			= environment.isPrecat;
-var currentLocation	= environment.location;
-var holdRequestLib	= environment.requestLib;
-var holdPickupLib       = environment.pickupLib; /* hold pickup lib */
-var requestor = environment.requestor || patron;
-var newHold = environment.newHold;
-
-
-
-/* create some new vars based on the data we have wherever possible */
-var patronProfile;
-var copyStatus;
-var marcXMLDoc;
-
-if( patron && patron.profile ) 
-	patronProfile = patron.profile.name;
-if( copy && copy.status ) 
-	copyStatus = copy.status.name;
-if( title && title.marc )
-	marcXMLDoc = new XML(title.marc);
-
-
-
-/* copy the group tree into some other useful data structures */
-var groupTree		= environment.groupTree;
-var groupList		= {};
-var groupIDList	= {};
-flattenGroupTree(groupTree);
-
-
-
-
-
-
-/* ----------------------------------------------------------------------------- 
-	Define all of the utility functions
-	----------------------------------------------------------------------------- */
-
-
-
-/* useful functions for creating wrappers around system functions */
-var __scratchKey = 0;
-var __SCRATCH = {};
-function scratchKey()		{ return '_' + __scratchKey++; };
-function scratchPad(key)	{ return '__SCRATCH.'+ key; }
-function getScratch(key)	{ return __SCRATCH[ key ]; }
-function scratchClear()		{ for( var o in __SCRATCH ) __SCRATCH[o] = null; }
-
-
-/* note: returns false if the value is 'f' or 'F' ... */
-function isTrue(d) {
-	if(	d && 
-			d != "0" && 
-			d != "f" &&
-			d != "F" )
-			return true;
-	return false;
-}
-
-/* Utility function for iterating over array */
-function iterate( arr, callback ) {
-	for( var i = 0; i < arr.length; i++ ) 
-		callback(arr[i]);
-}
-
-
-/**
-  * returns a list of items that when passed to the callback 
-  * 'func' returned true returns null if none were found
-  */
-function grep( arr, func ) {
-	var results = [];
-	iterate( arr, 
-		function(d) {
-			if( func(d) ) 
-				results.push(d);
-		}
-	);
-	if(results.length > 0)	
-		return results;
-	return null;
-}
-
-
-
-function flattenGroupTree(node) {
-	if(!node) return null;
-	groupList[node.name] = node;
-	groupIDList[node.id] = node;
-	iterate( node.children,
-		function(n) {
-			flattenGroupTree(n);
-		}
-	);
-}
-
-
-
-/**
-  * Returns true if 'child' is equal or descends from 'parent'
-  * @param parent The name of the parent group
-  * @param child The name of the child group
-  */
-function isGroupDescendant( parent, child ) {
-	log_debug("checking descendant p="+parent + " c=" + child);
-	return __isGroupDescendant(
-		groupList[parent],
-		groupList[child]);
-}
-
-function isGroupDescendantId( parentName, childId ) {
-	log_debug("checking descendant ID p="+parentName + " c=" + childId);
-	return __isGroupDescendant(
-		groupList[parentName],
-		groupIDList[childId]);
-}
-
-
-/**
-  * Returns true if 'child' is equal or descends from 'parent'
-  * @param parent The node of the parent group
-  * @param child The node of the child group
-  */
-function __isGroupDescendant( parent, child ) {
-    if(!(parent && child)) return false;
-	if (parent.id == child.id) return true;
-	var node = child;
-	while( (node = groupIDList[node.parent]) ) {
-		if( node.id == parent.id ) 
-			return true;
-	}
-	return false;
-}
-
-
-function getMARCItemType() {
-	if(	copy &&
-			copy.circ_as_type &&
-			copy.circ_as_type != 'undef' )
-		return copy.circ_as_type;
-	
-	return (marcXMLDoc) ? extractFixedField(marcXMLDoc, 'Type') : "";
-}
-
-
-function isOrgDescendent( parentName, childId ) {
-	var key = scratchKey();
-	__OILS_FUNC_isOrgDescendent(scratchPad(key), parentName, childId);
-	var val = getScratch(key);
-	if( val == '1' ) return true;
-	return false;
-}
-
-/* returns the number of unfulfilled holds open on this user */
-function userHoldCount(userid) {
-   var key = scratchKey();
-   __OILS_FUNC_userHoldCount(scratchPad(key), userid);
-   return getScratch(key);
-}
-
-function hasCommonAncestor( org1, org2, depth ) {
-	var key = scratchKey();
-	__OILS_FUNC_hasCommonAncestor(scratchPad(key), org1, org2, depth);
-	var val = getScratch(key);
-	if( val == '1' ) return true;
-	return false;
-}
-
-/* returns a dictionary of circmod : count for checked out items */
-function checkoutsByCircModifier(userid) {
-    var key = scratchKey();
-    __OILS_FUNC_userCircsByCircmod(scratchPad(key), userid);
-    var val = getScratch(key);
-    return (val) ? val : {};
-}
-
-/* useful for testing */
-function die(msg) {
-	log_error("die(): "+msg);
-	log_stderr("die(): "+msg);
-	var foo = null;
-	var baz = foo.bar;
-}
-
-
-
-/* logs a load of info */
-function log_vars( prefix ) {
-	var str = prefix + ' : ';
-
-	if(patron) {
-		str += ' Patron=' + patron.id;
-		str += ', Patron_Username='+ patron.usrname;
-		str += ', Patron_Profile_Group='+ patronProfile;
-		str += ', Patron_Fines='	+ patronFines;
-		str += ', Patron_OverdueCount='	+ patronOverdueCount;
-		str += ', Patron_Items_Out=' + patronItemsOut;
-
-		try {
-			str += ', Patron_Barcode='	+ patron.card.barcode;
-			str += ', Patron_Library='	+ patron.home_ou.name;
-		} catch(e) {}
-	}
-
-    if(requestor.id != patron.id) 
-        str+= ' Requestor='+requestor.usrname;
-
-	if(copy)	{
-		str += ', Copy=' + copy.id;
-		str += ', Copy_Barcode=' + copy.barcode;
-		str += ', Copy_status='	+ copyStatus;
-      str += (copy.circ_modifier) ? ', Circ_Mod=' + copy.circ_modifier : '';
-
-		try {
-			str += ', Circ_Lib=' + copy.circ_lib.shortname;
-			str += ', Copy_location=' + copy.location.name;
-		} catch(e) {}
-	}
-
-	if(volume) {
-        str += ', Item_Owning_lib=' + volume.owning_lib;
-        str += ', Volume='	+ volume.id;
-    }
-
-	if(title) str += ', Record='	+ title.id;
-
-	if(recDescriptor)	{
-		str += ', Record_Descriptor=' + recDescriptor.id;
-		str += ', Item_Type='			+ recDescriptor.item_type;
-		str += ', Item_Form='			+ recDescriptor.item_form;
-		str += ', Item_Lang='			+ recDescriptor.item_lang;
-		str += ', Item_Audience='		+ recDescriptor.audience;
-	}
-
-	str += ', Is_Renewal: '	+ ( (isTrue(isRenewal)) ? "yes" : "no" );
-	str += ', Is_Precat: '	+ ( (isTrue(isPrecat)) ? "yes" : "no" );
-	str += (holdRequestLib) ? ', Hold_request_lib=' + holdRequestLib.shortname : '';
-    str += (holdPickupLib) ? ', Hold_Pickup_Lib=' + holdPickupLib : '';
-
-	log_info(str);
-}
-
-
-
-/**
-  * Returns config information for the requested group.  If 
-  * no config info exists for the requested group, then this
-  * function searches up the tree to find the config info 
-  * for the nearest ancestor
-  * @param The name of the group who's config info to return
-  */
-function findGroupConfig(name) {
-	if(!name) return null;
-	var node = groupList[name];
-	do {
-		if( GROUP_CONFIG[node.name] ) {
-			debugGroupConfig(name, node.name, GROUP_CONFIG[node.name]);
-			return GROUP_CONFIG[node.name];
-		}
-	} while( (node = groupIDList[node.parent]) );
-	return null;
-}
-
-
-/** prints out the settings for the given group config **/
-function debugGroupConfig(name, foundName, config) {
-	if(!config) return;
-	var str = "findGroupConfig('"+name+"'): returning config info for '"+ foundName +"': ";
-	for( var i in config ) 
-		str += i + '=' + config[i] + '  ';
-	log_debug(str);
-}
-
-
-/* custom functions for Windsor libraries */
-
-function isValidPatron(patronProfile) {
-    var valid_patrons = ['Faculty', 'Graduate', 'Undergraduate', 'Staff members', 'Readers'];
-    for (var i = 0; i < valid_patrons.length; i++) {
-        if (valid_patrons[i] == patronProfile) {
-            return true;
-        }
-    }
-    return false;
-}
-
+load_lib('catalog/record_type.js');
+load_lib('circ/circ_groups.js');
+load_lib('JSON_v1.js');
+
+
+try {
+	if( environment.copy ) {
+		environment.copy.fetchBestHold = function() {
+			var key = scratchKey();
+			environment.copy.__OILS_FUNC_fetch_best_hold(scratchPad(key));
+			var val = getScratch(key);
+			return (val) ? val : null;
+		}
+	}
+} catch(e) {}
+
+
+/* ----------------------------------------------------------------------------- 
+	Collect all of the global variables
+	----------------------------------------------------------------------------- */
+
+/* the global result object.  Any data returned to the 
+	caller must be put into this object.  */
+var result				= environment.result = {};
+result.event			= 'SUCCESS';
+result.events			= [];
+result.fatalEvents	= [];
+result.infoEvents		= [];
+
+
+/* Pull in any variables passed in from the calling process */
+var copy					= environment.copy;
+var volume				= environment.volume;
+var title				= environment.title;
+var recDescriptor		= environment.titleDescriptor;
+var patron				= environment.patron;
+var patronItemsOut	= environment.patronItemsOut;
+var patronOverdueCount	= environment.patronOverdueCount;
+var patronFines		= environment.patronFines;
+var isRenewal			= environment.isRenewal;
+var isPrecat			= environment.isPrecat;
+var currentLocation	= environment.location;
+var holdRequestLib	= environment.requestLib;
+var holdPickupLib       = environment.pickupLib; /* hold pickup lib */
+var requestor = environment.requestor || patron;
+var newHold = environment.newHold;
+
+
+
+/* create some new vars based on the data we have wherever possible */
+var patronProfile;
+var copyStatus;
+var marcXMLDoc;
+
+if( patron && patron.profile ) 
+	patronProfile = patron.profile.name;
+if( copy && copy.status ) 
+	copyStatus = copy.status.name;
+if( title && title.marc )
+	marcXMLDoc = new XML(title.marc);
+
+
+
+/* copy the group tree into some other useful data structures */
+var groupTree		= environment.groupTree;
+var groupList		= {};
+var groupIDList	= {};
+flattenGroupTree(groupTree);
+
+
+
+
+
+
+/* ----------------------------------------------------------------------------- 
+	Define all of the utility functions
+	----------------------------------------------------------------------------- */
+
+
+
+/* useful functions for creating wrappers around system functions */
+var __scratchKey = 0;
+var __SCRATCH = {};
+function scratchKey()		{ return '_' + __scratchKey++; };
+function scratchPad(key)	{ return '__SCRATCH.'+ key; }
+function getScratch(key)	{ return __SCRATCH[ key ]; }
+function scratchClear()		{ for( var o in __SCRATCH ) __SCRATCH[o] = null; }
+
+
+/* note: returns false if the value is 'f' or 'F' ... */
+function isTrue(d) {
+	if(	d && 
+			d != "0" && 
+			d != "f" &&
+			d != "F" )
+			return true;
+	return false;
+}
+
+/* Utility function for iterating over array */
+function iterate( arr, callback ) {
+	for( var i = 0; i < arr.length; i++ ) 
+		callback(arr[i]);
+}
+
+
+/**
+  * returns a list of items that when passed to the callback 
+  * 'func' returned true returns null if none were found
+  */
+function grep( arr, func ) {
+	var results = [];
+	iterate( arr, 
+		function(d) {
+			if( func(d) ) 
+				results.push(d);
+		}
+	);
+	if(results.length > 0)	
+		return results;
+	return null;
+}
+
+
+
+function flattenGroupTree(node) {
+	if(!node) return null;
+	groupList[node.name] = node;
+	groupIDList[node.id] = node;
+	iterate( node.children,
+		function(n) {
+			flattenGroupTree(n);
+		}
+	);
+}
+
+
+
+/**
+  * Returns true if 'child' is equal or descends from 'parent'
+  * @param parent The name of the parent group
+  * @param child The name of the child group
+  */
+function isGroupDescendant( parent, child ) {
+	log_debug("checking descendant p="+parent + " c=" + child);
+	return __isGroupDescendant(
+		groupList[parent],
+		groupList[child]);
+}
+
+function isGroupDescendantId( parentName, childId ) {
+	log_debug("checking descendant ID p="+parentName + " c=" + childId);
+	return __isGroupDescendant(
+		groupList[parentName],
+		groupIDList[childId]);
+}
+
+
+/**
+  * Returns true if 'child' is equal or descends from 'parent'
+  * @param parent The node of the parent group
+  * @param child The node of the child group
+  */
+function __isGroupDescendant( parent, child ) {
+    if(!(parent && child)) return false;
+	if (parent.id == child.id) return true;
+	var node = child;
+	while( (node = groupIDList[node.parent]) ) {
+		if( node.id == parent.id ) 
+			return true;
+	}
+	return false;
+}
+
+
+function getMARCItemType() {
+	if(	copy &&
+			copy.circ_as_type &&
+			copy.circ_as_type != 'undef' )
+		return copy.circ_as_type;
+	
+	return (marcXMLDoc) ? extractFixedField(marcXMLDoc, 'Type') : "";
+}
+
+
+function isOrgDescendent( parentName, childId ) {
+	var key = scratchKey();
+	__OILS_FUNC_isOrgDescendent(scratchPad(key), parentName, childId);
+	var val = getScratch(key);
+	if( val == '1' ) return true;
+	return false;
+}
+
+/* returns the number of unfulfilled holds open on this user */
+function userHoldCount(userid) {
+   var key = scratchKey();
+   __OILS_FUNC_userHoldCount(scratchPad(key), userid);
+   return getScratch(key);
+}
+
+function hasCommonAncestor( org1, org2, depth ) {
+	var key = scratchKey();
+	__OILS_FUNC_hasCommonAncestor(scratchPad(key), org1, org2, depth);
+	var val = getScratch(key);
+	if( val == '1' ) return true;
+	return false;
+}
+
+/* returns a dictionary of circmod : count for checked out items */
+function checkoutsByCircModifier(userid) {
+    var key = scratchKey();
+    __OILS_FUNC_userCircsByCircmod(scratchPad(key), userid);
+    var val = getScratch(key);
+    return (val) ? val : {};
+}
+
+/* useful for testing */
+function die(msg) {
+	log_error("die(): "+msg);
+	log_stderr("die(): "+msg);
+	var foo = null;
+	var baz = foo.bar;
+}
+
+
+
+/* logs a load of info */
+function log_vars( prefix ) {
+	var str = prefix + ' : ';
+
+	if(patron) {
+		str += ' Patron=' + patron.id;
+		str += ', Patron_Username='+ patron.usrname;
+		str += ', Patron_Profile_Group='+ patronProfile;
+		str += ', Patron_Fines='	+ patronFines;
+		str += ', Patron_OverdueCount='	+ patronOverdueCount;
+		str += ', Patron_Items_Out=' + patronItemsOut;
+
+		try {
+			str += ', Patron_Barcode='	+ patron.card.barcode;
+			str += ', Patron_Library='	+ patron.home_ou.name;
+		} catch(e) {}
+	}
+
+    if(requestor.id != patron.id) 
+        str+= ' Requestor='+requestor.usrname;
+
+	if(copy)	{
+		str += ', Copy=' + copy.id;
+		str += ', Copy_Barcode=' + copy.barcode;
+		str += ', Copy_status='	+ copyStatus;
+      str += (copy.circ_modifier) ? ', Circ_Mod=' + copy.circ_modifier : '';
+
+		try {
+			str += ', Circ_Lib=' + copy.circ_lib.shortname;
+			str += ', Copy_location=' + copy.location.name;
+		} catch(e) {}
+	}
+
+	if(volume) {
+        str += ', Item_Owning_lib=' + volume.owning_lib;
+        str += ', Volume='	+ volume.id;
+    }
+
+	if(title) str += ', Record='	+ title.id;
+
+	if(recDescriptor)	{
+		str += ', Record_Descriptor=' + recDescriptor.id;
+		str += ', Item_Type='			+ recDescriptor.item_type;
+		str += ', Item_Form='			+ recDescriptor.item_form;
+		str += ', Item_Lang='			+ recDescriptor.item_lang;
+		str += ', Item_Audience='		+ recDescriptor.audience;
+	}
+
+	str += ', Is_Renewal: '	+ ( (isTrue(isRenewal)) ? "yes" : "no" );
+	str += ', Is_Precat: '	+ ( (isTrue(isPrecat)) ? "yes" : "no" );
+	str += (holdRequestLib) ? ', Hold_request_lib=' + holdRequestLib.shortname : '';
+    str += (holdPickupLib) ? ', Hold_Pickup_Lib=' + holdPickupLib : '';
+
+	log_info(str);
+}
+
+
+
+/**
+  * Returns config information for the requested group.  If 
+  * no config info exists for the requested group, then this
+  * function searches up the tree to find the config info 
+  * for the nearest ancestor
+  * @param The name of the group who's config info to return
+  */
+function findGroupConfig(name) {
+	if(!name) return null;
+	var node = groupList[name];
+	do {
+		if( GROUP_CONFIG[node.name] ) {
+			debugGroupConfig(name, node.name, GROUP_CONFIG[node.name]);
+			return GROUP_CONFIG[node.name];
+		}
+	} while( (node = groupIDList[node.parent]) );
+	return null;
+}
+
+
+/** prints out the settings for the given group config **/
+function debugGroupConfig(name, foundName, config) {
+	if(!config) return;
+	var str = "findGroupConfig('"+name+"'): returning config info for '"+ foundName +"': ";
+	for( var i in config ) 
+		str += i + '=' + config[i] + '  ';
+	log_debug(str);
+}
+
+
+/* custom functions for Windsor libraries */
+
+function isValidPatron(patronProfile) {
+    var valid_patrons = ['Faculty', 'Graduate', 'Undergraduate', 'Staff members', 'Readers'];
+    for (var i = 0; i < valid_patrons.length; i++) {
+        if (valid_patrons[i] == patronProfile) {
+            return true;
+        }
+    }
+    return false;
+}
+



More information about the open-ils-commits mailing list