this.applyTemplate(printReq).then(() => {
// Give templates a chance to render before printing
setTimeout(() => {
- this.dispatchPrint(printReq).then(_ => this.reset());
+ this.dispatchPrint(printReq).then(_ => {
+ this.reset();
+ this.printer.printJobQueued$.emit(printReq);
+ });
});
});
}
return this.checkHatchEnabled().then(enabled => {
if (enabled) {
- this.printViaHatch(printReq);
+ return this.printViaHatch(printReq);
} else {
// Here the needed HTML is already in the page.
window.print();
});
}
- printViaHatch(printReq: PrintRequest) {
+ printViaHatch(printReq: PrintRequest): Promise<any> {
if (!printReq.contentType) {
printReq.contentType = 'text/html';
}
html = `<html><body>${printReq.text}</body></html>`;
}
- this.serverStore.getItem(`eg.print.config.${printReq.printContext}`)
+ return this.serverStore.getItem(
+ `eg.print.config.${printReq.printContext}`)
.then(config => {
let msg: HatchMessage;
});
}
- this.hatch.sendRequest(msg).then(
+ return this.hatch.sendRequest(msg).then(
ok => console.debug('Print request succeeded'),
err => console.warn('Print request failed', err)
);
onPrintRequest$: EventEmitter<PrintRequest>;
+ // Emitted after a print request has been delivered to Hatch or
+ // window.print() has completed. Note window.print() returning
+ // is not necessarily an indication the job has completed.
+ printJobQueued$: EventEmitter<PrintRequest>;
+
constructor(
private locale: LocaleService,
private auth: AuthService,
private store: StoreService
) {
this.onPrintRequest$ = new EventEmitter<PrintRequest>();
+ this.printJobQueued$ = new EventEmitter<PrintRequest>();
}
print(printReq: PrintRequest) {