From 190785dbbf7ae6dace343ad12c04d7403468c48a Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 27 Feb 2012 17:32:31 -0500 Subject: [PATCH] Patron editor changes Originating from https://github.com/grpl-eg/rel_2_1.git: aad962182fc75967a763a66bf32208065fd4b773 39a67d5523f80aaf119b537f5665c0772958e6f7 8bac903b2e512d3625553f2693b100f3cc60f9a0 --- Open-ILS/examples/fm_IDL.xml | 3 + .../src/perlmods/lib/OpenILS/Application/Actor.pm | 6 +- .../lib/OpenILS/Application/Storage/CDBI/actor.pm | 2 +- Open-ILS/web/js/ui/tadl/actor/user/combodata.js | 59 ++++++ Open-ILS/web/js/ui/tadl/actor/user/register.js | 230 ++++++++++++++++++++- .../tadl.templates/default/actor/user/register.tt2 | 18 +- .../default/actor/user/register_table.tt2 | 144 ++++++++++++- 7 files changed, 447 insertions(+), 15 deletions(-) create mode 100644 Open-ILS/web/js/ui/tadl/actor/user/combodata.js diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 602ee6b874..f1bd9b9b27 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -4362,9 +4362,12 @@ SELECT usr, + + + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 8b56e9757a..9140233b8b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -775,6 +775,7 @@ sub _add_update_cards { my $session = shift; my $patron = shift; my $new_patron = shift; + my $user = shift; my $evt; @@ -786,7 +787,7 @@ sub _add_update_cards { if(ref($card) and $card->isnew()) { $virtual_id = $card->id(); - ( $card, $evt ) = _add_card($session,$card); + ( $card, $evt ) = _add_card($session,$card,$user); return (undef, $evt) if $evt; #if(ref($patron->card)) { $patron->card($patron->card->id); } @@ -807,8 +808,9 @@ sub _add_update_cards { # adds an card to the db and returns the card with new id sub _add_card { - my( $session, $card ) = @_; + my( $session, $card, $user ) = @_; $card->clear_id(); + $card->creator($user->id); $logger->info("Adding new patron card ".$card->barcode); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm index 392febe999..cbcbf9a3ad 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/actor.pm @@ -142,7 +142,7 @@ use base qw/actor/; __PACKAGE__->table( 'actor_card' ); __PACKAGE__->columns( Primary => qw/id/ ); -__PACKAGE__->columns( Essential => qw/usr barcode active/ ); +__PACKAGE__->columns( Essential => qw/usr barcode active creator create_date/ ); #------------------------------------------------------------------------------- package actor::user_access_entry; diff --git a/Open-ILS/web/js/ui/tadl/actor/user/combodata.js b/Open-ILS/web/js/ui/tadl/actor/user/combodata.js new file mode 100644 index 0000000000..f9d04c9d45 --- /dev/null +++ b/Open-ILS/web/js/ui/tadl/actor/user/combodata.js @@ -0,0 +1,59 @@ +var comboData = { + "address_types": { + "label":"type", + "identifier":"type", + "items":[ + {"type":"MAILING"}, + {"type":"PHYSICAL"}, + {"type":"JUVENILE"}, + {"type":"GUARDIAN"}, + {"type":"SCHOOL"}, + {"type":"ALTERNATE"}, + {"type":"INSTITUTION"} + ] + }, + + "suffixes": { + "label":"suffix", + "identifier":"suffix", + "items":[ + {"suffix":"Jr"}, + {"suffix":"Sr"}, + {"suffix":"II"}, + {"suffix":"III"}, + {"suffix":"AA"}, + {"suffix":"AS"}, + {"suffix":"AAS"}, + {"suffix":"BA"}, + {"suffix":"BS"}, + {"suffix":"CFPIM"}, + {"suffix":"CPA"}, + {"suffix":"CPIM"}, + {"suffix":"CPM"}, + {"suffix":"CXE"}, + {"suffix":"DC"}, + {"suffix":"DDS"}, + {"suffix":"DO"}, + {"suffix":"DPM"}, + {"suffix":"DVM"}, + {"suffix":"Esq"}, + {"suffix":"FACAAI"}, + {"suffix":"FACP"}, + {"suffix":"FACS"}, + {"suffix":"FACEP"}, + {"suffix":"FCP"}, + {"suffix":"FICS"}, + {"suffix":"GYN"}, + {"suffix":"JD"}, + {"suffix":"LPN"}, + {"suffix":"MA"}, + {"suffix":"MCSE"}, + {"suffix":"MD"}, + {"suffix":"MS"}, + {"suffix":"NMD"}, + {"suffix":"OB"}, + {"suffix":"PhD"}, + {"suffix":"RN"} + ] + } +}; diff --git a/Open-ILS/web/js/ui/tadl/actor/user/register.js b/Open-ILS/web/js/ui/tadl/actor/user/register.js index f74b110651..371e3f134e 100644 --- a/Open-ILS/web/js/ui/tadl/actor/user/register.js +++ b/Open-ILS/web/js/ui/tadl/actor/user/register.js @@ -46,6 +46,7 @@ var optInSettings; var allCardsTemplate; var uEditCloneCopyAddr; // if true, copy addrs on clone instead of link var homeOuTypes = {}; +var comboStores = {}; var dupeUsrname = false; var dupeBarcode = false; @@ -226,10 +227,20 @@ function load() { loadSurveys(); checkClaimsReturnCountPerm(); checkClaimsNoCheckoutCountPerm(); + checkBarPatronPerm(); + checkUnBarPatronPerm(); dojo.connect(replaceBarcode, 'onClick', replaceCardHandler); dojo.connect(allCards, 'onClick', drawAllCards); - if(patron.cards().length > 1) + dojo.connect(clearAlert, 'onClick', clearMessage); + dojo.connect(asAdult, 'onClick', RegAsAdult); + dojo.connect(plus, 'onClick', addOneMonth); + dojo.connect(plus6, 'onClick', addSixMonths); + dojo.connect(plus1, 'onClick', addOneYear); + dojo.connect(plus3, 'onClick', addThreeYears); + dojo.connect(genISM, 'onClick', replaceISMCard); + +// if(patron.cards().length > 1) dojo.removeClass(dojo.byId('uedit-all-barcodes'), 'hidden'); var input = findWidget('ac', 'barcode'); @@ -321,11 +332,25 @@ function drawAllCards() { } var row = allCardsTemplate.cloneNode(true); getByName(row, 'barcode').innerHTML = card.barcode(); + getByName(row, 'creator').innerHTML = card.creator(); + getByName(row, 'create_date').innerHTML = card.create_date(); getByName(row, 'active').appendChild( openils.Util.isTrue(card.active()) ? dojo.byId('true').cloneNode(true) : dojo.byId('false').cloneNode(true) ); + if (openils.Util.isTrue(card.active())){ + var act = new dijit.form.ToggleButton({label:"Disable", onClick: function() {disableCard(card.id());} },"disableButton"); + getByName(row, 'state').appendChild(act.domNode); + }else{ + var act = new dijit.form.Button({label:"Enable", onClick: function() {enableCard(card.id());} },"enableButton"); + getByName(row, 'state').appendChild(act.domNode); + } + if (!first) { + var pri = new dijit.form.Button({label:"Make Primary", onClick: function() {makePrimaryCard(card.id());} },"primaryButton"); + getByName(row, 'primary').appendChild(pri.domNode); + } + tbody.appendChild(row); first = false; @@ -335,6 +360,100 @@ function drawAllCards() { allCardsDialog.show(); } +function disableCard(id) { + var old = patron.cards().filter(function(c){return (c.id() == id)})[0]; + old.active('f'); + old.ischanged(1); + dojo.removeClass(dojo.byId('changesPending'),"hidden"); +} + +function enableCard(id) { + var old = patron.cards().filter(function(c){return (c.id() == id)})[0]; + old.active('t'); + old.ischanged(1); + dojo.removeClass(dojo.byId('changesPending'),"hidden"); +} + +function makePrimaryCard(id) { + patron.card().id(id); + patron.ischanged(1); + dojo.removeClass(dojo.byId('changesPending'),"hidden"); +} + + +function clearMessage(){ + var input = findWidget('au', 'alert_message'); + input.widget.attr('disabled', false).attr('readOnly', false).attr('value', null).focus(); +} + +function RegAsAdult(){ + var input = findWidget('au', 'ident_value2'); + input.widget.attr('value', 'REGISTERED AS ADULT').focus(); +} + +function addOneMonth(){ + var expire = findWidget('au', 'expire_date'); + var newDate = new Date(); + newDate.setDate(newDate.getDate() + 30); + expire.widget.attr('value', newDate).focus(); +} +function addSixMonths(){ + var expire = findWidget('au', 'expire_date'); + var newDate = new Date(); + newDate.setDate(newDate.getDate() + 180); + expire.widget.attr('value', newDate).focus(); +} +function addOneYear(){ + var expire = findWidget('au', 'expire_date'); + var newDate = new Date(); + newDate.setDate(newDate.getDate() + 365); + expire.widget.attr('value', newDate).focus(); +} +function addThreeYears(){ + var expire = findWidget('au', 'expire_date'); + var newDate = new Date(); + newDate.setDate(newDate.getDate() + 1095); + expire.widget.attr('value', newDate).focus(); +} + + +function updateSuffix(){ + var suffix = findWidget('au', 'suffix'); + suffix.widget.attr('value',dojo.byId("suffixSelector").value); +} + +function updateAddType(){ + var addType = findWidget('aua', 'address_type'); + addType.widget.attr('value',dojo.byId("addTypeSelector").value); +} + +function replaceISMCard(){ + var input = findWidget('ac', 'barcode'); + var rnd = Math.floor(Math.random()*999999); + rnd = '555'+rnd; + input.widget.attr('disabled', false).attr('readOnly', true).attr('value', rnd).focus(); + genISM.attr('disabled', true); + + var profile = findWidget('au', 'profile'); + profile.widget.attr('value',71); + +if (!patron.isnew()){ + var old = patron.cards().filter(function(c){return (c.id() == patron.card().id())})[0]; + old.active('f'); + old.ischanged(1); + + var newc = new fieldmapper.ac(); + newc.id(uEditCardVirtId--); + newc.isnew(1); + newc.active('t'); + patron.card(newc); + var t = patron.cards(); + if (!t) { t = []; } + t.push(newc); + patron.cards(t); +} +} + /** * Mark the current card inactive, create a new primary card */ @@ -346,7 +465,8 @@ function replaceCardHandler() { // pull old card off the cards list so we don't have a dupe sitting in there if (patron.cards().length > 0) { var old = patron.cards().filter(function(c){return (c.id() == patron.card().id())})[0]; - old.active('f'); + var add = confirm('Deactivate the original card?'); + if (add) old.active('f'); old.ischanged(1); } @@ -370,6 +490,17 @@ function generatePasswordHandler() { f.widget.attr('value', patron.passwd()); f = findWidget('au', 'passwd2'); f.widget.attr('value', patron.passwd()); +//MIEG: if you use the phone number, reset to the phone number + if(uEditUsePhonePw) { + // if configured, use the last four digits of the day phone number as the password + var newVal = findWidget('au', 'day_phone').widget.value; + if(newVal && newVal.length >= 4) { + var pw1 = findWidget('au', 'passwd').widget; + var pw2 = findWidget('au', 'passwd2').widget; + pw1.attr('value', newVal.substring(newVal.length - 4)); + pw2.attr('value', newVal.substring(newVal.length - 4)); + } + } } /** @@ -734,7 +865,7 @@ function fleshFMRow(row, fmcls, args) { else if(isphone && orgSettings['ui.patron.edit.phone.example']) { ftd.appendChild(document.createTextNode(localeStrings.EXAMPLE + orgSettings['ui.patron.edit.phone.example'])); } - else if(fieldIdl.datatype == 'timestamp') { + else if(fieldIdl.datatype == 'timestamp' && !fmfield.match(/expire/)) { ftd.appendChild(document.createTextNode(localeStrings.EXAMPLE + dojo.date.locale.format(new Date(1970,0,31),{selector: "date", fullYear: true, datePattern: (orgSettings['format.date'] ? orgSettings['format.date'] : null)}))); } } @@ -811,6 +942,17 @@ function fleshFMRow(row, fmcls, args) { orgLimitPerms : ['UPDATE_USER'], }; + // handle comboBox data, create store if necessary + if (dojo.attr(row, 'combodata')) { + + var dataName = dojo.attr(row, 'combodata'); + if (!comboStores[dataName]) + comboStores[dataName] = new dojo.data.ItemFileReadStore({data:comboData[dataName]}); + + wargs.dijitArgs.store = comboStores[dataName]; + wargs.dijitArgs.searchAttr = comboData[dataName].identifier; + } + if(fmfield == 'profile') { // fetch profile groups non-async so existing expire_date is // not overwritten when the profile groups arrive and update @@ -889,6 +1031,39 @@ function checkClaimsReturnCountPerm() { ); } +/** + * if the user does not have the BAR_PATRON/UNBAR_PATRON perm + * This function checks the perm and disable/enables the widget. + */ + +function checkBarPatronPerm() { + new openils.User().getPermOrgList( + 'BAR_PATRON', + function(orgList) { + var cr = findWidget('au', 'barred'); + if(orgList.indexOf(patron.home_ou()) == -1) + cr.widget.attr('disabled', true); + else + cr.widget.attr('disabled', false); + }, + true, + true + ); +} +function checkUnBarPatronPerm(){ + new openils.User().getPermOrgList( + 'UNBAR_PATRON', + function(orgList) { + var cr = findWidget('au', 'barred'); + if(orgList.indexOf(patron.home_ou()) == -1) + cr.widget.attr('disabled', true); + else + cr.widget.attr('disabled', false); + }, + true, + true + ); +} function checkClaimsNoCheckoutCountPerm() { new openils.User().getPermOrgList( @@ -970,6 +1145,42 @@ function attachWidgetEvents(fmcls, fmfield, widget) { dojo.connect(widget.widget, 'onChange', function() { var barcode = this.attr('value'); +//MIEG: TADL Michigan ID to barcode voodo +if (barcode.length > 22){ + if (barcode.length == 25) {var bc = barcode.substr(0,13);} + if (barcode.length == 23) {var bc = barcode.substr(0,11);} + var dob = findWidget('au', 'dob'); + var ident = findWidget('au', 'ident_value'); + var id_type = findWidget('au', 'ident_type'); + if (barcode.length == 25) { + var bc = barcode.substr(0,13); + if (!dob.widget.attr('value')){ + var y = barcode.substr(13,4); + var m = barcode.substr(17,2); + var d = barcode.substr(19,2); + var bdate = new Date(y,m-1,d); + dob.widget.attr('value',bdate); + } + if (!ident.widget.attr('value')) + ident.widget.attr('value',bc); + id_type.widget.attr('value',1); + } + if (barcode.length == 23) { + var bc = barcode.substr(0,11); + if (!dob.widget.attr('value')){ + var y = barcode.substr(11,4); + var m = barcode.substr(15,2); + var d = barcode.substr(17,2); + var bdate = new Date(y,m-1,d); + dob.widget.attr('value',bdate); + } + if (!ident.widget.attr('value')) + ident.widget.attr('value',bc); + id_type.widget.attr('value',4); + } + bc = bc.toLowerCase(); + this.attr('value',bc); +} dupeBarcode = false; dojo.addClass(dojo.byId('uedit-dupe-barcode-warning'), 'hidden'); fieldmapper.standardRequest( @@ -1065,10 +1276,12 @@ function attachWidgetEvents(fmcls, fmfield, widget) { var base = new Date(); base.setTime(base.getTime() - Number(openils.Util.intervalToSeconds(juvInterval) + '000')); - if(newDob <= base) // older than global.juvenile_age_threshold + if(newDob <= base) { // older than global.juvenile_age_threshold juvWidget.widget.attr('value', false); - else + openils.Util.show('parentGuardian'); + } else { juvWidget.widget.attr('value', true); + } } ); return; @@ -1347,6 +1560,13 @@ function _uEditSave(doClone) { case 'au': if(w._fmfield != 'passwd2') patron[w._fmfield](val); +//MIEG: dob kludge + if(w._fmfield == 'dob'){ + var DOB = dojo.date.stamp.fromISOString(val); + DOB = dojo.date.add(DOB,'hour',4); + DOB = dojo.date.stamp.toISOString(DOB); + patron[w._fmfield](DOB); + } break; case 'ac': diff --git a/Open-ILS/web/tadl.templates/default/actor/user/register.tt2 b/Open-ILS/web/tadl.templates/default/actor/user/register.tt2 index a82102064e..14fb3438c7 100644 --- a/Open-ILS/web/tadl.templates/default/actor/user/register.tt2 +++ b/Open-ILS/web/tadl.templates/default/actor/user/register.tt2 @@ -1,6 +1,7 @@ [% ctx.page_title = 'User Editor' %] [% WRAPPER default/base.tt2 %] - + +
@@ -43,18 +44,27 @@