From 8b35483d686479ce4d41fd65fbf77b8bffef7265 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 24 Jul 2006 20:26:26 +0000 Subject: [PATCH] added guardian notes to new juvenile users, verifying dob is a valid date not in the future git-svn-id: svn://svn.open-ils.org/ILS/trunk@5104 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/xul/staff_client/server/patron/ue.js | 19 ++++++++ Open-ILS/xul/staff_client/server/patron/ue.xhtml | 10 +++- .../xul/staff_client/server/patron/ue_config.js | 54 ++++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/Open-ILS/xul/staff_client/server/patron/ue.js b/Open-ILS/xul/staff_client/server/patron/ue.js index c3233ad745..b8dd870ea5 100644 --- a/Open-ILS/xul/staff_client/server/patron/ue.js +++ b/Open-ILS/xul/staff_client/server/patron/ue.js @@ -10,6 +10,7 @@ var surveyAnswersCache = {}; var userCache = {}; var groupsCache = {}; var netLevelsCache = {}; +var guardianNote = null; /* fetch the necessary data to start off */ @@ -59,6 +60,7 @@ function uEditFetchNetLevels() { req.send(true); return req.result(); } + /* ------------------------------------------------------------------------------ */ @@ -401,6 +403,7 @@ function uEditSaveUser(cloneme) { if( ! patron.ident_value2() ) patron.ident_value2(null); var req = new Request(UPDATE_PATRON, SESSION, patron); + req.alertEvent = false; req.send(true); var newuser = req.result(); @@ -410,6 +413,22 @@ function uEditSaveUser(cloneme) { return; } else { + + /* if it's a new user and a guardian note was created for this user, + create the note after we have the new user's id */ + if( guardianNote ) { + guardianNote.usr( newuser.id() ); + var req = new Request(CREATE_USER_NOTE, SESSION, guardianNote); + req.alertEvent = false; + req.send(true); + var resp = req.result(); + if( checkILSEvent(resp) ) { + alertILSEvent(resp, + "Error creating patron guardian/parent note"); + return; + } + } + alert($('ue_success').innerHTML); } diff --git a/Open-ILS/xul/staff_client/server/patron/ue.xhtml b/Open-ILS/xul/staff_client/server/patron/ue.xhtml index 80eb8509fa..0815f82250 100644 --- a/Open-ILS/xul/staff_client/server/patron/ue.xhtml +++ b/Open-ILS/xul/staff_client/server/patron/ue.xhtml @@ -955,10 +955,16 @@ Are you sure you wish to cancel this editing session? Canceling will destroy any unsaved changes you have made thus far to the user. - + + + This patron is under 18 years of age. Please enter the name + of the parent or guardian for this patron. + + + The date provided is either in the future or invalid. We're expecting YYYY-MM-DD + - diff --git a/Open-ILS/xul/staff_client/server/patron/ue_config.js b/Open-ILS/xul/staff_client/server/patron/ue_config.js index 9d9b19d655..cda22d73a7 100644 --- a/Open-ILS/xul/staff_client/server/patron/ue_config.js +++ b/Open-ILS/xul/staff_client/server/patron/ue_config.js @@ -11,10 +11,13 @@ const PATRON_SEARCH = 'open-ils.actor:open-ils.actor.patron.search.advanced'; const ZIP_SEARCH = 'open-ils.search:open-ils.search.zip'; const FETCH_ADDR_MEMS = 'open-ils.actor:open-ils.actor.address.members'; const FETCH_GRP_MEMS = 'open-ils.actor:open-ils.actor.usergroup.members.retrieve'; +const CREATE_USER_NOTE = 'open-ils.actor:open-ils.actor.note.create'; const defaultState = 'GA'; const defaultCountry = 'USA'; const defaultNetAccess = 'None'; const CSS_INVALID_DATA = 'invalid_value'; +const ADULT_AGE = 18; +const GUARDIAN_NOTE = 'SYSTEM: Parent/Guardian'; /* if they don't have these perms, they shouldn't be here */ var myPerms = [ 'CREATE_USER', 'UPDATE_USER', 'CREATE_PATRON_STAT_CAT_ENTRY_MAP' ]; @@ -175,6 +178,8 @@ function uEditDefineData(patron) { id : 'ue_dob', regex : dateRegex, type : 'input', + onpostchange : function(field) { uEditCheckDOB(field); }, + onblur : function(field) { uEditCheckDOB(field); } } }, { @@ -960,5 +965,54 @@ function uEditCheckSharedAddr(patron, address, tbody, row) { +var __lastdob; +function uEditCheckDOB(field) { + + var dob = uEditNodeVal(field); + + /* don't bother if the data isn't valid */ + if(!dob || !dob.match(field.widget.regex)) + return; + + if( dob == __lastdob ) return; + + __lastdob = dob; + + var parts = dob.split(/-/); + var d = new Date( parts[0], parts[1] - 1, parts[2] ); + + dob = buildDate( parts[0], parts[1], parts[2] ); + + var today = new Date(); + + if(!dob || dob > today) { + addCSSClass(field.widget.node, CSS_INVALID_DATA); + alertId('ue_bad_date'); + return; + } + + var base = new Date(); + base.setYear( today.getYear() + 1900 - ADULT_AGE ); + + /* patron already exists or is at least 18 */ + if( !patron.isnew() || dob < base ) return; + + if( guardianNote ) return; + + /* create a new note to represent the patron's guardian */ + var note = new aun(); + note.title(GUARDIAN_NOTE); + note.isnew(1); + note.creator(USER.id()); + note.isnew(1); + + var txt; /* get the guardian info from the staff */ + while(!txt || txt == "") + txt = prompt($('ue_juv_guardian').innerHTML); + + note.value(txt); + guardianNote = note; +} + -- 2.11.0