From f851314048b908cb488e5aba78060ca38f992d97 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 20 Oct 2015 12:02:39 -0400 Subject: [PATCH] KMAIN-1827 guardian required set onload Ensure that the parent/guardian (ident_value2) field gets the correct value for 'required' on patron load to ensure it's not required for non-juvenile patrons. Signed-off-by: Bill Erickson --- Open-ILS/web/js/ui/default/actor/user/register.js | 47 ++++++++++++++++++----- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/Open-ILS/web/js/ui/default/actor/user/register.js b/Open-ILS/web/js/ui/default/actor/user/register.js index 4f523875f8..c575f232b5 100644 --- a/Open-ILS/web/js/ui/default/actor/user/register.js +++ b/Open-ILS/web/js/ui/default/actor/user/register.js @@ -1299,6 +1299,15 @@ function fleshFMRow(row, fmcls, args) { w.attr('disabled', true); } } + // call the dobLoaded function only after both dob and + // guardian widgets have been created. And then only + // if this is an existing patron. + if (!patron.isnew()) { + if (fmfield == 'ident_value2' || + (fmfield == 'dob' && findWidget('au', 'ident_value2'))) { + dobLoaded(ww) ; + } + } } ); @@ -1429,6 +1438,30 @@ function usePhonePw(newVal) { } } +function dobIsJuvenile(newDob) { + var juvInterval = + orgSettings['global.juvenile_age_threshold'] || '18 years'; + + var base = new Date(); + base.setTime(base.getTime() - + Number(openils.Util.intervalToSeconds(juvInterval) + '000')); + + return newDob > base; +} + +// onload handler for DoB widget. Sets or clears the 'required' +// flag on the parent/guardian (ident_value2) field based on +// the user's existing DoB value. +// Param "ww" will contain the ident_value2 widget if it's not +// yet globally available (i.e. it's currently being built); +function dobLoaded(ww) { + if (!patron.dob()) return; + var guardian = findWidget('au', 'ident_value2') || ww; + var newDob = dojo.date.stamp.fromISOString(patron.dob()); + guardian.widget.attr('required', dobIsJuvenile(newDob)); +} + + function attachWidgetEvents(fmcls, fmfield, widget) { dojo.connect( @@ -1620,20 +1653,14 @@ function attachWidgetEvents(fmcls, fmfield, widget) { dojo.connect(widget.widget, 'onChange', function(newDob) { if(!newDob) return; + var oldDob = patron.dob(); if(dojo.date.stamp.fromISOString(oldDob) == newDob) return; - var juvInterval = orgSettings['global.juvenile_age_threshold'] || '18 years'; - var base = new Date(); - base.setTime(base.getTime() - Number(openils.Util.intervalToSeconds(juvInterval) + '000')); + var attrVal = dobIsJuvenile(newDob); - if(newDob <= base) { // older than global.juvenile_age_threshold - findWidget('au', 'juvenile').widget.attr('value', false); - findWidget('au', 'ident_value2').widget.attr('required', false); - } else { - findWidget('au', 'juvenile').widget.attr('value', true); - findWidget('au', 'ident_value2').widget.attr('required', true); - } + findWidget('au', 'juvenile').widget.attr('value', attrVal); + findWidget('au', 'ident_value2').widget.attr('required', attrVal); } ); return; -- 2.11.0