LP1816475: make resources bookable if they aren't already
authorJane Sandberg <sandbej@linnbenton.edu>
Sat, 6 Apr 2019 20:30:01 +0000 (13:30 -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.ts

index e3a6ac9..ab9cbf6 100644 (file)
@@ -1,8 +1,8 @@
-import { Component, Input, OnInit, AfterViewInit, QueryList, ViewChildren, ViewChild } from '@angular/core';
+import {Component, Input, OnInit, AfterViewInit, QueryList, ViewChildren, ViewChild} from '@angular/core';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
 import {single} from 'rxjs/operators';
-import { NgbTimeStruct } from '@ng-bootstrap/ng-bootstrap';
-import { AuthService } from '@eg/core/auth.service';
+import {NgbTimeStruct} from '@ng-bootstrap/ng-bootstrap';
+import {AuthService} from '@eg/core/auth.service';
 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
 import {DateSelectComponent} from '@eg/share/date-select/date-select.component';
 import {DateRangeSelectComponent} from '@eg/share/daterange-select/daterange-select.component';
@@ -11,6 +11,7 @@ import {FormatService} from '@eg/core/format.service';
 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 {PcrudService} from '@eg/core/pcrud.service';
 import {ServerStoreService} from '@eg/core/server-store.service';
 import {ToastService} from '@eg/share/toast/toast.service';
@@ -60,6 +61,7 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
     constructor(
         private auth: AuthService,
         private format: FormatService,
+        private net: NetService,
         private pcrud: PcrudService,
         private route: ActivatedRoute,
         private router: Router,
@@ -93,8 +95,23 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
                     this.resourceId = res.id();
                     this.fetchData('resource', this.resourceId);
                 }, (err) => {
-                    this.resourceId = -1;
-                    this.toast.danger('No resource found with this barcode');
+                    this.pcrud.search('acp',
+                        {'barcode' : this.resourceBarcode}, {'limit': 1})
+                    .pipe(single())
+                    .subscribe((item) => {
+                        this.net.request( 'open-ils.booking',
+                       'open-ils.booking.resources.create_from_copies',
+                        this.auth.token(), [item.id()])
+                       .subscribe((response) =>  {
+                            this.toast.info('Made this barcode bookable');
+                            this.resourceId = response['id'];
+                        }, (error) => {
+                            this.toast.danger('Cannot make this barcode bookable');
+                        })
+                    }, (acperror) => {
+                        this.toast.danger('No resource found with this barcode');
+                        this.resourceId = -1;
+                    });
                 });
             }
         });