added guardian notes to new juvenile users, verifying dob is a valid date not in...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 24 Jul 2006 20:26:26 +0000 (20:26 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 24 Jul 2006 20:26:26 +0000 (20:26 +0000)
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
Open-ILS/xul/staff_client/server/patron/ue.xhtml
Open-ILS/xul/staff_client/server/patron/ue_config.js

index c3233ad..b8dd870 100644 (file)
@@ -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);
        }
 
index 80eb850..0815f82 100644 (file)
                <span class='hide_me' id='ue_cancel_confirm'>
                        Are you sure you wish to cancel this editing session?
                        Canceling will destroy any unsaved changes you have made thus far to the user.
-                       </span>
+               </span>
+               <span class='hide_me' id='ue_juv_guardian'>
+                       This patron is under 18 years of age.  Please enter the name 
+                       of the parent or guardian for this patron.
+               </span>
+               <span class='hide_me' id='ue_bad_date'>
+                       The date provided is either in the future or invalid.  We're expecting YYYY-MM-DD
+               </span>
        </div>
 
-
        </body>
 </html>
 
index 9d9b19d..cda22d7 100644 (file)
@@ -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;
+}
+