From: Bill Erickson Date: Mon, 14 Mar 2016 14:43:08 +0000 (-0400) Subject: JBAS-1132 Self-register patron edit mods X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=02a0c5ca15021f20a243d35f15612d9a6a370d40;p=working%2FEvergreen.git JBAS-1132 Self-register patron edit mods * Fire on-change handler for various fields after a staged user is loaded to apply various rules: ** setting juvenile flag from dob ** running duplicate patron searches ** creating password from phone ** Setting expire date base on profile * Support for loading stat cats data Signed-off-by: Bill Erickson --- 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 9b95e7591e..5486a91ba6 100644 --- a/Open-ILS/web/js/ui/default/actor/user/register.js +++ b/Open-ILS/web/js/ui/default/actor/user/register.js @@ -322,6 +322,8 @@ function load() { }, true); }); + if (stageUser) processStageUserValues(); + lock_ready = true; } @@ -731,6 +733,14 @@ function uEditLoadStageUser(stageUname) { } } + // if either mailing or billing addresses are not provided, + // use each for the other as a fall-back. + if (patron.mailing_address() && !patron.billing_address()) { + patron.billing_address(patron.mailing_address()); + } else if (patron.billing_address() && !patron.mailing_address()) { + patron.mailing_address(patron.billing_address()); + } + // TODO: uses the first card only if(data.cards.length) { var card = new fieldmapper.ac(); @@ -742,6 +752,16 @@ function uEditLoadStageUser(stageUname) { } } + // Copy stat cat data + dojo.forEach(data.statcats, function(stat_cat) { + var entry = new fieldmapper.actscecm(); + entry.isnew(true); + entry.stat_cat(stat_cat.statcat()); + entry.stat_cat_entry(stat_cat.value()); + entry.target_usr(patron.id()); + patron.stat_cat_entries().push(entry); + }); + return patron; } @@ -1322,6 +1342,44 @@ function fleshFMRow(row, fmcls, args) { return widget; } +// JBAS-1132 +// When loading a staged user, force the on-change handler to run for +// various fields, since their values are applied at load- time instead +// of via manual changing. +// All staged user values of concern are simple text values, whose +// widgets are loaded synchronously. No need to setTimeout or +// track loaded fields, etc. before calling this function. +// Force on-change to run for: +// * duplicate value searches +// * setting default password from phone +function processStageUserValues() { + + dojo.forEach( + ['family_name', 'email', 'ident_value', 'ident_value2', + 'dob', 'day_phone', 'evening_phone', 'other_phone'], + function(field) { + var val = findWidget('au', field).widget.attr('value'); + if (val) { + findWidget('au', field).widget.attr('value', ''); + findWidget('au', field).widget.attr('value', val); + } + } + ); + + dojo.forEach( + patron.addresses(), + function(addr) { + var callback = function(w) { return w._addr == addr.id() }; + var widg = findWidget('aua', 'street1', callback).widget; + var val = widg.attr('value'); + if (val) { + widg.attr('value', ''); + widg.attr('value', val); + } + } + ); +} + function trimGrpTree(autoWidget) { var store = autoWidget.widget.store; if(!store) return; @@ -1628,20 +1686,30 @@ function attachWidgetEvents(fmcls, fmfield, widget) { return; case 'profile': // when the profile changes, update the expire date - dojo.connect(widget.widget, 'onChange', - function() { - var self = this; - var expireWidget = findWidget('au', 'expire_date'); - function found(items) { - if(items.length == 0) return; - var item = items[0]; - var interval = self.store.getValue(item, 'perm_interval'); - expireWidget.widget.attr('value', dojo.date.add(new Date(), - 'second', openils.Util.intervalToSeconds(interval))); - } - this.store.fetch({onComplete:found, query:{id:this.attr('value')}}); + + function profileChangedHandler(self) { + var expireWidget = findWidget('au', 'expire_date'); + function found(items) { + if(items.length == 0) return; + var item = items[0]; + var interval = self.store.getValue(item, 'perm_interval'); + expireWidget.widget.attr('value', dojo.date.add(new Date(), + 'second', openils.Util.intervalToSeconds(interval))); } - ); + self.store.fetch({onComplete:found, query:{id:self.attr('value')}}); + } + + // Force the handler to run if a profile was set on the + // staged user. Otherwise it won't run unless the profile + // is manually altered. Run it in a timeout so the expire + // widget has a chance to render before we reference it. + if (stageUser && stageUser.profile) { + setTimeout(function() { + profileChangedHandler(widget.widget)}, 300); + } + + dojo.connect(widget.widget, 'onChange', + function() {profileChangedHandler(this) }); return; case 'dob': @@ -1874,6 +1942,9 @@ function uEditAddressAlertSearch(args, addrId) { function uEditDupeSearch(type, value) { if(!value) return; var search; + + console.debug('running dupe search for ' + type + ' : ' + value); + switch(type) { case 'name':