{cls: 'ac', path: 'card', field: 'barcode', disabled: !patron.card().isnew()}}">
</ng-container>
<div class="col-lg-6">
- <button class="btn btn-outline-dark" (click)="replaceBarcode()" i18n>
- Replace Barcode
- </button>
- <button class="btn btn-outline-dark ml-2" (click)="barcodesDialog.open()" i18n>
- See All
- </button>
+ <ng-container *ngIf="!patron.isnew()">
+ <button class="btn btn-outline-dark" (click)="replaceBarcode()" i18n>
+ Replace Barcode
+ </button>
+ <button class="btn btn-outline-dark ml-2" (click)="barcodesDialog.open()" i18n>
+ See All
+ </button>
+ </ng-container>
+ <span *ngIf="dupeBarcode" class="text-danger font-weight-bold ml-2" i18n>
+ Barcode is already in use
+ </span>
+ </div>
+ </div>
+
+ <div class="row pt-1 pb-1 mt-1" *ngIf="showField('au.usrname')">
+ <ng-container *ngTemplateOutlet="fieldLabel; context: {args: {field: 'usrname'}}">
+ </ng-container>
+ <ng-container *ngTemplateOutlet="fieldInput; context: {args: {field: 'usrname'}}">
+ </ng-container>
+ <div class="col-lg-6">
+ <span *ngIf="dupeUsername" class="text-danger font-weight-bold ml-2" i18n>
+ Username is already in use
+ </span>
</div>
</div>
- <ng-container *ngTemplateOutlet="fieldRow; context:
- {args: {template: fieldInput, field: 'usrname'}}">
- </ng-container>
<div class="row pt-1 pb-1 mt-1">
<ng-container *ngTemplateOutlet="fieldLabel; context: {args: {field: 'passwd'}}">
</ng-container>
fieldName="au-home_ou-input"
[initialOrgId]="patron.home_ou()"
[disableOrgs]="cannotHaveUsersOrgs()"
+ [required]="true"
(onChange)="
fieldValueChange(null, null, 'home_ou', $event ? $event.id() : null);
afterFieldChange(null, null, 'home_ou')">
<eg-profile-select #profileSelect
[useDisplayEntries]="true"
[initialGroupId]="patron.profile()"
+ [required]="true"
(profileChange)="
fieldValueChange(null, null, 'profile', $event ? $event.id() : null);
afterFieldChange(null, null, 'profile')">
<button class="btn btn-success" (click)="newAddr()" i18n>New Address</button>
- <ng-container *ngIf="showField('stat_cats')">
+ <ng-container *ngIf="showField('stat_cats') && statCats.length > 0">
<div class="alert alert-success pt-2 pb-2 mt-3 mb-3 d-flex">
<div class="m-auto font-weight-bold" i18n>Statistical Categories</div>
</div>
</ng-container>
- <ng-container *ngIf="showField('surveys')">
+ <ng-container *ngIf="showField('surveys') && surveys.length > 0">
<div class="alert alert-success pt-2 pb-2 mt-2 mb-2 d-flex">
<div class="m-auto font-weight-bold" i18n>Surveys</div>
</div>
secondaryGroups: IdlObject[];
expireDate: Date;
changesPending = false;
+ dupeBarcode = false;
+ dupeUsername = false;
+ origUsername: string;
fieldPatterns: {[cls: string]: {[field: string]: RegExp}} = {
au: {},
return this.patronService.getFleshedById(this.patronId)
.then(patron => {
this.patron = patron;
+ this.origUsername = patron.usrname();
this.absorbPatronData();
});
} else {
// Avoid responding to any value changes while we are loading
if (this.loading) { return; }
- // TODO other checks
+ // Timeout gives the form a chance to mark fields as (in)valid
+ setTimeout(() => {
- this.changesPending = true;
- const canSave = document.querySelector('.ng-invalid') === null;
- this.toolbar.disableSaveStateChanged.emit(!canSave);
+ this.changesPending = true;
+
+ const invalidInput = document.querySelector('.ng-invalid');
+
+ if (invalidInput) {
+ console.debug('Field is invalid', invalidInput.id);
+ }
+
+ const canSave = (
+ invalidInput === null &&
+ !this.dupeBarcode &&
+ !this.dupeUsername
+ );
+
+ this.toolbar.disableSaveStateChanged.emit(!canSave);
+ });
}
userStatCatChange(cat: IdlObject, entry: ComboboxEntry) {
break;
case 'barcode':
- // TODO check for dupes open-ils.actor.barcode.exists
- if (!this.patron.usrname()) {
- // This will apply the value and fire the dupe checker
- this.fieldValueChange(null, null, 'usrname', value);
- this.afterFieldChange(null, null, 'usrname');
- }
+ this.handleBarcodeChange(value);
break;
case 'usrname':
- // TODO check for dupes open-ils.actor.username.exists
+ this.handleUsernameChange(value);
break;
}
this.adjustSaveSate();
}
+ handleUsernameChange(value: any) {
+ this.dupeUsername = false;
+
+ if (!value || value === this.origUsername) {
+ // In case the usrname changes then changes back.
+ return;
+ }
+
+ this.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.username.exists',
+ this.auth.token(), value
+ ).subscribe(resp => this.dupeUsername = Boolean(resp));
+ }
+
+ handleBarcodeChange(value: any) {
+ this.dupeBarcode = false;
+
+ if (!value) { return; }
+
+ this.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.barcode.exists',
+ this.auth.token(), value
+ ).subscribe(resp => {
+ if (Number(resp) === 1) {
+ this.dupeBarcode = true;
+ } else {
+
+ if (this.patron.usrname()) { return; }
+
+ // Propagate username with barcode value by default.
+ // This will apply the value and fire the dupe checker
+ this.fieldValueChange(null, null, 'usrname', value);
+ this.afterFieldChange(null, null, 'usrname');
+ }
+ });
+ }
+
dupeValueChange(name: string, value: any) {
if (name.match(/phone/)) { name = 'phone'; }
const nowEpoch = new Date().getTime();
const newDate = new Date(nowEpoch + (seconds * 1000 /* millis */));
this.expireDate = newDate;
- this.fieldValueChange(null, null, 'profile', newDate.toISOString());
- this.afterFieldChange(null, null, 'profile');
+ this.fieldValueChange(null, null, 'expire_date', newDate.toISOString());
+ this.afterFieldChange(null, null, 'expire_date');
}
handleBoolResponse(success: boolean,
} else {
// Create settings for all non-null setting values for new patrons.
- this.userSettings.forEach( (val, key) => {
+ Object.keys(this.userSettings).forEach(key => {
+ const val = this.userSettings[key];
if (val !== null) { settings[key] = val; }
});
}
this.fieldPatterns.au.usrname = new RegExp('.*');
}
}
-
}