fixed bug in user editor which prevented the expire_date from getting set properly...
[Evergreen.git] / Evergreen / xul / staff_client / server / patron / ue_config.js
index 37eb11b..a071339 100644 (file)
@@ -16,6 +16,7 @@ const CHECK_BARCODE           = 'open-ils.actor:open-ils.actor.barcode.exists';
 const defaultState             = 'GA';
 const defaultCountry           = 'USA';
 const defaultNetAccess = 'None';
+const defaultNetLevel   = 1;
 const CSS_INVALID_DATA = 'invalid_value';
 const ADULT_AGE                        = 18;
 //const GUARDIAN_NOTE          = 'SYSTEM: Parent/Guardian';
@@ -39,13 +40,14 @@ var myPerms = [
 
 var dataFields;
 const numRegex         = /^\d+$/;
-const wordRegex        = /^\w+$/;
+const wordRegex        = /^[\w-]+$/;
+const unameRegex       = /^\w[\.\w\@-]*$/;
 const ssnRegex         = /^\d{3}-\d{2}-\d{4}$/;
 const dlRegex          = /^[a-zA-Z]{2}-\w+/; /* driver's license */
 const phoneRegex       = /^\d{3}-\d{3}-\d{4}(| ex\d+)$/i;
 const nonumRegex       = /^[a-zA-Z]\D*$/; /* no numbers, no beginning whitespace */
 const dateRegex        = /^\d{4}-\d{2}-\d{2}/;
-const zipRegex         = /^\d{5}(-\d{4}|$)/; /* 12345 or 12345-6789 */
+const zipRegex         = /^\d{5}(-\d{4}|-?$)/; /* 12345 or 12345-6789 */
 
 var barredAlerted = false;
 
@@ -77,6 +79,7 @@ function uEditUsrnameBlur(field) {
 function uEditBarcodeBlur(field) {
        var barcode = uEditNodeVal(field);
        if(!barcode) return;
+       _debug("blurring card with new value " + barcode);
        var req = new Request(CHECK_BARCODE, SESSION, barcode);
        req.callback( 
                function(r) {
@@ -126,7 +129,7 @@ function uEditDefineData(patron) {
                        errkey  : 'ue_bad_username',
                        widget  : {
                                id              : 'ue_username',
-                               regex   : wordRegex,
+                               regex   : unameRegex,
                                type    : 'input',
                                onblur : uEditUsrnameBlur
                        }
@@ -159,6 +162,11 @@ function uEditDefineData(patron) {
                                        var pw1f = uEditFindFieldByWId('ue_password1');
                                        var pw1 = uEditNodeVal(pw1f);
                                        field.widget.regex = new RegExp('^'+pw1+'$');
+                                       if( pw1 ) field.required = true;
+                                       else {
+                                               if(!patron.isnew())
+                                                       field.required = false;
+                                       }
                                }
                        }
                },
@@ -390,6 +398,8 @@ function uEditDefineData(patron) {
                                        exptime                 += intsecs * 1000;
                                        expdate.setTime(exptime);
 
+                                       _debug("profile change (interval= '"+interval+"', seconds="+intsecs+")\n\tgenerated a date of " + expdate);
+
                                        var year                        = expdate.getYear() + 1900;
                                        var month               = (expdate.getMonth() + 1) + '';
                                        var day                 = (expdate.getDate()) + '';
@@ -397,8 +407,12 @@ function uEditDefineData(patron) {
                                        if(!month.match(/\d{2}/)) month = '0' + month;
                                        if(!day.match(/\d{2}/)) day = '0' + day;
 
+
                                        var node = $('ue_expire');
                                        node.value = year+'-'+month+'-'+day;
+
+                                       _debug("profile change formatted date to "+ node.value);
+                                       node.onchange();
                                }
                        }
                },
@@ -428,6 +442,7 @@ function uEditDefineData(patron) {
                                id                      : 'ue_claims_returned',
                                type            : 'input',
                                regex           : numRegex,
+                               disabled : true
                        }
                },
                {
@@ -879,6 +894,8 @@ function uEditBuildSCMField(statcat, row) {
                                        /* map does not exist in the map array but now has data */
                                        if(newval) { 
                                                map.isnew(1);
+                                               if(!patron.stat_cat_entries())
+                                                       patron.stat_cat_entries([]);
                                                patron.stat_cat_entries().push(map);
                                        }
                                }