From ad985ee1228e12be224aff79858e74c3073d71f8 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 15 Nov 2016 15:40:39 -0500 Subject: [PATCH] webstaff: tweaks to egPrint This patch attempts to unbreak receipt and CSV printing by fetching and injecting the print CSS into a style element, as a link element in the print div doesn't seem to get processed. It also automatically clears the content of the print div so that after you print a receipt, the browser print command will print the page, not the receipt. Signed-off-by: Galen Charlton Signed-off-by: Kathy Lussier --- .../web/js/ui/default/staff/services/print.js | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) 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 960eb1d2b8..30a1751ae7 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -91,11 +91,12 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg // (absorption) for browser printing return service.ingest_print_content( args.content_type, args.content, args.scope - ).then(function() { $window.print() }); + ).then(function() { $window.print(); service.clear_print_content(); }); } else { // HTML content is already ingested and accessible // within the page to the printer. $window.print(); + service.clear_print_content(); } } ); @@ -152,7 +153,7 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg // 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. -.directive('egPrintContainer', ['$compile', function($compile) { +.directive('egPrintContainer', ['$compile', '$http', function($compile, $http) { return { restrict : 'AE', scope : {}, // isolate our scope @@ -163,13 +164,34 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg ['$scope','$q','$window','$timeout','egHatch','egPrint','egEnv', function($scope , $q , $window , $timeout , egHatch , egPrint , egEnv) { + egPrint.clear_print_content = function() { + $scope.elm.html(''); + $compile($scope.elm.contents())($scope.$new(true)); + } + egPrint.ingest_print_content = function(type, content, printScope) { if (type == 'text/csv' || type == 'text/plain') { // preserve newlines, spaces, etc. - content = '
' + content + '
'; + content = '
' + content + '
'; } + return $http.get(egEnv.basePath + 'css/print.css').then( + function(response) { + content = '' + + content; + return finish_ingest_print_content(type, content, printScope); + }, + function() { + return finish_ingest_print_content(type, content, printScope); + } + ); + + } + + function finish_ingest_print_content(type, content, printScope) { $scope.elm.html(content); var sub_scope = $scope.$new(true); -- 2.43.2