From 3fd72e1fe72931b67a72a6c8993d36b6885caed0 Mon Sep 17 00:00:00 2001 From: pines Date: Tue, 28 Nov 2006 19:04:44 +0000 Subject: [PATCH] revert to (less) broken print code with the race condition git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_0@6626 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../xul/staff_client/chrome/content/util/print.js | 158 +++++++-------------- .../server/admin/printer_settings.html | 19 +-- .../staff_client/server/admin/printer_settings.js | 10 -- 3 files changed, 55 insertions(+), 132 deletions(-) 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 7343becfb5..b8231f1e0a 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/print.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/print.js @@ -53,42 +53,27 @@ util.print.prototype = { var w; 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 { alert("Please inform the developers that the go_print bug occurred. After this alert, we will try to print again."); window.print(); } /* FIXME - mozilla bug#301560 - xpcom kills it too */ if (' + (typeof params.modal != 'undefined' ? 'true' : 'false') + ') setTimeout(function(){ try { window.print(); window.close(); } catch(E) { alert(E); } },0); }'); - w = obj.win.open('data:text/html,' + window.escape(msg) + '','receipt_temp','chrome,resizable'); - w.minimize(); - w.go_print = function() { - - //setTimeout( - // function() { - try { - obj.NSPrint(w, silent, params); - } catch(E) { - obj.error.standard_unexpected_error_alert("Print Error in util.print.simple. After this dialog we'll try a second print attempt. content_type = " + content_type,E); - w.print(); - } - w.minimize(); w.close(); - // }, 0 - //); - - } + var jsrc = 'data:text/javascript,' + window.escape('var params = { "data" : ' + js2JSON(params.data) + ', "list" : ' + js2JSON(params.list) + '}; function my_init() { return; /* FIXME - mozilla bug#301560 - xpcom kills it too */ if (' + (typeof params.modal != 'undefined' ? 'true' : 'false') + ') setTimeout(function(){ try { window.print(); window.close(); } catch(E) { alert(E); } },0); }'); + w = obj.win.open('data:text/html,' + window.escape(msg) + '','receipt_temp','chrome,resizable'); break; default: w = obj.win.open('data:' + content_type + ',' + window.escape(msg),'receipt_temp','chrome,resizable'); - w.minimize(); - setTimeout( - function() { - try { - obj.NSPrint(w, silent, params); - } catch(E) { - obj.error.standard_unexpected_error_alert("Print Error in util.print.simple. After this dialog we'll try a second print attempt. content_type = " + content_type,E); - w.print(); - } - w.minimize(); w.close(); - }, 1000 - ); break; } + w.minimize(); + + setTimeout( + function() { + try { + obj.NSPrint(w, silent, params); + } catch(E) { + obj.error.sdump('D_ERROR','util.print.simple: ' + E); + w.print(); + } + w.minimize(); w.close(); + }, 0 + ); } catch(E) { this.error.standard_unexpected_error_alert('util.print.simple',E); } @@ -100,10 +85,9 @@ util.print.prototype = { } catch(E) { dump(E+'\n'); } - var cols = []; + var cols; // FIXME -- This could be done better.. instead of finding the columns and handling a tree dump, // we could do a dump_with_keys instead - /* switch(params.type) { case 'offline_checkout' : JSAN.use('circ.util'); @@ -187,7 +171,6 @@ util.print.prototype = { ); break; } - */ var s = this.template_sub( params.header, cols, params ); for (var i = 0; i < params.list.length; i++) { @@ -198,7 +181,7 @@ util.print.prototype = { if (params.sample_frame) { var jsrc = 'data:text/javascript,' + window.escape('var params = { "data" : ' + js2JSON(params.data) + ', "list" : ' + js2JSON(params.list) + '};'); - params.sample_frame.setAttribute('src','data:text/html,' + window.escape(s) + ''); + params.sample_frame.setAttribute('src','data:text/html,' + window.escape(s) + ''); } else { this.simple(s,params); } @@ -253,7 +236,6 @@ util.print.prototype = { try { if (typeof params.row != 'undefined') { if (params.row.length >= 0) { - alert('debug pause'); for (var i = 0; i < cols.length; i++) { var re = new RegExp(cols[i],"g"); try{b = s; s=s.replace(re, params.row[i]);} @@ -287,89 +269,56 @@ util.print.prototype = { var obj = this; try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); - - if (obj.data.print_strategy) { - - switch(obj.data.print_strategy) { - case 'dos.print': - obj._NSPrint_dos_print(w,silent,params); - break; - case 'window.print': - w.print(); - break; - case 'webBrowserPrint': - obj._NSPrint_webBrowserPrint(w,silent,params); - break; - default: - //w.print(); - obj._NSPrint_webBrowserPrint(w,silent,params); - break; - } - - } else { - //w.print(); - obj._NSPrint_webBrowserPrint(w,silent,params); - } - - } catch (e) { - //alert('Probably not printing: ' + e); - this.error.sdump('D_ERROR','PRINT EXCEPTION: ' + js2JSON(e) + '\n'); - } - - }, - - '_NSPrint_dos_print' : function(w,silent,params) { - var obj = this; - try { - /* 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(); - - JSAN.use('util.file'); var file = new util.file('receipt.txt'); - file.write_content('truncate',text); file.close(); - - file = new util.file('receipt.bat'); - if (! file._file.exists()) { - file.write_content('truncate','copy chrome\\open_ils_staff_client\\content\\conf\\receipt.txt lpt1 /b\n'); - file.close(); - file = new util.file('receipt.bat'); - } - - var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess); - process.init(file._file); - - var args = []; - - process.run(true, args, args.length); - - } catch (e) { - //alert('Probably not printing: ' + e); - this.error.sdump('D_ERROR','PRINT EXCEPTION: ' + js2JSON(e) + '\n'); - } - }, - - '_NSPrint_webBrowserPrint' : function(w,silent,params) { - var obj = this; - try { - netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var webBrowserPrint = w .QueryInterface(Components.interfaces.nsIInterfaceRequestor) .getInterface(Components.interfaces.nsIWebBrowserPrint); this.error.sdump('D_PRINT','webBrowserPrint = ' + webBrowserPrint); if (webBrowserPrint) { var gPrintSettings = obj.GetPrintSettings(); + //obj.error.standard_unexpected_error_alert('debugging printer settings #1',gPrintSettings); + //var s = '1: '; for (var i in gPrintSettings) if (i.match(/^paper/)) s += i + ': ' + gPrintSettings[i] + '\n'; alert(s); if (silent) gPrintSettings.printSilent = true; else gPrintSettings.printSilent = false; + //alert('silent = ' + silent + ' printSilent = ' + gPrintSettings.printSilent); if (params) { + /* They can set these now in Local Admin */ + /* + gPrintSettings.marginTop = 0; + gPrintSettings.marginLeft = 0; + gPrintSettings.marginBottom = 0; + gPrintSettings.marginRight = 0; + */ if (params.marginLeft) gPrintSettings.marginLeft = params.marginLeft; } + /* + gPrintSettings.headerStrLeft = ''; + gPrintSettings.headerStrCenter = ''; + gPrintSettings.headerStrRight = ''; + gPrintSettings.footerStrLeft = ''; + gPrintSettings.footerStrCenter = ''; + gPrintSettings.footerStrRight = ''; + */ + //this.error.sdump('D_PRINT','gPrintSettings = ' + obj.error.pretty_print(js2JSON(gPrintSettings))); + //alert('gPrintSettings = ' + js2JSON(gPrintSettings)); webBrowserPrint.print(gPrintSettings, null); + //var s = '2: '; for (var i in gPrintSettings) if (i.match(/^paper/)) s += i + ': ' + gPrintSettings[i] + '\n'; alert(s); + + /* This isn't working for kInitSavePageData, so we're going to save gPrintSettings ourselves from the local admin screen */ + /* + if (this.gPrintSettingsAreGlobal && this.gSavePrintSettings) { + var PSSVC = Components.classes["@mozilla.org/gfx/printsettings-service;1"] + .getService(Components.interfaces.nsIPrintSettingsService); + PSSVC.savePrintSettingsToPrefs( gPrintSettings, true, gPrintSettings.kInitSaveAll); + PSSVC.savePrintSettingsToPrefs( gPrintSettings, false, gPrintSettings.kInitSavePrinterName); + } + */ + //var s = '3: '; for (var i in gPrintSettings) if (i.match(/^paper/)) s += i + ': ' + gPrintSettings[i] + '\n'; alert(s); + //obj.error.standard_unexpected_error_alert('debugging printer settings #3',gPrintSettings); + //this.error.sdump('D_PRINT','gPrintSettings 2 = ' + obj.error.pretty_print(js2JSON(gPrintSettings))); + //alert('Should be printing\n'); this.error.sdump('D_PRINT','Should be printing\n'); } else { + //alert('Should not be printing\n'); this.error.sdump('D_ERROR','Should not be printing\n'); } } catch (e) { @@ -379,6 +328,7 @@ util.print.prototype = { // Unfortunately this will also consume helpful failures this.error.sdump('D_ERROR','PRINT EXCEPTION: ' + js2JSON(e) + '\n'); } + }, 'GetPrintSettings' : function() { diff --git a/Open-ILS/xul/staff_client/server/admin/printer_settings.html b/Open-ILS/xul/staff_client/server/admin/printer_settings.html index fdb05b3070..49cd7e2e66 100644 --- a/Open-ILS/xul/staff_client/server/admin/printer_settings.html +++ b/Open-ILS/xul/staff_client/server/admin/printer_settings.html @@ -1,29 +1,12 @@ - - - - - - - - - - - + -

