added logic to use the last 4 digits of patron phone number as the default password...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 19 Dec 2008 22:40:24 +0000 (22:40 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 19 Dec 2008 22:40:24 +0000 (22:40 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@11638 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/server/patron/ue.js
Open-ILS/xul/staff_client/server/patron/ue_config.js

index 79963fc..2a3bec4 100644 (file)
@@ -12,6 +12,7 @@ var groupsCache                               = {};
 var netLevelsCache                     = {};
 var orgSettings             = [];
 //var guardianNote                             = null;
+var uEditUsePhonePw = false;
 
 if(!window.xulG) var xulG = null;
 
@@ -139,10 +140,17 @@ function uEditBuild() {
        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 uEditNewPatron() {
 }
 
 function uEditMakeRandomPw(patron) {
+    if(uEditUsePhonePw) return;
        var rand  = Math.random();
        rand = parseInt(rand * 10000) + '';
        while(rand.length < 4) rand += '0';
@@ -253,8 +262,20 @@ function uEditMakeRandomPw(patron) {
        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();
index 836aa6f..c39952a 100644 (file)
@@ -294,6 +294,19 @@ function uEditDefineData(patron) {
                                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 @@ function uEditDefineData(patron) {
                                id                      : 'ue_night_phone',
                                type            : 'input',
                                regex           :  phoneRegex,
+                onblur      : function() {
+                    if(uEditUsePhonePw)
+                        uEditMakePhonePw();
+                }
                        }
                },
                {
@@ -316,6 +333,10 @@ function uEditDefineData(patron) {
                                id                      : 'ue_other_phone',
                                type            : 'input',
                                regex           :  phoneRegex,
+                onblur      : function() {
+                    if(uEditUsePhonePw)
+                        uEditMakePhonePw();
+                }
                        }
                },
                {
@@ -1065,7 +1086,10 @@ function uEditCheckDOB(field) {
         }
 
         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'));