[open-ils-commits] r13889 - trunk/Open-ILS/xul/staff_client/server/patron (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Aug 20 04:01:47 EDT 2009


Author: phasefx
Date: 2009-08-20 04:01:42 -0400 (Thu, 20 Aug 2009)
New Revision: 13889

Modified:
   trunk/Open-ILS/xul/staff_client/server/patron/items.js
Log:
Fix a horrible regression when renewing multiple items at once in Items Out.

Referencing loop variables in Javascript with closures is dangerous, so one strategy is to do something like this:

funcs = [];
for (var i = 0; i < my_array.length; i++ ) {

	/* Bad */
	// funcs.push( function(){ do_something( my_array[i] ); } );
	/* Better */
	funcs.push( function(safe_value){ return function(){ do_something( safe_value ); } }( my_array[i] ) );
}

In our case, our generated function accidentally referenced a value dependent on the loop variable instead of the corresponding argument of the function generator.

So we had multiple async renewal calls that depending on the timing, could try to renew the same item.  To further add insult to injury, this could potentially put the database in an inconsistent 
state wtih duplicate circulations.



Modified: trunk/Open-ILS/xul/staff_client/server/patron/items.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/patron/items.js	2009-08-19 17:30:24 UTC (rev 13888)
+++ trunk/Open-ILS/xul/staff_client/server/patron/items.js	2009-08-20 08:01:42 UTC (rev 13889)
@@ -275,7 +275,7 @@
 					l.setAttribute('value', $("patronStrings").getFormattedString('staff.patron.items.items_renew.renewing',[bc]));
 					x.appendChild(l);
 				}
-				var renew = circ.util.renew_via_barcode( barcode, obj.patron_id, 
+				var renew = circ.util.renew_via_barcode( bc, obj.patron_id, 
 					function(r) {
                         try {
                             if ( (typeof r[0].ilsevent != 'undefined' && r[0].ilsevent == 0) ) {
@@ -297,7 +297,7 @@
                             }
                             obj.refresh(circ_id);
                         } catch(E) {
-   					       obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.items.items_renew.err_in_renew_via_barcode',[barcode]), E);
+   					       obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.items.items_renew.err_in_renew_via_barcode',[bc]), E);
                         }
 					} 
 				);



More information about the open-ils-commits mailing list