place holds continued
authorBill Erickson <berickxx@gmail.com>
Fri, 16 Nov 2018 20:52:29 +0000 (15:52 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 30 Nov 2018 16:34:20 +0000 (11:34 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html
Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/result/record.component.ts

index f0677be..7f403ff 100644 (file)
@@ -6,6 +6,7 @@
     <div class="col-lg-3">
       <div class="form-check">
         <input class="form-check-input" type="radio" 
+          (change)="holdForChanged()"
           name="holdFor" value="patron" [(ngModel)]="holdFor"/>
         <label class="form-check-label" i18n>
           Place hold for patron by barcode:
@@ -27,6 +28,7 @@
     <div class="col-lg-3">
       <div class="form-check">
         <input class="form-check-input" type="radio" 
+          (change)="holdForChanged()"
           name="holdFor" value="staff" [(ngModel)]="holdFor"/>
         <label class="form-check-label" i18n>
           Place hold for this staff account: {{requestor.usrname()}}
   </div>
 </form>
 
-<h4 class="p-3" i18n>Placing Hold(s) On Records...</h4>
-
+<div class="row font-weight-bold mt-2 ml-1 mr-1">
+  <div class="col-lg-10" i18n>Placing hold(s) on record(s)</div>
+  <div class="col-lg-2" i18n>Holds Status</div>
+</div>
 <ng-container *ngFor="let recId of recordIds">
-  <div class="row mt-2 ml-2 mr-2">
-    <div class="col-lg-12">
+  <div class="row mt-2 ml-1 mr-1">
+    <div class="col-lg-10">
       <eg-bib-summary [recordId]="recId" [expand]="false"></eg-bib-summary> 
     </div>
+    <div class="col-lg-2">
+      <div class="alert alert-info">Hold Pending</div>
+    </div>
   </div>
 </ng-container>
 
index 4d86428..f31dd35 100644 (file)
@@ -23,12 +23,13 @@ export class HoldComponent implements OnInit {
     pickupLib: number;
     notifyEmail: boolean;
     notifyPhone: boolean;
+    notifySms: boolean;
     phoneValue: string;
     suspend: boolean;
     activeDate: string;
     recordIds: number[];
 
-    barcodeInFlight: string;
+    currentUserBarcode: string;
 
     constructor(
         private router: Router,
@@ -52,7 +53,7 @@ export class HoldComponent implements OnInit {
         }
 
         this.holdFor = 'patron';
-        this.requestor = this.user = this.auth.user();
+        this.requestor = this.auth.user();
         this.pickupLib = this.auth.user().ws_ou();
         this.findRecords();
 
@@ -72,10 +73,12 @@ export class HoldComponent implements OnInit {
         console.log('placing hold for ' + this.holdFor);
 
         if (this.holdFor === 'patron') {
-            // Patron lookup occurs via onchange on the barcode
-            // input or via the patron search form.
+            if (this.userBarcode) {
+                this.userBarcodeChanged();
+            }
         } else {
-            this.user = this.requestor;
+            this.currentUserBarcode = '_'; // just for preventing dupes
+            this.getUser(this.requestor.id());
         }
     }
 
@@ -84,17 +87,17 @@ export class HoldComponent implements OnInit {
     }
 
     userBarcodeChanged() {
-        this.user = null;
 
+        // Avoid simultaneous or duplicate lookups
+        if (this.userBarcode === this.currentUserBarcode) { 
+            return; 
+        }
+
+        this.resetForm();
         if (!this.userBarcode) { return; }
 
-        // Avoid simultaneous lookups caused by firing the
-        // keyup handler and change handler in quick succession.
-        // keyup handler applied so barcode scanner will result
-        // in immediate lookup.  change handler for humans 
-        // copy/paste'ing then tabbing through the form or off-clicking.
-        if (this.userBarcode === this.barcodeInFlight) { return; }
-        this.barcodeInFlight = this.userBarcode;
+        this.user = null;
+        this.currentUserBarcode = this.userBarcode;
 
         this.net.request(
             'open-ils.actor',
@@ -117,12 +120,49 @@ export class HoldComponent implements OnInit {
         });
     }
 
+    resetForm() {
+        this.notifyEmail = true;
+        this.notifyPhone = true;
+        this.phoneValue = '';
+        this.pickupLib = this.requestor.ws_ou();
+    }
+
     getUser(id: number) {
-        // TODO fetch user settings for PU lib, etc.
-        this.pcrud.retrieve('au', id).subscribe(user => {
+        this.pcrud.retrieve('au', id, {flesh: 1, flesh_fields: {au: ['settings']}})
+        .subscribe(user => {
             this.user = user;
-            this.notifyPhone = user.day_phone() || user.evening_phone();
-            this.barcodeInFlight = null;
+            this.applyUserSettings();
+        });
+    }
+
+    applyUserSettings() {
+        if (!this.user || !this.user.settings()) { return; }
+
+        // Start with defaults.
+        this.phoneValue = this.user.day_phone() || this.user.evening_phone();
+
+        // Default to work org if placing holds for staff.
+        if (this.user.id() !== this.requestor.id()) {
+            this.pickupLib = this.user.home_ou();
+        }
+
+        this.user.settings().forEach(setting => {
+            const name = setting.name();
+            const value = setting.value();
+
+            if (value === '' || value === null) { return; }
+
+            switch(name) {
+                case 'opac.hold_notify':
+                    this.notifyPhone = Boolean(value.match(/phone/));
+                    this.notifyEmail = Boolean(value.match(/email/));
+                    this.notifySms = Boolean(value.match(/sms/));
+                    break;
+
+                case 'opac.default_pickup_location':
+                    this.pickupLib = value; 
+                    break;
+            }
         });
     }
 }
index cb6567f..b99a4a1 100644 (file)
@@ -64,7 +64,8 @@ export class ResultRecordComponent implements OnInit, OnDestroy {
     }
 
     placeHold(): void {
-        alert('Placing hold on bib ' + this.summary.id);
+        this.router.navigate(['/staff/catalog/hold/T'], 
+            {queryParams: {target: this.summary.id}});
     }
 
     addToList(): void {