]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/circ/patron/summary.component.ts
LP1904036 print/copy patron address; summary styling
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / circ / patron / summary.component.ts
1 import {Component, OnInit, Input} from '@angular/core';
2 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
3 import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap';
4 import {OrgService} from '@eg/core/org.service';
5 import {IdlObject} from '@eg/core/idl.service';
6 import {NetService} from '@eg/core/net.service';
7 import {PatronService} from '@eg/staff/share/patron/patron.service';
8 import {PatronContextService} from './patron.service';
9 import {PrintService} from '@eg/share/print/print.service';
10
11 @Component({
12   templateUrl: 'summary.component.html',
13   styleUrls: ['summary.component.css'],
14   selector: 'eg-patron-summary'
15 })
16 export class SummaryComponent implements OnInit {
17
18     constructor(
19         private org: OrgService,
20         private net: NetService,
21         private printer: PrintService,
22         public patronService: PatronService,
23         public context: PatronContextService
24     ) {}
25
26     ngOnInit() {
27     }
28
29     patron(): IdlObject {
30         return this.context.patron;
31     }
32
33     printAddress(addr: IdlObject) {
34         this.printer.print({
35             templateName: 'patron_address',
36             contextData: {
37                 patron: this.context.patron,
38                 address: addr
39             },
40             printContext: 'default'
41         });
42     }
43
44     copyAddress(addr: IdlObject) {
45         // Note navigator.clipboard requires special permissions.
46         // This is hinky, but gets the job done without the perms.
47
48         const node = document.getElementById(
49             `patron-address-copy-${addr.id()}`) as HTMLTextAreaElement;
50
51         // Un-hide the textarea just long enough to copy its data.
52         // Using node.style instead of *ngIf in hopes it
53         // will be quicker, so the user never sees the textarea.
54         node.style.visibility = 'visible';
55         node.focus();
56         node.select();
57
58         if (!document.execCommand('copy')) {
59             console.error('Copy command failed');
60         }
61
62         node.style.visibility = 'hidden';
63     }
64
65 }
66