From: Bill Erickson Date: Wed, 11 Jan 2017 19:33:13 +0000 (-0500) Subject: LP#1646166 Hatch print requires no print CSS X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1e2c16fdd6e985acacf869d9317f5f59641cafe5;p=evergreen%2Fpines.git LP#1646166 Hatch print requires no print CSS Avoid inserting the print CSS into the print content when printing remotely. Commit includes some refactoring of the print code to create more obvious separation between remote vs. in-browser printing. Signed-off-by: Bill Erickson Conflicts: Open-ILS/web/js/ui/default/staff/services/print.js --- diff --git a/Open-ILS/web/js/ui/default/staff/services/print.js b/Open-ILS/web/js/ui/default/staff/services/print.js index fa60193683..98fb0c2c45 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -56,49 +56,62 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg) { service.print_content = function(args) { service.fleshPrintScope(args.scope); + var promise = egHatch.hatchAvailable ? + service.print_via_hatch(args) : + service.print_via_browser(args); + + return promise['finally']( + function() { service.clear_print_content() }); + } + + service.print_via_hatch = function(args) { var promise; - if (args.content_type == 'text/html') { - // all HTML content is assumed to require compilation, - // regardless of the print destination + if (args.content_type == 'text/html') { promise = service.ingest_print_content( args.content_type, args.content, args.scope); - } else { - // text content does not require compilation for remote printing + // text content requires no compilation for remote printing. promise = $q.when(args.content); } - // TODO: link print context to template type - var context = args.context || 'default'; return promise.then(function(html) { + return egHatch.remotePrint( + args.context || 'default', + args.content_type, + html, + args.show_dialog + ); + }); + } - return egHatch.remotePrint(context, - args.content_type, html, args.show_dialog)['catch']( + service.print_via_browser = function(args) { + var type = args.content_type; + var content = args.content; + var printScope = args.scope; - function(msg) { - // remote print not available; + if (type == 'text/csv' || type == 'text/plain') { + // preserve newlines, spaces, etc. + content = '
' + content + '
'; + } - if (egHatch.hatchRequired()) { - console.error("Unable to print data; " - + "hatchRequired=true, but hatch is not connected"); - return $q.reject(); - } + // Fetch the print CSS required for in-browser printing. + return $http.get(egEnv.basePath + 'css/print.css') + .then(function(response) { - if (args.content_type != 'text/html') { - // text content does require compilation - // (absorption) for browser printing - return service.ingest_print_content( - args.content_type, args.content, args.scope - ).then(function() { $window.print() }); - } else { - // HTML content is already ingested and accessible - // within the page to the printer. - $window.print(); - } - } - ); + // Add the bare CSS to the content + return '' + + content; + + }).then(function(content) { + // Ingest the content into the page DOM. + return service.ingest_print_content(type, content, printScope); + + }).then(function() { + $window.print(); }); } @@ -145,13 +158,21 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg) { * The div housing eg-print-container must apply the correct * print media CSS to ensure this content (and not the rest * of the page) is printed. + * + * NOTE: There should only ever be 1 egPrintContainer instance per page. + * egPrintContainer attaches functions to the egPrint service with + * closures around the egPrintContainer instance's $scope (including its + * DOM element). Having multiple egPrintContainers could result in chaos. */ +<<<<<<< HEAD // FIXME: only apply print CSS when print commands are issued via the // print container, otherwise using the browser's native print page // option will always result in empty pages. Move the print CSS // out of the standalone CSS file and put it into a template file // for this directive. +======= +>>>>>>> 9ff498f... LP#1646166 Hatch print requires no print CSS .directive('egPrintContainer', ['$compile', function($compile) { return { restrict : 'AE', @@ -163,13 +184,22 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg) { ['$scope','$q','$window','$timeout','egHatch','egPrint', function($scope , $q , $window , $timeout , egHatch , egPrint) { + // Insert the printable content into the DOM. + // For remote printing, this lets us exract the compiled HTML + // from the DOM. + // For local printing, this lets us print directly from the + // DOM with print CSS. + // Returns a promise reolved with the compiled HTML as a string. egPrint.ingest_print_content = function(type, content, printScope) { +<<<<<<< HEAD if (type == 'text/csv' || type == 'text/plain') { // preserve newlines, spaces, etc. content = '
' + content + '
'; } +======= +>>>>>>> 9ff498f... LP#1646166 Hatch print requires no print CSS $scope.elm.html(content); var sub_scope = $scope.$new(true);