From 4adbcf322472141642e6eccb74fb0bfffef716db Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 21 Jun 2018 15:15:23 -0400 Subject: [PATCH] LP#1775466 AngJS reprint last stores compiled html Store the compiled HTML instead of the source template and source context after each print. With this, reprintLast() doesn't have to recompiled the content. This is particularly useful for sharing printed content between AngularJS and Angular. Signed-off-by: Bill Erickson --- Open-ILS/web/js/ui/default/staff/services/print.js | 37 +++++++++++++--------- 1 file changed, 22 insertions(+), 15 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 fee4c8af8a..d12a6cd84f 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -156,20 +156,17 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg content; }).then(function(content) { - service.last_print.content = content; - service.last_print.content_type = type; - service.last_print.printScope = printScope - - egHatch.setItem('eg.print.last_printed', service.last_print); // Ingest the content into the page DOM. - return service.ingest_print_content( - service.last_print.content_type, - service.last_print.content, - service.last_print.printScope - ); + return service.ingest_print_content(type, content, printScope); + + }).then(function(html) { + + // Note browser ignores print context + service.last_print.content = html; + service.last_print.content_type = type; + egHatch.setItem('eg.print.last_printed', service.last_print); - }).then(function() { $window.print(); }); } @@ -192,9 +189,7 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg } else { promise.then(function () { service.ingest_print_content( - service.last_print.content_type, - service.last_print.content, - service.last_print.printScope + null, null, null, service.last_print.content ).then(function() { $window.print() }); }); } @@ -300,7 +295,19 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg // 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) { + // + // If a pre-compiled HTML string is provided, it's inserted + // as-is into the DOM for browser printing without any + // additional interpolation. This is useful for reprinting, + // previously compiled content. + egPrint.ingest_print_content = + function(type, content, printScope, compiledHtml) { + + if (compiledHtml) { + $scope.elm.html(compiledHtml); + return $q.when(compiledHtml); + } + $scope.elm.html(content); var sub_scope = $scope.$new(true); -- 2.11.0