]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/cat/vandelay/queued-record.component.ts
LP1615805 No inputs after submit in patron search (AngularJS)
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / cat / vandelay / queued-record.component.ts
1 import {Component} from '@angular/core';
2 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
3 import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap';
4 import {PcrudService} from '@eg/core/pcrud.service';
5 import {IdlObject} from '@eg/core/idl.service';
6
7 @Component({
8     templateUrl: 'queued-record.component.html'
9 })
10 export class QueuedRecordComponent {
11
12     queueId: number;
13     queueType: string;
14     recordId: number;
15     recordTab: string;
16     queuedRecord: IdlObject;
17
18     constructor(
19         private router: Router,
20         private route: ActivatedRoute,
21         private pcrud: PcrudService) {
22
23         this.route.paramMap.subscribe((params: ParamMap) => {
24             this.queueId = +params.get('id');
25             this.recordId = +params.get('recordId');
26             this.queueType = params.get('qtype');
27             this.recordTab = params.get('recordTab');
28             if (this.recordTab === 'edit') {
29                 this.loadRecord();
30             }
31         });
32     }
33
34     // Changing a tab in the UI means changing the route.
35     // Changing the route ultimately results in changing the tab.
36     onNavChange(evt: NgbNavChangeEvent) {
37         this.recordTab = evt.nextId;
38
39         // prevent tab changing until after route navigation
40         evt.preventDefault();
41
42         const url =
43           `/staff/cat/vandelay/queue/${this.queueType}/${this.queueId}` +
44           `/record/${this.recordId}/${this.recordTab}`;
45
46         this.router.navigate([url]);
47     }
48
49     loadRecord() {
50         this.queuedRecord = null;
51         this.pcrud.retrieve((this.queueType === 'bib' ? 'vqbr' : 'vqar'), this.recordId)
52             .subscribe(rec => this.queuedRecord = rec);
53     }
54
55     handleMarcRecordSaved(saveEvent: any) {
56         this.queuedRecord.marc(saveEvent.marcXml);
57         if (this.queueType === 'bib') {
58             this.queuedRecord.bib_source(saveEvent.bibSource);
59         }
60         this.pcrud.update(this.queuedRecord).subscribe(
61             response => {
62                 console.log('response = ', response);
63             }
64         );
65     }
66 }
67