]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/print/print.service.ts
LP#1775466 Angular(6) base application
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / print / print.service.ts
1 import {Injectable, EventEmitter, TemplateRef} from '@angular/core';
2 import {StoreService} from '@eg/core/store.service';
3
4 export interface PrintRequest {
5     template?: TemplateRef<any>;
6     contextData?: any;
7     text?: string;
8     printContext: string;
9     contentType?: string; // defaults to text/html
10     showDialog?: boolean;
11 }
12
13 @Injectable()
14 export class PrintService {
15
16     onPrintRequest$: EventEmitter<PrintRequest>;
17
18     constructor(private store: StoreService) {
19         this.onPrintRequest$ = new EventEmitter<PrintRequest>();
20     }
21
22     print(printReq: PrintRequest) {
23         this.onPrintRequest$.emit(printReq);
24     }
25
26     reprintLast() {
27         const prev = this.store.getLocalItem('eg.print.last_printed');
28
29         if (prev) {
30             const req: PrintRequest = {
31                 text: prev.content,
32                 printContext: prev.context || 'default',
33                 contentType: prev.content_type || 'text/html',
34                 showDialog: Boolean(prev.show_dialog)
35             };
36
37             this.print(req);
38         }
39     }
40 }
41