LP#1646166 Hatch printing multi root-node templates
authorBill Erickson <berickxx@gmail.com>
Thu, 16 Feb 2017 17:17:55 +0000 (12:17 -0500)
committerKathy Lussier <klussier@masslnc.org>
Thu, 16 Feb 2017 20:21:36 +0000 (15:21 -0500)
Print templates with no root element or root elements that contained
necessary attributes (id, style, etc.) failed to print correctly in
some casese with Hatch HTML printing because the root node was dropped
after compilation.  This commit changes how we extract the compiled HTML
from the page, using the more reliable method of pulling it directly
from the print element div instead of inspecting the compiled nodes.

Commit also wraps all content in <html/><body/> for good measure.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/ui/default/staff/services/print.js

index 02424a9..67a26b3 100644 (file)
@@ -79,6 +79,8 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
         }
 
         return promise.then(function(html) {
+            // For good measure, wrap the compiled HTML in container tags.
+            html = "<html><body>" + html + "</body></html>";
             return egHatch.remotePrint(
                 args.context || 'default',
                 args.content_type, 
@@ -214,15 +216,12 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
 
                     var resp = $compile($scope.elm.contents())(sub_scope);
 
+
                     var deferred = $q.defer();
                     $timeout(function(){
-                        // give the $digest a chance to complete then
-                        // resolve with the compiled HTML from our
-                        // print container
-
-                        deferred.resolve(
-                            resp.contents()[0].parentNode.innerHTML
-                        );
+                        // give the $digest a chance to complete then resolve
+                        // with the compiled HTML from our print container
+                        deferred.resolve($scope.elm.html());
                     });
 
                     return deferred.promise;