import {ToastService} from '@eg/share/toast/toast.service';
import {StringService} from '@eg/share/string/string.service';
import {HtmlToTxtService} from '@eg/share/util/htmltotxt.service';
+
const HATCH_FILE_WRITER_PRINTER = 'hatch_file_writer';
+const HATCH_BROWSER_PRINTING_PRINTER = 'hatch_browser_printing';
@Component({
selector: 'eg-print',
.then(use => this.useHatchPrinting = (use && this.hatch.connect()));
}
+ // Resolves to true if a) Hatch is usable and b) the requested print
+ // context is not using the 'native brower printing' printer.
+ checkHatchEnabledForRequest(printReq: PrintRequest): Promise<boolean> {
+ return this.checkHatchEnabled().then(enabled => {
+ if (!enabled) { return false; }
+
+ return this.serverStore.getItem(`eg.print.config.${printReq.printContext}`)
+ .then(config => {
+ return (
+ !config ||
+ config.printer !== HATCH_BROWSER_PRINTING_PRINTER
+ );
+ });
+ });
+ }
+
handlePrintRequest(printReq: PrintRequest) {
if (this.isPrinting) {
return promise.then(() => {
- return this.checkHatchEnabled().then(enabled => {
+ return this.checkHatchEnabledForRequest(printReq).then(enabled => {
// Insert HTML into the browser DOM for in-browser printing.
if (printReq.text && !enabled) {
show_dialog: printReq.showDialog
});
- return this.checkHatchEnabled().then(enabled => {
+ return this.checkHatchEnabledForRequest(printReq).then(enabled => {
if (enabled) {
this.printViaHatch(printReq);
} else {
<span ng-if="printer.name == 'hatch_file_writer'">
[% l('Hatch File Writer') %]
</span>
- <span ng-if="printer.name != 'hatch_file_writer'">
+ <span ng-if="printer.name == 'hatch_browser_printing'">
+ [% l('Browser Printing') %]
+ </span>
+ <span ng-if="printer.name != 'hatch_file_writer'
+ && printer.name != 'hatch_browser_printing'">
{{printer.name}}
</span>
</a>
value="[% l('No Printer Selected') %]">
<input ng-if="useFileWriter()" type="text" disabled="disabled"
class="form-control" value="[% l('Hatch File Writer') %]"/>
- <input ng-if="printConfig[context].printer && !useFileWriter()"
+ <input ng-if="useBrowserPrinting()" type="text" disabled="disabled"
+ class="form-control" value="[% l('Browser Printing') %]"/>
+ <input ng-if="printConfig[context].printer && !useFileWriter() && !useBrowserPrinting()"
type="text" class="form-control" disabled="disabled"
value="{{printConfig[context].printer}}">
</div><!-- /input-group -->
</div>
</div>
+ <div class="pad-vert"
+ ng-show="!isTestView && hatchIsOpen() && useBrowserPrinting()">
+ <div class="alert alert-info">
+ [% |l %]Hatch Browser Printing sends print requests directly
+to the browser, bypassing the external Hatch print mechanism. No additional
+settings are required.[% END %]
+ </div>
+ </div>
+
<div class="row"
- ng-show="!isTestView && hatchIsOpen() && !useFileWriter()"
+ ng-show="!isTestView && hatchIsOpen() && !useFileWriter() && !useBrowserPrinting()"
<div class="col-md-10">
<div class="row">
<div class="col-md-1"></div>
}
function loadPrinterOptions(name) {
- if (name == 'hatch_file_writer') {
+ if (name == 'hatch_file_writer' || name == 'hatch_browser_printing') {
$scope.printerOptions = {};
} else {
egCore.hatch.getPrinterOptions(name).then(
);
}
+ $scope.useBrowserPrinting = function() {
+ return (
+ $scope.printConfig[$scope.context] &&
+ $scope.printConfig[$scope.context].printer == 'hatch_browser_printing'
+ );
+ }
+
+
// Load startup data....
// Don't bother talking to Hatch if it's not there.
if (!egCore.hatch.hatchAvailable) return;
name: 'hatch_file_writer'
});
+ printers.push({name: 'hatch_browser_printing'});
+
var def = $scope.getPrinterByAttr('is-default', true);
if (!def && printers.length) def = printers[0];
return service.fleshPrintScope(args.scope)
.then(function() { return egHatch.usePrinting(); })
.then(function(useHatch) {
+ if (!useHatch) { return false; }
+ return egHatch.getPrintConfig(args.context || 'default')
+ .then(function(config) {
+ // Avoid using Hatch if the print context calls
+ // for native browser printing.
+ return config.printer != 'hatch_browser_printing';
+ });
+ })
+ .then(function(useHatch) {
var promise = useHatch ?
service.print_via_hatch(args) :
service.print_via_browser(args);