]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/catalog/record/opac.component.ts
LP1907286 Staff catalog sets last retrieved record
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / catalog / record / opac.component.ts
1 import {Component, Input, Renderer2} from '@angular/core';
2 import {DomSanitizer} from '@angular/platform-browser';
3
4 const OPAC_BASE_URL = '/eg/opac/record';
5
6 @Component({
7   selector: 'eg-opac-record-detail',
8   templateUrl: 'opac.component.html'
9 })
10 export class OpacViewComponent {
11
12     url; // SafeResourceUrlImpl
13     loaded: boolean;
14
15     _recordId: number;
16     @Input() set recordId(id: number) {
17
18         // Verify record ID is numeric only
19         if (id && (id + '').match(/^\d+$/)) {
20             this._recordId = id;
21             this.url = this.sanitizer.bypassSecurityTrustResourceUrl(
22                 `${OPAC_BASE_URL}/${id}?readonly=1`);
23         } else {
24             this._recordId = null;
25             this.url = null;
26         }
27     }
28
29     get recordId(): number {
30         return this._recordId;
31     }
32
33     constructor(
34         private sanitizer: DomSanitizer,
35         private renderer: Renderer2) {}
36
37     handleLoad() {
38         const iframe = this.renderer.selectRootElement('#opac-iframe');
39
40         // 50 extra px adds enough space to avoid the scrollbar altogether
41         const height = 50 + iframe.contentWindow.document.body.offsetHeight;
42
43         iframe.style.height = `${height}px`;
44         this.loaded = true;
45     }
46 }
47