From 76c2227d0b7b60db80c6b8a9f236ae03479e7617 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 12 Nov 2009 17:03:58 +0000 Subject: [PATCH] Added ability to retrieve/edit a staged user and subsequently save as a "real" user. importing Stage module into Actor.pm Added retrieve by username API to Stage.pm git-svn-id: svn://svn.open-ils.org/ILS/trunk@14882 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Actor.pm | 1 + .../perlmods/OpenILS/Application/Actor/Stage.pm | 24 +++++- Open-ILS/web/js/ui/default/actor/user/register.js | 90 +++++++++++++++++++++- 3 files changed, 111 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index befdb1e2db..3fc2702434 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -30,6 +30,7 @@ use OpenILS::Application::Actor::Container; use OpenILS::Application::Actor::ClosedDates; use OpenILS::Application::Actor::UserGroups; use OpenILS::Application::Actor::Friends; +use OpenILS::Application::Actor::Stage; use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Utils::Penalty; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor/Stage.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor/Stage.pm index b17ff47a1a..2aebb119e0 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor/Stage.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor/Stage.pm @@ -62,7 +62,7 @@ sub user_stage_by_org { my $stage_ids = $e->search_staging_user_stage( [ - { home_ou => $org_id}, + { home_ou => $org_id, complete => 'f'}, { limit => $limit, offset => $offset, order_by => {stgu => 'row_id'} @@ -88,6 +88,28 @@ sub flesh_user_stage { } +__PACKAGE__->register_method ( + method => 'user_stage_by_uname', + api_name => 'open-ils.actor.user.stage.retrieve.by_username', +); + +sub user_stage_by_uname { + my($self, $conn, $auth, $username) = @_; + + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + + my $user = $e->search_staging_user_stage({ + usrname => $username, + complete => 'f' + })->[0] or return $e->event; + + return $e->event unless $e->allowed('VIEW_USER', $user->home_ou); + return flesh_user_stage($e, $user->row_id); +} + + + __PACKAGE__->register_method ( method => 'delete_user_stage', 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 a7d1b83b58..a5ad0cb4fb 100644 --- a/Open-ILS/web/js/ui/default/actor/user/register.js +++ b/Open-ILS/web/js/ui/default/actor/user/register.js @@ -39,6 +39,7 @@ var addrTemplateRows; var cgi; var cloneUser; var cloneUserObj; +var stageUser; if(!window.xulG) var xulG = null; @@ -50,6 +51,7 @@ function load() { cgi = new openils.CGI(); cloneUser = cgi.param('clone'); var userId = cgi.param('usr'); + var stageUname = cgi.param('stage'); if(xulG) { if(xulG.ses) openils.User.authtoken = xulG.ses; @@ -81,9 +83,13 @@ function load() { if(userId) { patron = uEditLoadUser(userId); } else { - patron = uEditNewPatron(); - if(cloneUser) - uEditCopyCloneData(patron); + if(stageUname) { + patron = uEditLoadStageUser(stageUname); + } else { + patron = uEditNewPatron(); + if(cloneUser) + uEditCopyCloneData(patron); + } } @@ -113,6 +119,76 @@ function load() { checkClaimsNoCheckoutCountPerm(); } + +/** + * Loads a staged user and turns them into something the editor can understand + */ +function uEditLoadStageUser(stageUname) { + + var data = fieldmapper.standardRequest( + ['open-ils.actor', 'open-ils.actor.user.stage.retrieve.by_username'], + { params : [openils.User.authtoken, stageUname] } + ); + + stageUser = data.user; + patron = uEditNewPatron(); + + // copy the data into our new user object + for(var key in fieldmapper.IDL.fmclasses.stgu.field_map) { + if(fieldmapper.IDL.fmclasses.au.field_map[key] && !fieldmapper.IDL.fmclasses.stgu.field_map[key].virtual) { + if(data.user[key]() !== null) + patron[key]( data.user[key]() ); + } + } + + // copy the data into our new address objects + // TODO: uses the first mailing address only + if(data.mailing_addresses.length) { + + var mail_addr = new fieldmapper.aua(); + mail_addr.id(-1); // virtual ID + mail_addr.usr(-1); + mail_addr.isnew(1); + patron.mailing_address(mail_addr); + patron.addresses().push(mail_addr); + + for(var key in fieldmapper.IDL.fmclasses.stgma.field_map) { + if(fieldmapper.IDL.fmclasses.aua.field_map[key] && !fieldmapper.IDL.fmclasses.stgma.field_map[key].virtual) { + if(data.mailing_addresses[0][key]() !== null) + mail_addr[key]( data.mailing_addresses[0][key]() ); + } + } + } + + // copy the data into our new address objects + // TODO uses the first billing address only + if(data.billing_addresses.length) { + + var bill_addr = new fieldmapper.aua(); + bill_addr.id(-2); // virtual ID + bill_addr.usr(-1); + bill_addr.isnew(1); + patron.billing_address(bill_addr); + patron.addresses().push(bill_addr); + + for(var key in fieldmapper.IDL.fmclasses.stgba.field_map) { + if(fieldmapper.IDL.fmclasses.aua.field_map[key] && !fieldmapper.IDL.fmclasses.stgba.field_map[key].virtual) { + if(data.billing_addresses[0][key]() !== null) + bill_addr[key]( data.billing_addresses[0][key]() ); + } + } + } + + // TODO: uses the first card only + if(data.cards.length) { + var card = new fieldmapper.ac(); + card.id(-1); // virtual ID + patron.card().barcode(data.cards[0].barcode()); + } + + return patron; +} + /* * clone the home org, phone numbers, and billing/mailing address */ @@ -763,6 +839,7 @@ function _uEditSave(doClone) { newPatron = openils.Util.readResponse(r); if(newPatron) { uEditUpdateUserSettings(newPatron.id()); + if(stageUser) uEditRemoveStage(); uEditFinishSave(newPatron, doClone); } } @@ -770,6 +847,13 @@ function _uEditSave(doClone) { ); } +function uEditRemoveStage() { + var resp = fieldmapper.standardRequest( + ['open-ils.actor', 'open-ils.actor.user.stage.delete'], + { params : [openils.User.authtoken, stageUser.row_id()] } + ) +} + function uEditFinishSave(newPatron, doClone) { if(doClone && cloneUser == null) -- 2.11.0