From: erickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Thu, 19 Aug 2010 20:00:14 +0000 (+0000)
Subject: added util function for printing an html string;  use new func for PO printing; ... 
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=49d9ba168fcee4ebeb04fe39dc83b70445f5336f;p=evergreen%2Fpines.git

added util function for printing an html string;  use new func for PO printing;  TODO, use new func in selfcheck code to reduce duplication

git-svn-id: svn://svn.open-ils.org/ILS/trunk@17270 dcc99617-32d9-48b4-a31d-7c20da2025e4
---

diff --git a/Open-ILS/web/js/dojo/openils/Util.js b/Open-ILS/web/js/dojo/openils/Util.js
index 08a56bdae3..a9da87beaf 100644
--- a/Open-ILS/web/js/dojo/openils/Util.js
+++ b/Open-ILS/web/js/dojo/openils/Util.js
@@ -361,5 +361,36 @@ if(!dojo._hasResource["openils.Util"]) {
         dojo.forEach(patterns, function(pat) { _hilightNode(node, pat); });
     };
 
+
+    /**
+     * Takes a chunk of HTML, inserts it into a new window, prints the window, 
+     * then closes the windw.  To provide ample printer queueing time, automatically
+     * wait a short time before closing the window after calling .print().  The amount
+     * of time to wait is based on the size of the data to be printed.
+     * @param html The HTML string
+     * @param callback Optional post-printing callback
+     */
+    openils.Util.printHtmlString = function(html, callback) {
+
+        var win = window.open('', 'Print Window', 'resizable,width=800,height=600,scrollbars=1'); 
+
+        // force the new window to the background
+        win.blur(); 
+        window.focus(); 
+
+        win.document.body.innerHTML = html;
+        win.print();
+
+        setTimeout(
+            function() { 
+                win.close();
+                if(callback)
+                    callback();
+            },
+            // 1k == 1 second pause, max 10 seconds
+            Math.min(html.length, 10000)
+        );
+    };
+
 }
 
diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js
index 4a24f7410f..00ae185bf0 100644
--- a/Open-ILS/web/js/ui/default/acq/common/li_table.js
+++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js
@@ -2076,8 +2076,7 @@ function AcqLiTable() {
                     progressDialog.hide();
                     var evt = openils.Util.readResponse(r);
                     if(evt && evt.template_output()) {
-                        win = window.open('','', 'resizable,width=800,height=600,scrollbars=1');
-                        win.document.body.innerHTML = evt.template_output().data();
+                        openils.Util.printHtmlString(evt.template_output().data());
                     }
                 }
             }