Return explicit nulls if no matching username / barcode is found (and modify tests...
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 29 Jan 2008 19:14:29 +0000 (19:14 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 29 Jan 2008 19:14:29 +0000 (19:14 +0000)
We suspect JSON::XS started returning '0' instead of 0, which threw off our logic.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@8528 dcc99617-32d9-48b4-a31d-7c20da2025e4

Evergreen/xul/staff_client/server/patron/ue_config.js
Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/web/opac/skin/default/js/myopac.js
Open-ILS/xul/staff_client/server/patron/ue_config.js

index e540314..ab3ba46 100644 (file)
@@ -37,12 +37,12 @@ var barredAlerted = false;
 
 function uEditUsrnameBlur(field) {
        var usrname = uEditNodeVal(field);
-       if(!usrname) return;
+       if (!usrname) { return; }
        var req = new Request(CHECK_USERNAME, SESSION, usrname);
        req.callback( 
                function(r) {
                        var res = r.getResultObject();
-                       if( res && res != patron.id() ) {
+                       if( res !== null && res != patron.id() ) {
                                field.widget.onblur = null; /* prevent alert storm */
                                alertId('ue_dup_username');
                                field.widget.onblur = uEditUsrnameBlur;
@@ -67,7 +67,7 @@ function uEditBarcodeBlur(field) {
        req.callback( 
                function(r) {
                        var res = r.getResultObject();
-                       if( res && res != patron.id() ) {
+                       if( res !== null && res != patron.id() ) {
                                field.widget.onblur = null; /* prevent alert storm */
                                alertId('ue_dup_barcode');
                                field.widget.onblur = uEditBarcodeBlur;
index 9330f96..3cbeaa1 100644 (file)
@@ -2704,7 +2704,7 @@ __PACKAGE__->register_method(
        method => 'usrname_exists',
        api_name        => 'open-ils.actor.username.exists',
        signature => q/
-               Returns 1 if the requested username exists, returns 0 otherwise
+               Returns the user ID of the requested username if that username exists, returns null otherwise
        /
 );
 
@@ -2714,14 +2714,14 @@ sub usrname_exists {
        return $e->event unless $e->checkauth;
        my $a = $e->search_actor_user({usrname => $usrname, deleted=>'f'}, {idlist=>1});
        return $$a[0] if $a and @$a;
-       return 0;
+       return undef;
 }
 
 __PACKAGE__->register_method(
        method => 'barcode_exists',
        api_name        => 'open-ils.actor.barcode.exists',
        signature => q/
-               Returns 1 if the requested barcode exists, returns 0 otherwise
+               Returns the user ID for the requested barcode if that barcode exists, returns null otherwise
        /
 );
 
@@ -2730,8 +2730,8 @@ sub barcode_exists {
        my $e = new_editor(authtoken=>$auth);
        return $e->event unless $e->checkauth;
        my $card = $e->search_actor_card({barcode => $barcode});
-    return 0 unless @$card;
-    return $card->[0]->usr;
+       return undef unless @$card;
+       return $card->[0]->usr;
 }
 
 
index 0e5b49f..e2b6188 100644 (file)
@@ -859,7 +859,14 @@ function myOPACUpdateUsername() {
        var req = new Request(CHECK_USERNAME, G.user.session, username);
        req.send(true);
        var res = req.result();
-       if( res && res == G.user.id() ) {
+       /* If the username does not already exist, res will be null;
+        * we can move on to updating the username.
+        * 
+        * If the username does exist, then res will be the user ID.
+        * G.user.id() gives us the currently authenticated user ID.
+        * If res == G.user.id(), we try to update the username anyways.
+        */
+       if( res !== null && res != G.user.id() ) {
                alertId('myopac_username_dup');
                return;
        }
index 172124a..f5281b9 100644 (file)
@@ -52,12 +52,12 @@ var barredAlerted = false;
 
 function uEditUsrnameBlur(field) {
        var usrname = uEditNodeVal(field);
-       if(!usrname) return;
+       if (!usrname) { return; }
        var req = new Request(CHECK_USERNAME, SESSION, usrname);
        req.callback( 
                function(r) {
                        var res = r.getResultObject();
-                       if( res && res != patron.id() ) {
+                       if( res !== null && res != patron.id() ) {
                                field.widget.onblur = null; /* prevent alert storm */
                                alertId('ue_dup_username');
                                field.widget.onblur = uEditUsrnameBlur;
@@ -81,7 +81,7 @@ function uEditBarcodeBlur(field) {
        req.callback( 
                function(r) {
                        var res = r.getResultObject();
-                       if( res && res != patron.id() ) {
+                       if( res !== null && res != patron.id() ) {
                                field.widget.onblur = null; /* prevent alert storm */
                                alertId('ue_dup_barcode');
                                field.widget.onblur = uEditBarcodeBlur;