trudging forward. added more sanity checks and more info is added in the saveuser...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 20 Feb 2006 22:53:36 +0000 (22:53 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 20 Feb 2006 22:53:36 +0000 (22:53 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@3135 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/server/patron/user_editor.js
Open-ILS/xul/staff_client/server/patron/user_editor.xml

index f6f31d7..454dab8 100644 (file)
@@ -5,6 +5,8 @@ var advanced                    = false;
 var SC_FETCH_ALL     = 'open-ils.circ:open-ils.circ.stat_cat.actor.retrieve.all';
 var SC_CREATE_MAP              = 'open-ils.circ:open-ils.circ.stat_cat.actor.user_map.create';
 var SV_FETCH_ALL               = 'open-ils.circ:open-ils.circ.survey.retrieve.all';
+var FETCH_ID_TYPES     = 'open-ils.actor:open-ils.actor.user.ident_types.retrieve';
+var identTypes                 = null;
 
 var myPerms            = [ 'CREATE_USER', 'UPDATE_USER', 'CREATE_PATRON_STAT_CAT_ENTRY_MAP' ];
 
@@ -45,6 +47,7 @@ function uEditInit() {
                function() { 
                        fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
                        uEditDrawUser(fetchFleshedUser(cgi.param('usr')));
+                       uEditFetchIDTypes();
                        uEditFetchStatCats();
                        uEditFetchSurveys();
                }, 20 
@@ -117,6 +120,26 @@ function uEditDrawUser(patron) {
        if(!patron) return 0;
 }
 
+function uEditFetchIDTypes() {
+       var req = new Request(FETCH_ID_TYPES);
+       req.callback(uEditDrawIDTypes);
+       req.send();
+}
+
+function uEditDrawIDTypes(r) {
+
+       var types = r.getResultObject();
+       var pri_sel = $('ue_primary_ident_type');
+       var sec_sel = $('ue_secondary_ident_type');
+
+       var idx = 1;
+       for( var t in types ) {
+               var type = types[t];
+               setSelectorVal( pri_sel, idx, type.name(), type.id() );
+               setSelectorVal( sec_sel, idx++, type.name(), type.id() );
+       }
+}
+
 function uEditFetchStatCats() {
        var req = new Request(SC_FETCH_ALL, SESSION);
        req.callback(uEditDrawStatCats);
@@ -234,21 +257,121 @@ function uEditInsertSurveyQuestion( div, table, tbody, row, survey, question, si
 }
 
 
+function uEditFetchError(id) { return $(id).innerHTML + "\n"; }
+
+
 function uEditSaveUser() {
 
-       if(patron == null) patron = new au();
+       var card                = null;
+       var errors      = "";
 
-       var barcode = $('ue_barcode').value;
-       patron.usrname($('ue_username').value); 
-       patron.passwd($('ue_password1').value); 
-       patron.first_given_name($('ue_firstname').value);
-       patron.second_given_name($('ue_middlename').value);
-       patron.family_name($('ue_lastname').value);
-       patron.suffix($('ue_suffix').value);
-       patron.dob($('ue_dob').value);
+       if(patron == null) { 
+               patron = new au(); 
+               patron.isnew(1);
+               card = new ac();
+               patron.card(-1); /* attach to the virtual id of the card */
+               patron.cards([card]);
 
-       alert(js2JSON(patron));
+       } else { 
+               patron.ischanged(1); 
+               patron.isnew(0);
+       }
+
+       errors += uEditFleshCard(card);
+       errors += uEditAddBasicPatronInfo(patron);
+       errors += uEditAddIdents(patron);
 
+       if(errors) alert(errors);
+       else alert(js2JSON(patron));
 }
 
+function uEditSetVal( obj, func, val, regex ) {
+
+       if( val == null ) return false;
+       if(!instanceOf(val, String)) {
+               try {
+                       val = val.value;
+               } catch(e) { return false; }
+       }
+
+       if(val == "" ) return false;
+       if(regex && !val.match(regex) ) return false;
+
+       obj[func](val);
+       alert("Setting val: "+val);
+
+       return true;
+}
+
+
+function uEditAddBasicPatronInfo(patron) {
+
+       var errors = "";
+
+       if(!uEditSetVal(patron, "usrname", $('ue_username'), /.+/ ))
+               errors += uEditFetchError('ue_bad_username');
+
+       /* make sure passwords match */
+       var p1 = $('ue_password1').value;
+       var p2 = $('ue_password1').value;
+       if( p1 != p2 || !uEditSetVal( patron, "passwd", p1 )) 
+               errors += uEditFetchError('ue_bad_password');
+
+       if(!uEditSetVal(patron, "first_given_name", $('ue_firstname'), /.+/)) 
+               errors += uEditFetchError('ue_bad_firstname');
+
+       if(!uEditSetVal(patron, "second_given_name", $('ue_middlename'), /.+/)) 
+               errors += uEditFetchError('ue_bad_middlename');
+
+       if(!uEditSetVal(patron, "family_name", $('ue_lastname'), /.+/)) 
+               errors += uEditFetchError('ue_bad_lastname');
+
+       patron.suffix($('ue_suffix').value); /* suffis isn't required */
+
+       if(!uEditSetVal(patron, "dob", $('ue_dob'), /^\d{4}-\d{2}-\d{2}/ ) )
+               errors += uEditFetchError('ue_bad_dob');
+
+       /* make sure emails match */
+       var email       = $('ue_email1').value;
+       var email2      = $('ue_email2').value;
+       if( email != email2 || !uEditSetVal(patron, "email", email, /.+\@.+\..+/ ))
+               errors += uEditFetchError('ue_bad_email');
+
+       return errors;
+}
+
+function uEditFleshCard(card) {
+       if(!card) return "";
+
+       if(!uEditSetVal( card, "barcode", $('ue_barcode') ))
+               return uEditFetchError('ue_bad_barcode');
+
+       card.id(-1);
+       card.active(1);
+       return "";
+}
+
+function uEditAddIdents(patron) {
+
+       var ptype1 = 
+       var ptype2 = getSelectorVal($('ue_secondary_ident_type'));
+       var val1 = $('ue_primary_ident').value;
+       var val2 = $('ue_secondary_ident').value;
+       
+       if( !uEditSetVal( patron, 
+               "ident_type", getSelectorVal($('ue_primary_ident_type'), /^[0-9]+$/ );
+               return uEditFetchError('ue_no_ident');
+
+       if( !uEditSetVal( patron, 
+               "ident_type2", getSelectorVal($('ue_secondary_ident_type'), /^[0-9]+$/ );
+               return uEditFetchError('ue_no_ident');
+
+       if( !uEditSetVal( patron, "ident_value", $('ue_primary_ident') ))
+               return uEditFetchError('ue_no_ident');
+
+       if( !uEditSetVal( patron, "ident_value2", $('ue_secondary_ident') ))
+               return uEditFetchError('ue_no_ident');
+
+       return "";
+}
 
index 2faa1b9..7dbd729 100644 (file)
                                                                <tbody>
                                                                        <tr>
                                                                                <td><div class='wide right'>Barcode</div></td>
-                                                                               <td><div class='wide left'><input type='text' id='ue_barcode'/></div></td>
+                                                                               <td><div class='wide left'>
+
+                                                                                       <input type='text' id='ue_barcode' 
+                                                                                               onblur=' var un = $("ue_username");
+                                                                                                       if(!un.value) un.value = this.value;'/>
+
+                                                                               </div></td>
                                                                        </tr>
                                                                        <tr>
                                                                                <td><div class='wide right'>Username</div></td>
                                                                                                </button>
 
                                                                                                <span class='pad' style='font-size: 8pt;'>(YYYY-MM-DD)</span>
+                                                                                               <div style='margin-top: 5px;'>
+                                                                                                       Note: a default will be provided if none is selected
+                                                                                               </div>
        
                                                                                                <script type="text/javascript">
                                                                                                        Calendar.setup({
                        </tbody>
                </table>
        </center>
+
+       <!-- ************************************************************** -->
+       <!-- This holds all of the strings we may have to alert to the user -->
+       <!-- ************************************************************** -->
+       <div class='hide_me'>
+               <span id='ue_bad_dob'>The date of birth field is not formatted correctly.  We're expecting YYY-MM-DD</span>
+               <span id='ue_bad_username'>Username is invalid.</span>
+               <span id='ue_bad_password'>Passwords do not match or are invalid</span>
+               <span id='ue_bad_firstname'>First name is invalid</span>
+               <span id='ue_bad_middlename'>Middle name is invalid</span>
+               <span id='ue_bad_lastname'>Last name is invalid</span>
+               <span id='ue_bad_barcode'>Barcode is invalid.</span>
+               <span id='ue_duplicate_barcode'>The barcode is invalid.</span>
+               <span id='ue_new_barcode_warn'>
+                       This will de-activate the existing barcode for this user!  If you wish to continue, 
+                       enter the new barcode below.  Otherwise, click the Cancel button.
+               </span>
+               <span id='ue_no_ident'>You must select two types of identification.</span>
+               <span id='ue_bad_email'>The email addresses do not match or are invalid</span>
+       </div>
+
        </body>
 </html>