var netLevelsCache = {};
var orgSettings = [];
//var guardianNote = null;
+var uEditUsePhonePw = false;
if(!window.xulG) var xulG = null;
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(),
}
function uEditMakeRandomPw(patron) {
+ if(uEditUsePhonePw) return;
var rand = Math.random();
rand = parseInt(rand * 10000) + '';
while(rand.length < 4) rand += '0';
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();
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();
+ }
+ }
}
},
{
id : 'ue_night_phone',
type : 'input',
regex : phoneRegex,
+ onblur : function() {
+ if(uEditUsePhonePw)
+ uEditMakePhonePw();
+ }
}
},
{
id : 'ue_other_phone',
type : 'input',
regex : phoneRegex,
+ onblur : function() {
+ if(uEditUsePhonePw)
+ uEditMakePhonePw();
+ }
}
},
{
}
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'));