LP1816475: improving create fmeditor
authorJane Sandberg <sandbej@linnbenton.edu>
Sun, 7 Apr 2019 07:01:27 +0000 (00:01 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Wed, 17 Apr 2019 20:41:53 +0000 (13:41 -0700)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.html
Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.ts

index e007598..91ad9a6 100644 (file)
 
 <eg-fm-record-editor #newDialog
   idlClass="bresv"
+  datetimeFields="start_time,end_time"
   [fieldOptions]="{usr:{customTemplate:{template:patronTemplate,context:{'patronId':this.patronId}}}}"
   hiddenFields="id,xact_start,request_time,capture_time,pickup_time,return_time,capture_staff,xact_finish,cancel_time,booking_interval,target_resource,unrecovered,request_lib,fine_interval,fine_amount,max_fine">
 </eg-fm-record-editor>
   </ng-container>
 </ng-template>
 <ng-template #patronTemplate let-patronId="patronId">
-  <ng-container *ngIf="patronId">
-    <input type="text" disabled value="{{patronId}}">
-  </ng-container>
+  <input *ngIf="patronId" type="text" disabled value="{{patronId}}" class="form-control" name="usr" (beforeSave$="record['usr'] = patronId">
+  <div *ngIf="!patronId" class="input-group flex-nowrap">
+    <div class="input-group-prepend">
+      <label class="input-group-text" for="patron-barcode" i18n>Patron barcode</label>
+      <input type="text" id="patron-barcode" class="form-control" i18n-placeholder placeholder="Patron barcode" [(ngModel)]="patronBarcode" (change)="findPatronByBarcode()">
+      <input type="hidden" value="{{patronId}}" name="usr" (beforeSave$)="record['usr'] = patronId">
+    </div>
+  </div>
 </ng-template>
index b2bb56a..ad69ad5 100644 (file)
@@ -12,6 +12,7 @@ import {GridComponent} from '@eg/share/grid/grid.component';
 import {GridDataSource,  GridRowFlairEntry} from '@eg/share/grid/grid';
 import {IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
+import {PatronService} from '@eg/staff/share/patron.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {ResourceTypeComboboxComponent} from './resource-type-combobox.component';
 import {ServerStoreService} from '@eg/core/server-store.service';
@@ -33,6 +34,7 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
     isBooked: (col: any, row: any) => string;
     resourceAvailabilityIcon: (row: any) => GridRowFlairEntry;
 
+    patronBarcode: string;
     patronId: number;
     resourceBarcode: string;
     resourceId: number;
@@ -47,6 +49,7 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
     resources: IdlObject[] = [];
     limitByAttr: (attributeId: number, $event: ComboboxEntry) => void;
     useCurrentResourceBarcode: () => void;
+    findPatronByBarcode: () => void;
 
     setGranularity: () => void;
     handleMultiDayReservation: () => void;
@@ -65,6 +68,7 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
         private auth: AuthService,
         private format: FormatService,
         private net: NetService,
+        private patron: PatronService,
         private pcrud: PcrudService,
         private route: ActivatedRoute,
         private router: Router,
@@ -186,6 +190,14 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
                 this.router.navigate(['/staff', 'booking', 'create_reservation', 'for_resource', this.resourceBarcode]);
             }
         };
+        this.findPatronByBarcode = () => {
+            if (this.patronBarcode) {
+                this.patron.bcSearch(this.patronBarcode).pipe(single()).subscribe(
+                    resp => { this.patronId = resp[0].id; },
+                    err => { this.toast.danger('No patron found with this barcode'); },
+                );
+            }
+        };
 
 
     }
@@ -198,7 +210,8 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
 
     showNewDialog(idlThing: IdlObject) {
         return this.newDialog.open({size: 'lg'}).then(
-            ok => {
+            response => {
+               console.log(response);
                 this.toast.success('Reservation successfully created'); // TODO: needs i18n, pluralization
                 this.fetchData();
             },