<eg-fm-record-editor #newDialog
idlClass="bresv"
[fieldOptions]="{usr:{customTemplate:{template:patronTemplate}},start_time:{customTemplate:{template:datetimeWithDefaults}},end_time:{customTemplate:{template:datetimeWithDefaults}},pickup_lib:{customTemplate:{template:pickupLibrary}},target_resource:{customTemplate:{template:targetResource}}}"
- 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,target_resource,target_resource_type">
+ hiddenFields="id,xact_start,request_time,capture_time,pickup_time,return_time,capture_staff,xact_finish,cancel_time,booking_interval,unrecovered,request_lib,fine_interval,fine_amount,max_fine,current_resource,target_resource_type">
</eg-fm-record-editor>
<ng-template #reservationsTemplate let-row="row" let-col="col">
</eg-combobox>
</ng-container>
</ng-template>
-
import {Component, Input, OnInit, AfterViewInit, QueryList, ViewChildren, ViewChild} from '@angular/core';
import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {forkJoin} from 'rxjs';
import {single} from 'rxjs/operators';
import {NgbDateStruct, NgbTimeStruct} from '@ng-bootstrap/ng-bootstrap';
import {AuthService} from '@eg/core/auth.service';
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 {IdlObject, IdlService} from '@eg/core/idl.service';
import {NetService} from '@eg/core/net.service';
import {OrgService} from '@eg/core/org.service';
import {PatronService} from '@eg/staff/share/patron.service';
advancedCollapsed = true;
attributes: IdlObject[] = [];
+ selectedAttributes: number[] = [];
multiday = false;
handleDateChange: ($event: Date) => void;
resourceAvailabilityIcon: (row: any) => GridRowFlairEntry;
constructor(
private auth: AuthService,
private format: FormatService,
+ private idl: IdlService,
private net: NetService,
private org: OrgService,
private patron: PatronService,
});
this.limitByAttr = (attributeId: number, $event: ComboboxEntry) => {
- console.log('LIMIT');
- console.log('id: ' + attributeId);
- console.log('event: ' + JSON.stringify($event));
+ this.selectedAttributes[attributeId] = $event.id;
+ this.fetchData();
};
this.setGranularity = () => {
} else {
if (this.multiday) { this.defaultTimes['end_time'] = this.defaultTimes['start_time'].clone().add(1, 'days'); }
}
- if (this.resourceId) {
+ if (this.resourceId && !this.resourceTypeId) {
this.pcrud.search('brsrc', {id: this.resourceId}, {
flesh: 1,
limit: 1,
this.pcrud.search('brt', {id: this.resourceTypeId}, {
}).subscribe( t => {
this.transferable = t.transferable();
- this.openTheDialog(rows).then(
- newId => { this.net.request('open-ils.storage', 'open-ils.storage.booking.reservation.resource_targeter', [newId]); }
- );
- });
+ this.openTheDialog(rows).then(newId => {
+ if (this.selectedAttributes.length) {
+ let creates$ = [];
+ this.selectedAttributes.forEach(attrValue => {
+ if (attrValue) {
+ const bravm = this.idl.create('bravm');
+ bravm.attr_value(attrValue);
+ bravm.reservation(newId);
+ creates$.push(this.pcrud.create(bravm));
+ }
+ });
+ forkJoin(...creates$).subscribe(() => {
+ this.net.request('open-ils.storage', 'open-ils.storage.booking.reservation.resource_targeter', [newId]); });
+ } else {
+ this.net.request('open-ils.storage', 'open-ils.storage.booking.reservation.resource_targeter', [newId]);
+ }
+ });
+ })
}
}
}
this.resourceId = null;
this.resourceTypeId = $event.id;
this.attributes = [];
+ this.selectedAttributes = [];
if (this.resourceTypeId) {
this.pcrud.search('bra', {resource_type : this.resourceTypeId}, {
order_by: 'name ASC',
select = {'curr_rsrcs': {'end_time': {'>' : Moment.tz([this.idealDate.getFullYear(), this.idealDate.getMonth(), this.idealDate.getDate()], this.format.wsOrgTimezone).startOf('day').toISOString()},
'start_time': { '<': Moment.tz([this.idealDate.getFullYear(), this.idealDate.getMonth(), this.idealDate.getDate()], this.format.wsOrgTimezone).add(1, 'days').endOf('day').toISOString() }}}
}
+ if (this.selectedAttributes.length) {
+ where['id'] = {"in": {"from": "bram", "select": {"bram": ["resource"]}, "where": {"value": this.selectedAttributes.filter((a) => (a !== null))}}};
+ }
this.scheduleSource.data = [];
this.pcrud.search('brsrc', where, {
order_by: 'barcode ASC',
flesh: 2,
- flesh_fields: {'brsrc': ['curr_rsrcs'], 'bresv': ['usr']},
+ flesh_fields: {'brsrc': ['curr_rsrcs', 'attr_maps'], 'bresv': ['usr']},
select: select
}).subscribe(
r => {