[open-ils-commits] r19316 - trunk/Open-ILS/xul/staff_client/chrome/content/util (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Jan 27 15:58:46 EST 2011


Author: phasefx
Date: 2011-01-27 15:58:41 -0500 (Thu, 27 Jan 2011)
New Revision: 19316

Modified:
   trunk/Open-ILS/xul/staff_client/chrome/content/util/print.js
Log:
Make window.print() configurable.  The "Mozilla Print" strategy is internally identified as 'webBrowserPrint', and it uses XPCOM for printing the contents of an HTML document.  However, in some cases we override this with a 'window.print' strategy to workaround bugs.  A problem with this has been that an actual bare javascript window.print() does not honor any of configured "gPrintSettings".  However, it is informed by (and in turn informs) a Mozilla preference called print.print_printer.  Right now window.print (if used from within the JSAN util.print library) only gets called in when in the Default printer context/role.  So we force print.print_printer to equal the configured printer for the Default role.  Have I mentioned that I hate printing in Mozilla?


Modified: trunk/Open-ILS/xul/staff_client/chrome/content/util/print.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/util/print.js	2011-01-27 16:21:28 UTC (rev 19315)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/util/print.js	2011-01-27 20:58:41 UTC (rev 19316)
@@ -333,8 +333,21 @@
                         obj._NSPrint_custom_print(w,silent,params);
                     break;    
                     case 'window.print':
+                        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
+                        var originalPrinter = false;
+                        if (prefs.prefHasUserValue('print.print_printer')) {
+                            // This is for restoring print.print_printer after any print dialog, so that when
+                            // window.print gets used again, it uses the configured printer for the right context
+                            // (which should only be default--window.print is a kludge and is in limited use),
+                            // rather than the printer last used.
+                            originalPrinter = prefs.getCharPref('print.print_printer');
+                        }
                         if (typeof w == 'object') {
                             w.print();
+                            if (originalPrinter) {
+                                prefs.setCharPref('print.print_printer',originalPrinter);
+                            }
                         } else {
                             if (params.content_type == 'text/plain') {
                                 w = window.open('data:text/plain,'+escape(params.msg));
@@ -344,6 +357,9 @@
                             setTimeout(
                                 function() {
                                     w.print();
+                                    if (originalPrinter) {
+                                        prefs.setCharPref('print.print_printer',originalPrinter);
+                                    }
                                     setTimeout(
                                         function() {
                                             w.close(); 
@@ -580,6 +596,12 @@
             if (typeof obj.gPrintSettings == 'undefined') obj.GetPrintSettings();
             if (obj.gPrintSettings) file.set_object(obj.gPrintSettings); 
             file.close();
+            if (this.context == 'default') {
+                // print.print_printer gets used by bare window.print()'s.  We sometimes use window.print for the
+                // WebBrowserPrint strategy to workaround bugs with the NSPrint xpcom, and only in the default context.
+                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
+                prefs.setCharPref('print.print_printer',obj.gPrintSettings.printerName);
+            }
         } catch(E) {
             this.error.standard_unexpected_error_alert("save_settings()",E);
         }



More information about the open-ils-commits mailing list