patched up the dup ident handing in the editor and added server side event
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 19 Jun 2006 15:59:46 +0000 (15:59 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 19 Jun 2006 15:59:46 +0000 (15:59 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4673 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/extras/ils_events.xml
Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/xul/staff_client/server/patron/ue.js

index feecd30..8c82001 100644 (file)
                <desc xml:lang="en-US">The patron has too many overdue items</desc>
        </event>
 
+       <event code='1214' textcode='PATRON_DUP_IDENT1'>
+               <desc xml:lang="en-US">The selected primary identification type and value are in use by another patron</desc>
+       </event>
+
 
 
 
index 3485845..36b9a69 100644 (file)
@@ -386,6 +386,9 @@ sub _add_patron {
                return (undef, OpenILS::Event->new('USERNAME_EXISTS'));
        }
 
+       $evt = _check_dup_ident($session, $patron);
+       return (undef, $evt) if $evt;
+
        $logger->info("Creating new user in the DB with username: ".$patron->usrname());
 
        my $id = $session->request(
@@ -404,11 +407,17 @@ sub _update_patron {
 
        $logger->info("Updating patron ".$patron->id." in DB");
 
+       my $evt;
+
        if(!$noperm) {
-               my $evt = $U->check_perms($user_obj->id, $patron->home_ou, 'UPDATE_USER');
+               $evt = $U->check_perms($user_obj->id, $patron->home_ou, 'UPDATE_USER');
                return (undef, $evt) if $evt;
        }
 
+       $evt = _check_dup_ident($session, $patron);
+       return (undef, $evt) if $evt;
+
+
        # update the password by itself to avoid the password protection magic
        if( $patron->passwd ) {
                my $s = $session->request(
@@ -435,6 +444,29 @@ sub _update_patron {
        return ($patron);
 }
 
+sub _check_dup_ident {
+       my( $session, $patron ) = @_;
+
+       my $search = {
+               ident_type      => $patron->ident_type, 
+               ident_value => $patron->ident_value,
+       };
+
+       $logger->debug("patron update searching for dup ident values: " . 
+               $patron->ident_type . ':' . $patron->ident_value);
+
+       $search->{id} = {'!=' => $patron->id} if $patron->id and $patron->id > 0;
+
+       my $dups = $session->request(
+               'open-ils.storage.direct.actor.user.search_where.atomic', $search )->gather(1);
+
+
+       return OpenILS::Event->new('PATRON_DUP_IDENT1', payload => $patron )
+               if $dups and @$dups;
+
+       return undef;
+}
+
 
 sub _add_update_addresses {
 
index 6430344..0cccd28 100644 (file)
@@ -403,10 +403,14 @@ function uEditSaveUser(cloneme) {
        req.send(true);
        var newuser = req.result();
 
-       if( checkILSEvent(newuser) ) 
-               alert(js2JSON(newuser));
-       else 
+       var evt;
+       if( (evt = checkILSEvent(newuser)) || ! newuser ) {
+               if(evt) alert(js2JSON(newuser));
+               return;
+
+       } else {
                alert($('ue_success').innerHTML);
+       }
 
        if(cloneme) {
                /* if the user we just created was a clone, and we want to clone it,
@@ -463,7 +467,6 @@ function uEditRunDupeSearch(type, search_hash) {
                }
        );
 
-       /*req.callback(uEditHandleDupResults);*/
        req.callback(
                function(r) {
                        uEditHandleDupResults( r.getResultObject(), search_hash, type, container );
@@ -497,16 +500,16 @@ function uEditHandleDupResults(ids, search_hash, type, container) {
        uEditDupHashes[type] = search_hash;
 
        switch(type) {
-               case 'ident1' :
+               case 'ident' :
                        if(confirm($('ue_dup_ident1').innerHTML)) 
-                               uEditShowSearch(type);
+                               uEditShowSearch(null, type);
                        break;
        }
 }
 
 
-function uEditShowSearch(link) {
-       var type = link.getAttribute('type');
+function uEditShowSearch(link,type) {
+       if(!type) type = link.getAttribute('type');
        if(window.xulG)
                window.xulG.spawn_search(uEditDupHashes[type]); 
        else alert('Search would be:\n' + js2JSON(uEditDupHashes[type]));