From 7985a7c9c329fbf24e005a951fbffdf819f6fd9d Mon Sep 17 00:00:00 2001 From: pines Date: Wed, 21 Feb 2007 21:23:39 +0000 Subject: [PATCH] windowless print for dos.print strategy git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_0@6978 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../xul/staff_client/chrome/content/util/print.js | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/util/print.js b/Open-ILS/xul/staff_client/chrome/content/util/print.js index 184b01e40b..8de8d57f63 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/print.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/print.js @@ -52,6 +52,29 @@ util.print.prototype = { } var w; + + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + obj.data.init({'via':'stash'}); + + if (params.print_strategy || obj.data.print_strategy) { + + switch(params.print_strategy || obj.data.print_strategy) { + case 'dos.print': + /* FIXME - this it a kludge.. we're going to sidestep window-based html rendering for printing */ + /* I'm using regexps to mangle the html receipt templates; it'd be nice to use xsl but the */ + /* templates aren't guaranteed to be valid xml */ + if (content_type=='text/html') { + w = msg.replace(//gi,'\r\n').replace(//gi,'\r\n').replace(//gi,'\r\n').replace(//gi,'\r\n').replace(//gi,'\r\n').replace(//gi,'\r\n').replace(//gi,'\r\n * ').replace(/<.+?>/gi,''); + } else { + w = msg; + } + if (! params.no_form_feed) { w = w + '\r\n\f'; } + obj.NSPrint(w, silent, params); + return; + break; + } + } + switch(content_type) { case 'text/html' : var jsrc = 'data:text/javascript,' + window.escape('var params = { "data" : ' + js2JSON(params.data) + ', "list" : ' + js2JSON(params.list) + '}; function my_init() { if (typeof go_print == "function") { go_print(); } else { setTimeout( function() { if (typeof go_print == "function") { alert("Please tell the developers that the 2-second go_print workaround executed, and let them know whether this job printed successfully. Thanks!"); go_print(); } else { alert("Please tell the developers that the 2-second go_print workaround did not work. We will try to print one more time; there have been reports of wasted receipt paper at this point. Please check the settings in the print dialog and/or prepare to power off your printer. Thanks!"); window.print(); } }, 2000 ); } /* FIXME - mozilla bug#301560 - xpcom kills it too */ }'); @@ -238,13 +261,19 @@ util.print.prototype = { var obj = this; try { - /* This is a kludge/workaround. webBrowserPrint doesn't always work. So we're going to let + /* OLD way: This is a kludge/workaround. webBrowserPrint doesn't always work. So we're going to let the html window handle our receipt template rendering, and then force a selection of all the text nodes and dump that to a file, for printing through a dos utility */ + /* netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); w.getSelection().selectAllChildren(w.document.firstChild); var text = w.getSelection().toString(); + */ + + /* NEW way: we just pass in the text */ + + var text = w; var file = new util.file('receipt.txt'); file.write_content('truncate',text); file.close(); -- 2.11.0