[open-ils-commits] r11638 - trunk/Open-ILS/xul/staff_client/server/patron

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Dec 19 17:40:28 EST 2008


Author: erickson
Date: 2008-12-19 17:40:24 -0500 (Fri, 19 Dec 2008)
New Revision: 11638

Modified:
   trunk/Open-ILS/xul/staff_client/server/patron/ue.js
   trunk/Open-ILS/xul/staff_client/server/patron/ue_config.js
Log:
added logic to use the last 4 digits of patron phone number as the default password, based on org setting.  better org setting handling

Modified: trunk/Open-ILS/xul/staff_client/server/patron/ue.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/patron/ue.js	2008-12-19 22:38:40 UTC (rev 11637)
+++ trunk/Open-ILS/xul/staff_client/server/patron/ue.js	2008-12-19 22:40:24 UTC (rev 11638)
@@ -12,6 +12,7 @@
 var netLevelsCache			= {};
 var orgSettings             = [];
 //var guardianNote				= null;
+var uEditUsePhonePw = false;
 
 if(!window.xulG) var xulG = null;
 
@@ -139,10 +140,17 @@
 	var usr = cgi.param('usr'); 
 	if (xulG) if (xulG.usr) usr = xulG.usr;
 	if (xulG) if (xulG.params) if (xulG.params.usr) usr = xulG.params.usr;
+
+    orgSettings = fetchBatchOrgSetting(USER.ws_ou(), [
+        'global.juvenile_age_threshold',
+        'patron.password.use_phone'
+    ]);
+
+    uEditUsePhonePw = (orgSettings['patron.password.use_phone'] && 
+        orgSettings['patron.password.use_phone'].value);
+
 	patron = fetchFleshedUser(usr);
 	if(!patron) patron = uEditNewPatron(); 
-
-    orgSettings = fetchBatchOrgSetting(USER.ws_ou(), ['global.juvenile_age_threshold']);
 	
 	uEditDraw( 
 		uEditFetchIdentTypes(),
@@ -244,6 +252,7 @@
 }
 
 function uEditMakeRandomPw(patron) {
+    if(uEditUsePhonePw) return;
 	var rand  = Math.random();
 	rand = parseInt(rand * 10000) + '';
 	while(rand.length < 4) rand += '0';
@@ -253,8 +262,20 @@
 	return rand;
 }
 
-function uEditResetPw() { 
-	var pw = uEditMakeRandomPw(patron);	
+function uEditMakePhonePw() {
+    if(patron.passwd()) return;
+    if( (pw = patron.day_phone()) || 
+        (pw = patron.evening_phone()) || (pw = patron.other_phone()) ) {
+            pw = pw.substring(pw.length - 4); // this is iffy
+            uEditResetPw(pw);
+	        appendClear($('ue_password_plain'), text(pw));
+	        unHideMe($('ue_password_gen'));
+	        patron.passwd(pw);
+    }
+}
+
+function uEditResetPw(pw) { 
+    if(!pw) pw = uEditMakeRandomPw(patron);	
 	$('ue_password1').value = pw;
 	$('ue_password2').value = pw;
     $('ue_password1').onchange();

Modified: trunk/Open-ILS/xul/staff_client/server/patron/ue_config.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/patron/ue_config.js	2008-12-19 22:38:40 UTC (rev 11637)
+++ trunk/Open-ILS/xul/staff_client/server/patron/ue_config.js	2008-12-19 22:40:24 UTC (rev 11638)
@@ -294,6 +294,19 @@
 				id			: 'ue_day_phone',
 				type		: 'input',
 				regex		:  phoneRegex,
+                onblur      : function() {
+                    if(uEditUsePhonePw)
+                        uEditMakePhonePw();
+                },
+                onpostchange: function(field, newval) {
+                    /*  if this is a new patron and we are using the phone number for
+                        the password and the staff edits the phone number after entering
+                        it (think typos), update the password too */
+                    if(uEditUsePhonePw && patron.isnew() && patron.passwd() != newval) {
+                        patron.passwd(null);
+                        uEditMakePhonePw();
+                    }
+                }
 			}
 		},
 		{
@@ -305,6 +318,10 @@
 				id			: 'ue_night_phone',
 				type		: 'input',
 				regex		:  phoneRegex,
+                onblur      : function() {
+                    if(uEditUsePhonePw)
+                        uEditMakePhonePw();
+                }
 			}
 		},
 		{
@@ -316,6 +333,10 @@
 				id			: 'ue_other_phone',
 				type		: 'input',
 				regex		:  phoneRegex,
+                onblur      : function() {
+                    if(uEditUsePhonePw)
+                        uEditMakePhonePw();
+                }
 			}
 		},
 		{
@@ -1065,7 +1086,10 @@
         }
 
         var base = new Date();
-        var age = orgSettings['global.juvenile_age_threshold'].value || DEFAULT_ADULT_AGE;
+        var age;
+        if(orgSettings['global.juvenile_age_threshold'])
+            age = orgSettings['global.juvenile_age_threshold'].value;
+        else age = DEFAULT_ADULT_AGE;
         base.setTime(base.getTime() - Number(interval_to_seconds(age) + '000'));
 
 



More information about the open-ils-commits mailing list