1 dump('entering util/print.js\n');
3 if (typeof util == 'undefined') util = {};
4 util.print = function () {
6 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
8 JSAN.use('util.error'); this.error = new util.error();
9 JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init( { 'via':'stash' } );
10 JSAN.use('util.window'); this.win = new util.window();
15 util.print.prototype = {
17 'simple' : function(msg,params) {
19 if (!params) params = {};
23 obj.data.last_print = msg; obj.data.stash('last_print');
26 if (params && params.no_prompt && params.no_prompt == true) silent = true;
28 var w = obj.win.open('data:text/html,<html>' + window.escape(msg) + '</html>','temp','chrome,resizable');
35 obj.NSPrint(w, silent, params);
37 obj.error.sdump('D_ERROR','util.print.simple: ' + E);
40 w.minimize(); w.close();
45 'NSPrint' : function(w,silent,params) {
48 var webBrowserPrint = w
49 .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
50 .getInterface(Components.interfaces.nsIWebBrowserPrint);
51 this.error.sdump('D_PRINT','webBrowserPrint = ' + webBrowserPrint);
52 if (webBrowserPrint) {
53 var gPrintSettings = GetPrintSettings();
54 if (silent) gPrintSettings.printSilent = true;
55 else gPrintSettings.printSilent = false;
57 gPrintSettings.marginTop = 0;
58 gPrintSettings.marginLeft = 0;
59 gPrintSettings.marginBottom = 0;
60 gPrintSettings.marginRight = 0;
61 if (params.marginLeft) gPrintSettings.marginLeft = params.marginLeft;
63 gPrintSettings.headerStrLeft = '';
64 gPrintSettings.headerStrCenter = '';
65 gPrintSettings.headerStrRight = '';
66 gPrintSettings.footerStrLeft = '';
67 gPrintSettings.footerStrCenter = '';
68 gPrintSettings.footerStrRight = '';
69 this.error.sdump('D_PRINT','gPrintSettings = ' + js2JSON(gPrintSettings));
70 //alert('gPrintSettings = ' + js2JSON(gPrintSettings));
71 webBrowserPrint.print(gPrintSettings, null);
72 //alert('Should be printing\n');
73 this.error.sdump('D_PRINT','Should be printing\n');
75 //alert('Should not be printing\n');
76 this.error.sdump('D_PRINT','Should not be printing\n');
79 //alert('Probably not printing: ' + e);
80 // Pressing cancel is expressed as an NS_ERROR_ABORT return value,
81 // causing an exception to be thrown which we catch here.
82 // Unfortunately this will also consume helpful failures, so add a
83 this.error.sdump('D_PRINT','PRINT EXCEPTION: ' + js2JSON(e) + '\n');
84 // if you need to debug
89 'GetPrintSettings' : function() {
91 var pref = Components.classes["@mozilla.org/preferences-service;1"]
92 .getService(Components.interfaces.nsIPrefBranch);
94 this.gPrintSettingsAreGlobal = pref.getBoolPref("print.use_global_printsettings", false);
95 this.gSavePrintSettings = pref.getBoolPref("print.save_print_settings", false);
98 var printService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
99 .getService(Components.interfaces.nsIPrintSettingsService);
100 if (this.gPrintSettingsAreGlobal) {
101 this.gPrintSettings = printService.globalPrintSettings;
102 this.setPrinterDefaultsForSelectedPrinter(printService);
104 this.gPrintSettings = printService.newPrintSettings;
107 this.error.sdump('D_PRINT',"GetPrintSettings() "+e+"\n");
108 //alert("GetPrintSettings() "+e+"\n");
111 return this.gPrintSettings;
114 'setPrinterDefaultsForSelectedPrint' : function (aPrintService) {
115 if (this.gPrintSettings.printerName == "") {
116 this.gPrintSettings.printerName = aPrintService.defaultPrinterName;
119 // First get any defaults from the printer
120 aPrintService.initPrintSettingsFromPrinter(this.gPrintSettings.printerName, this.gPrintSettings);
122 // now augment them with any values from last time
123 aPrintService.initPrintSettingsFromPrefs(this.gPrintSettings, true, this.gPrintSettings.kInitSaveAll);
127 dump('exiting util/print.js\n');