webstaff: tweaks to egPrint
authorGalen Charlton <gmc@esilibrary.com>
Tue, 15 Nov 2016 20:40:39 +0000 (15:40 -0500)
committerKathy Lussier <klussier@masslnc.org>
Tue, 22 Nov 2016 19:10:05 +0000 (14:10 -0500)
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 <gmc@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/ui/default/staff/services/print.js

index 960eb1d..30a1751 100644 (file)
@@ -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 = '<link rel="stylesheet" href="'+ egEnv.basePath + 'css/print.css" type="text/css" media="print" /><pre>' + content + '</pre>';
+                        content = '<pre>' + content + '</pre>';
                     }
 
+                    return $http.get(egEnv.basePath + 'css/print.css').then(
+                        function(response) {
+                            content = '<style type="text/css" media="print">' +
+                                      response.data +
+                                      '</style>' +
+                                      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);