Normal Settings



-

Advanced Settings

- - -

- Warning: The alternate (DOS LPT1) print strategy will ignore the printer settings made in the "Normal Settings" section. In Windows, you must map your printer to the LPT1 port, under Start Menu -> Printers and Faxes -> your printer -> right-click, Properties -> Ports. Also, HTML styling such as different font weights and sizes will be lost when using the DOS LPT1 print. Data is sent to the printer as simple text in this case. -

diff --git a/Open-ILS/xul/staff_client/server/admin/printer_settings.js b/Open-ILS/xul/staff_client/server/admin/printer_settings.js index 80c759a975..e768b43ddb 100644 --- a/Open-ILS/xul/staff_client/server/admin/printer_settings.js +++ b/Open-ILS/xul/staff_client/server/admin/printer_settings.js @@ -37,14 +37,4 @@ g.printer_settings = function() { g.print.save_settings(); } -g.set_print_strategy = function(which) { - netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); - JSAN.use('util.file'); var file = new util.file('print_strategy'); - file.write_content( 'truncate', String( which ) ); - file.close(); - JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); - data.print_strategy = which; data.stash('print_strategy'); - alert('Print strategy (' + which + ') saved to file system.'); -} - g.save_settings = function() { g.print.save_settings(); } -- 2.11.0