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;
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;
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
/
);
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
/
);
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;
}
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;
}
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;
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;