added util function for printing an html string; use new func for PO printing; ...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 19 Aug 2010 20:00:14 +0000 (20:00 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 19 Aug 2010 20:00:14 +0000 (20:00 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@17270 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/Util.js
Open-ILS/web/js/ui/default/acq/common/li_table.js

index 08a56bd..a9da87b 100644 (file)
@@ -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)
+        );
+    };
+
 }
 
index 4a24f74..00ae185 100644 (file)
@@ -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());
                     }
                 }
             }