From 85e40c04426d972fd97e47b99c0191579a47513e Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 21 Feb 2006 03:55:13 +0000 Subject: [PATCH] more cleaning and arranging, better error handling. shoving more data into user object git-svn-id: svn://svn.open-ils.org/ILS/trunk@3137 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../staff_client/server/patron/user_editor.js | 183 +++++++++++------- .../server/patron/user_editor.xml | 13 +- 2 files changed, 123 insertions(+), 73 deletions(-) diff --git a/Open-ILS/xul/staff_client/server/patron/user_editor.js b/Open-ILS/xul/staff_client/server/patron/user_editor.js index 855ed286ba..c21591a294 100644 --- a/Open-ILS/xul/staff_client/server/patron/user_editor.js +++ b/Open-ILS/xul/staff_client/server/patron/user_editor.js @@ -6,7 +6,10 @@ 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 FETCH_GROUPS = 'open-ils.actor:open-ils.actor.groups.tree.retrieve'; var identTypes = null; +var groupTree = null; +var ERRORS = ""; /* global set of errors */ var myPerms = [ 'CREATE_USER', 'UPDATE_USER', 'CREATE_PATRON_STAT_CAT_ENTRY_MAP' ]; @@ -31,11 +34,11 @@ var pageFocus = [ 'ue_view_summary' ]; -var regexes = {}; +var regexes = {}; regexes.phone = /\d{3}-\d{3}-\d{4}/; -regexes.email = /.+\@.+\..+/; +regexes.email = /\w+\@\w+\.\w+/; regexes.date = /^\d{4}-\d{2}-\d{2}/; -regexes.isid = /^\d+$/; +regexes.isnum = /^\d+$/; /* fetch the necessary data to start off */ function uEditInit() { @@ -55,6 +58,7 @@ function uEditInit() { uEditDrawUser(fetchFleshedUser(cgi.param('usr'))); uEditBuildLibSelector(); uEditFetchIDTypes(); + uEditFetchGroups(); uEditFetchStatCats(); uEditFetchSurveys(); }, 20 @@ -145,6 +149,7 @@ function uEditDrawIDTypes(r) { setSelectorVal( pri_sel, idx, type.name(), type.id() ); setSelectorVal( sec_sel, idx++, type.name(), type.id() ); } + identTypes = types; } function uEditFetchStatCats() { @@ -264,13 +269,12 @@ function uEditInsertSurveyQuestion( div, table, tbody, row, survey, question, si } -function uEditFetchError(id) { return $(id).innerHTML + "\n"; } +function uEditFetchError(id) { if($(id)) return $(id).innerHTML + "\n"; return "";} function uEditSaveUser() { var card = null; - var errors = ""; if(patron == null) { patron = new au(); @@ -284,113 +288,112 @@ function uEditSaveUser() { patron.isnew(0); } - errors += uEditFleshCard(card); - errors += uEditAddBasicPatronInfo(patron); - errors += uEditAddPhones(patron); - errors += uEditAddIdents(patron); + uEditFleshCard(card); + uEditAddBasicPatronInfo(patron); + uEditAddPhones(patron); + uEditAddIdents(patron); + uEditAddGroupsAndPerms(patron); - if(errors) alert(errors); + if(ERRORS) { alert(ERRORS); ERRORS = ""; } else alert(js2JSON(patron)); } -function uEditSetVal( obj, func, val, regxtype ) { +/* returns true if an error occurred */ +function uEditSetVal( obj, func, val, regxtype, errtype ) { - if( val == null ) return false; - if(!instanceOf(val, String)) { - try { - val = val.value; - } catch(e) { return false; } - } + var error = uEditFetchError(errtype); + var iserr = false; + + while(1) { - if(val == "" ) return false; + if( val == null ) { iserr = true; break; } - if(regxtype && regexes[regxtype] - && !val.match(regexes[regxtype]) ) return false; + if(!instanceOf(val, String)) { + try { val = val.value; } catch(e) { return; } + } - obj[func](val); - alert("Setting val: "+val); + if(val == "" ) { iserr = true; break; } - return true; + if(regxtype && regexes[regxtype] + && !val.match(regexes[regxtype]) ) { iserr = true; break; } + + try { obj[func](val); } catch(e) { + alert("Error running function: " +func); + } + + break; + } + + if(iserr) { ERRORS += error; return true; } + return false; } 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( p1 != p2 || uEditSetVal( patron, "passwd", p1 )) + ERRORS += uEditFetchError('ue_bad_password'); - 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'); + uEditSetVal(patron, "usrname", $('ue_username'), null, 'ue_bad_username' ); + uEditSetVal(patron, "first_given_name", $('ue_firstname'), null, 'ue_bad_firstname' ); + uEditSetVal(patron, "second_given_name", $('ue_middlename'), null, 'ue_bad_middlename' ); + uEditSetVal(patron, "family_name", $('ue_lastname'), null, 'ue_bad_lastname' ); + uEditSetVal(patron, "dob", $('ue_dob'), 'date', 'ue_bad_dob' ); patron.suffix($('ue_suffix').value); /* suffis isn't required */ - if(!uEditSetVal(patron, "dob", $('ue_dob'), 'date' ) ) - 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, 'email' )) - errors += uEditFetchError('ue_bad_email'); - + if( email != email2 || uEditSetVal(patron, "email", email, 'email' )) + ERRORS += uEditFetchError('ue_bad_email'); - return errors; + patron.home_ou(getSelectorVal($('ue_org_selector'))); } function uEditAddPhones(patron) { - var errors = ""; /* verifies the phone numbers are formatted correctly */ var verify = function(n1, n2, n3) { var a = n1.value; var p = n2.value; var s = n3.value; - if( !a || !b || !c ) return false; + if( !a || !p || !s ) return false; return a + '-' + p + '-' + s; } - if(!uEditSetVal( patron, "day_phone", + var er = 'ue_bad_phone' + + uEditSetVal( patron, "day_phone", verify($('ue_day_phone_area'), $('ue_day_phone_prefix'), - $('ue_day_phone_suffix')), 'phone' )) - errors += uEditFetchError('ue_bad_phone'); + $('ue_day_phone_suffix')), 'phone', er ); - if(!uEditSetVal( patron, "night_phone", + uEditSetVal( patron, "evening_phone", verify($('ue_night_phone_area'), $('ue_night_phone_prefix'), - $('ue_night_phone_suffix')), 'phone' )) - errors += uEditFetchError('ue_bad_phone'); + $('ue_night_phone_suffix')), 'phone', er ); - if(!uEditSetVal( patron, "other_phone", + uEditSetVal( patron, "other_phone", verify($('ue_other_phone_area'), $('ue_other_phone_prefix'), - $('ue_other_phone_suffix')), 'phone' )) - errors += uEditFetchError('ue_bad_phone'); + $('ue_other_phone_suffix')), 'phone', er ); - return errors; } function uEditFleshCard(card) { if(!card) return ""; - if(!uEditSetVal( card, "barcode", $('ue_barcode') )) - return uEditFetchError('ue_bad_barcode'); + if(uEditSetVal( card, "barcode", $('ue_barcode'), null, 'ue_bad_barcode' )) + return; card.id(-1); card.active(1); @@ -399,33 +402,75 @@ function uEditFleshCard(card) { function uEditAddIdents(patron) { - if( !uEditSetVal( patron, - "ident_type", getSelectorVal($('ue_primary_ident_type')), 'isid' )) - return uEditFetchError('ue_no_ident'); + var err = 'ue_no_ident'; - if( !uEditSetVal( patron, - "ident_type2", getSelectorVal($('ue_secondary_ident_type')), 'isid' )) - return uEditFetchError('ue_no_ident'); + uEditSetVal( patron, "ident_type", + getSelectorVal($('ue_primary_ident_type')), 'isnum', err ); - if( !uEditSetVal( patron, "ident_value", $('ue_primary_ident') )) - return uEditFetchError('ue_no_ident'); + uEditSetVal( patron, "ident_type2", + getSelectorVal($('ue_secondary_ident_type')), 'isnum', err ); - if( !uEditSetVal( patron, "ident_value2", $('ue_secondary_ident') )) - return uEditFetchError('ue_no_ident'); + uEditSetVal( patron, "ident_value", + $('ue_primary_ident'), null, err ); + + uEditSetVal( patron, "ident_value2", + $('ue_secondary_ident'), null, err ); - return ""; } -var orgSelecto function uEditBuildLibSelector( node, depth, selector ) { if(!selector) selector = $('ue_org_selector'); if(!node) { depth = 0; node = globalOrgTree; } - insertSelectorVal( selector, -1, node.name(), node.id(), null, depth++ ); + var opt = insertSelectorVal( selector, -1, node.name(), node.id(), null, depth++ ); + + /* allow these orgs to be selectable via permission? */ + if(!findOrgType(node.ou_type()).can_have_vols()) opt.disabled = true; + if( node.id() == USER.home_ou() ) setSelector(selector, node.id()); for( var c in node.children() ) uEditBuildLibSelector(node.children()[c], depth, selector); } +function uEditFetchGroups() { + var req = new Request(FETCH_GROUPS); + req.callback(uEditDrawGroups); + req.send(); +} + +function uEditDrawGroups(r, tree, depth, selector) { + + if(!tree) { + tree = r.getResultObject(); + depth = 0; + groupTree = tree; + selector = $('ue_profile'); + } + + insertSelectorVal( selector, -1, tree.name(), tree.id(), null, depth++ ); + for( var c in tree.children() ) + uEditDrawGroups( null, tree.children()[c], depth, selector ); +} + + + +function uEditAddGroupsAndPerms(patron) { + + uEditSetVal( patron, "profile", + getSelectorVal($('ue_profile')), 'isnum', 'ue_no_profile'); + + var expire = $('ue_expire').value; + if(expire) + uEditSetVal( patron, "expire_date", expire, 'date', 'ue_bad_expire' ); + + if($('ue_active').checked) patron.active(1); + if($('ue_barred').checked) patron.barred(1); + if($('ue_group_lead').checked) patron.master_account(1); + + uEditSetVal( patron, "claims_returned_count", + $('ue_claims_returned'), 'isnum', 'ue_bad_claims_returned'); +} + + diff --git a/Open-ILS/xul/staff_client/server/patron/user_editor.xml b/Open-ILS/xul/staff_client/server/patron/user_editor.xml index d9b40c351f..27fd754d05 100644 --- a/Open-ILS/xul/staff_client/server/patron/user_editor.xml +++ b/Open-ILS/xul/staff_client/server/patron/user_editor.xml @@ -631,20 +631,25 @@
The date of birth field is not formatted correctly. We're expecting YYYY-MM-DD - Username is invalid. + Username is invalid Passwords do not match or are invalid First name is invalid Middle name is invalid Last name is invalid - Barcode is invalid. - The barcode is invalid. + Barcode is invalid + The selected barcode already exists in the database 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. - You must select two types of identification. + You must select two types of identification The email addresses do not match or are invalid An invalid phone number was entered + A profile group must be selected + The user expiration date is invalid. We're expecting YYYY-MM-DD + The claims returned count is invalid + A profile group must be selected + An unknown formatting error occurred
-- 2.43.2