1 dump('entering util/print.js\n');
3 if (typeof util == 'undefined') util = {};
4 util.print = function (context) {
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();
11 JSAN.use('util.functional');
12 JSAN.use('util.file');
14 this.context = context || 'default';
16 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
17 var key = 'oils.printer.external.cmd.' + this.context;
18 var has_key = prefs.prefHasUserValue(key);
19 if(!has_key && this.context != 'default') {
20 key = 'oils.printer.external.cmd.default';
21 has_key = prefs.prefHasUserValue(key);
23 this.oils_printer_external_cmd = has_key ? prefs.getCharPref(key) : '';
26 if (prefs.prefHasUserValue('print.always_print_silent')) {
27 if (! prefs.getBoolPref('print.always_print_silent')) {
28 prefs.clearUserPref('print.always_print_silent');
32 dump('Error in print.js trying to clear print.always_print_silent\n');
38 util.print.prototype = {
40 'reprint_last' : function() {
42 var obj = this; obj.data.init({'via':'stash'});
43 if (!obj.data.last_print) {
45 document.getElementById('offlineStrings').getString('printing.nothing_to_reprint')
49 var msg = obj.data.last_print.msg;
50 var params = obj.data.last_print.params; params.no_prompt = false;
51 obj.simple( msg, params );
53 this.error.standard_unexpected_error_alert('util.print.reprint_last',E);
57 'html2txt' : function(html) {
58 JSAN.use('util.text');
59 //dump('html2txt, before:\n' + html + '\n');
60 var lines = html.split(/\n/);
62 for (var i = 0; i < lines.length; i++) {
65 // This undoes the util.text.preserve_string_in_html call that spine_label.js does
66 line = util.text.reverse_preserve_string_in_html(line);
67 // This looks for @hex attributes containing 2-digit hex codes, and converts them into real characters
68 line = line.replace(/(<.+?)hex=['"](.+?)['"](.*?>)/gi, function(str,p1,p2,p3,offset,s) {
70 var hex_chars = p2.match(/[0-9,a-f,A-F][0-9,a-f,A-F]/g);
71 for (var j = 0; j < hex_chars.length; j++) {
72 raw_chars += String.fromCharCode( parseInt(hex_chars[j],16) );
74 return p1 + p3 + raw_chars;
76 line = line.replace(/<head.*?>.*?<\/head>/gi, '');
77 line = line.replace(/<br.*?>/gi,'\r\n');
78 line = line.replace(/<table.*?>/gi,'');
79 line = line.replace(/<tr.*?>/gi,'');
80 line = line.replace(/<hr.*?>/gi,'\r\n');
81 line = line.replace(/<p.*?>/gi,'');
82 line = line.replace(/<block.*?>/gi,'');
83 line = line.replace(/<li.*?>/gi,' * ');
84 line = line.replace(/<.+?>/gi,'');
85 if (line) { new_lines.push(line); }
90 var new_html = new_lines.join('\n');
91 //dump('html2txt, after:\n' + new_html + '\nhtml2txt, done.\n');
95 'simple' : function(msg,params) {
97 if (!params) params = {};
102 obj.data.last_print = { 'msg' : msg, 'params' : params, 'context' : this.context};
103 obj.data.stash('last_print');
106 if ( params && params.no_prompt && (params.no_prompt == true || params.no_prompt == 'true') ) {
111 if (params && params.content_type) {
112 content_type = params.content_type;
114 content_type = 'text/html';
119 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
120 obj.data.init({'via':'stash'});
122 if (typeof obj.data.print_strategy == 'undefined') {
123 obj.data.print_strategy = {};
124 obj.data.stash('print_strategy');
127 if (params.print_strategy || obj.data.print_strategy[obj.context] || obj.data.print_strategy['default']) {
129 switch(params.print_strategy || obj.data.print_strategy[obj.context] || obj.data.print_strategy['default']) {
131 params.dos_print = true;
133 /* FIXME - this it a kludge.. we're going to sidestep window-based html rendering for printing */
134 /* I'm using regexps to mangle the html receipt templates; it'd be nice to use xsl but the */
135 /* templates aren't guaranteed to be valid xml. The unadulterated msg is still preserved in */
137 if (content_type=='text/html') {
138 w = obj.html2txt(msg);
142 if (! params.no_form_feed) { w = w + '\f'; }
143 obj.NSPrint(w, silent, params);
149 switch(content_type) {
151 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 */ }');
152 var print_url = 'data:text/html,'
153 + '<html id="top"><head><script src="/xul/server/main/JSAN.js"></script><script src="' + window.escape(jsrc) + '"></script></head>'
154 + '<body onload="try{my_init();}catch(E){alert(E);}">' + window.escape(msg) + '</body></html>';
155 w = obj.win.open(print_url,'receipt_temp','chrome,resizable');
157 w.go_print = function() {
159 obj.NSPrint(w, silent, params);
161 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);
164 w.minimize(); w.close();
168 w = obj.win.open('data:' + content_type + ',' + window.escape(msg),'receipt_temp','chrome,resizable');
173 obj.NSPrint(w, silent, params);
175 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);
178 w.minimize(); w.close();
185 this.error.standard_unexpected_error_alert('util.print.simple',E);
189 'tree_list' : function (params) {
191 dump('print.tree_list.params.list = \n' + this.error.pretty_print(js2JSON(params.list)) + '\n');
192 dump('print.tree_list.params.data = \n' + this.error.pretty_print(js2JSON(params.data)) + '\n');
198 if (params.header) s += this.template_sub( params.header, cols, params );
200 for (var i = 0; i < params.list.length; i++) {
201 params.row = params.list[i];
203 s += this.template_sub( params.line_item, cols, params );
206 if (params.footer) s += this.template_sub( params.footer, cols, params );
208 if (params.sample_frame) {
209 var jsrc = 'data:text/javascript,' + window.escape('var params = { "data" : ' + js2JSON(params.data) + ', "list" : ' + js2JSON(params.list) + '};');
210 params.sample_frame.setAttribute('src','data:text/html,<html id="top"><head><script src="' + window.escape(jsrc) + '"></script></head><body>' + window.escape(s) + '</body></html>');
212 this.simple(s,params);
216 'template_sub' : function( msg, cols, params ) {
219 if (!msg) { dump('template sub called with empty string\n'); return; }
220 JSAN.use('util.date');
223 try{b = s; s = s.replace(/%LINE_NO%/,Number(params.row_idx)+1);}
224 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
226 try{b = s; s = s.replace(/%patron_barcode%/,params.patron_barcode);}
227 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
229 try{b = s; s = s.replace(/%LIBRARY%/,params.lib.name());}
230 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
231 try{b = s; s = s.replace(/%PINES_CODE%/,params.lib.shortname());}
232 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
233 try{b = s; s = s.replace(/%SHORTNAME%/,params.lib.shortname());}
234 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
235 try{b = s; s = s.replace(/%STAFF_FIRSTNAME%/,params.staff.first_given_name());}
236 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
237 try{b = s; s = s.replace(/%STAFF_LASTNAME%/,params.staff.family_name());}
238 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
239 try{b = s; s = s.replace(/%STAFF_BARCODE%/,params.staff.barcode); }
240 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
241 try{b = s; s = s.replace(/%STAFF_PROFILE%/,obj.data.hash.pgt[ params.staff.profile() ].name() ); }
242 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
243 try{b = s; s = s.replace(/%PATRON_ALIAS_OR_FIRSTNAME%/,(params.patron.alias() == '' || params.patron.alias() == null) ? params.patron.first_given_name() : params.patron.alias());}
244 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
245 try{b = s; s = s.replace(/%PATRON_ALIAS%/,(params.patron.alias() == '' || params.patron.alias() == null) ? '' : params.patron.alias());}
246 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
247 try{b = s; s = s.replace(/%PATRON_FIRSTNAME%/,params.patron.first_given_name());}
248 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
249 try{b = s; s = s.replace(/%PATRON_LASTNAME%/,params.patron.family_name());}
250 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
251 try{b = s; s = s.replace(/%PATRON_BARCODE%/,typeof params.patron.card() == 'object' ? params.patron.card().barcode() : util.functional.find_id_object_in_list( params.patron.cards(), params.patron.card() ).barcode() ) ;}
252 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
254 try{b = s; s=s.replace(/%TODAY%/g,(new Date()));}
255 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
256 try{b = s; s=s.replace(/%TODAY_m%/g,(util.date.formatted_date(new Date(),'%m')));}
257 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
258 try{b = s; s=s.replace(/%TODAY_TRIM%/g,(util.date.formatted_date(new Date(),'')));}
259 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
260 try{b = s; s=s.replace(/%TODAY_d%/g,(util.date.formatted_date(new Date(),'%d')));}
261 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
262 try{b = s; s=s.replace(/%TODAY_Y%/g,(util.date.formatted_date(new Date(),'%Y')));}
263 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
264 try{b = s; s=s.replace(/%TODAY_H%/g,(util.date.formatted_date(new Date(),'%H')));}
265 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
266 try{b = s; s=s.replace(/%TODAY_I%/g,(util.date.formatted_date(new Date(),'%I')));}
267 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
268 try{b = s; s=s.replace(/%TODAY_M%/g,(util.date.formatted_date(new Date(),'%M')));}
269 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
270 try{b = s; s=s.replace(/%TODAY_D%/g,(util.date.formatted_date(new Date(),'%D')));}
271 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
272 try{b = s; s=s.replace(/%TODAY_F%/g,(util.date.formatted_date(new Date(),'%F')));}
273 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
276 if (typeof params.row != 'undefined') {
277 if (params.row.length >= 0) {
278 alert('debug - please tell the developers that deprecated template code tried to execute');
279 for (var i = 0; i < cols.length; i++) {
280 var re = new RegExp(cols[i],"g");
281 try{b = s; s=s.replace(re, params.row[i]);}
282 catch(E){s = b; this.error.standard_unexpected_error_alert('print.js, template_sub(): 1 string = <' + s + '>',E);}
285 /* for dump_with_keys */
286 for (var i in params.row) {
287 var re = new RegExp('%'+i+'%',"g");
288 try{b = s; s=s.replace(re, params.row[i]);}
289 catch(E){s = b; this.error.standard_unexpected_error_alert('print.js, template_sub(): 2 string = <' + s + '>',E);}
294 if (typeof params.data != 'undefined') {
295 for (var i in params.data) {
296 var re = new RegExp('%'+i+'%',"g");
297 if (typeof params.data[i] == 'string' || typeof params.data[i] == 'number') {
298 try{b = s; s=s.replace(re, params.data[i]);}
299 catch(E){s = b; this.error.standard_unexpected_error_alert('print.js, template_sub(): 3 string = <' + s + '>',E);}
301 /* likely a null, print as an empty string */
302 try{b = s; s=s.replace(re, '');}
303 catch(E){s = b; this.error.standard_unexpected_error_alert('print.js, template_sub(): 3 string = <' + s + '>',E);}
307 } catch(E) { dump(E+'\n'); }
312 var date_format_patt=/%DATE_FORMAT\(\s*([^,]*?)\s*,\s*([^)]*?)\s*\)%/
313 while(match = date_format_patt.exec(s)) {
314 if(match[1] == '' || match[2] == '')
315 s = s.replace(match[0], '');
317 s = s.replace(match[0], util.date.formatted_date(match[1], match[2]));
319 } catch(E) { dump(E+'\n'); }
324 // Pre-trim inside of substrings, and only inside of them
325 // This keeps the trim commands from being truncated
326 var substr_trim_patt=/(%SUBSTR\(-?\d+,?\s*(-?\d+)?\)%.*?)(\s*%-TRIM%|%TRIM-%\s*)(.*?%SUBSTR_END%)/;
327 while(match = substr_trim_patt.exec(s))
328 s = s.replace(match[0], match[1] + match[4]);
329 // Then do the substrings themselves
330 var substr_patt=/%SUBSTR\((-?\d+),?\s*(-?\d+)?\)%(.*?)%SUBSTR_END%/;
331 while(match = substr_patt.exec(s)) {
332 var substring_start = parseInt(match[1]);
333 if(substring_start < 0) substring_start = match[3].length + substring_start;
334 var substring_length = parseInt(match[2]);
335 if(substring_length > 0)
336 s = s.replace(match[0], match[3].substring(substring_start, substring_start + substring_length));
337 else if(substring_length < 0)
338 s = s.replace(match[0], match[3].substring(substring_start + substring_length, substring_start));
340 s = s.replace(match[0], match[3].substring(substring_start));
342 } catch(E) { dump(E+'\n'); }
344 // Cleanup unwanted whitespace
346 s = s.replace(/%TRIM-%\s*/g,'');
347 s = s.replace(/\s*%-TRIM%/g,'');
348 } catch(E) { dump(E+'\n'); }
352 alert('Error in print.js, template_sub(): ' + E);
357 'NSPrint' : function(w,silent,params) {
361 if (!params) params = {};
363 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
364 obj.data.init({'via':'stash'});
366 if (params.print_strategy || obj.data.print_strategy[obj.context] || obj.data.print_strategy['default']) {
368 dump('params.print_strategy = ' + params.print_strategy
369 + ' || obj.data.print_strategy[' + obj.context + '] = ' + obj.data.print_strategy[obj.context]
370 + ' || obj.data.print_strategy[default] = ' + obj.data.print_strategy['default']
371 + ' => ' + ( params.print_strategy || obj.data.print_strategy[obj.context] || obj.data.print_strategy['default'] ) + '\n');
372 switch(params.print_strategy || obj.data.print_strategy[obj.context] || obj.data.print_strategy['default']) {
375 if (typeof w != 'string') {
377 var temp_w = params.msg || w.document.firstChild.innerHTML;
378 if (!params.msg) { params.msg = temp_w; }
379 if (typeof temp_w != 'string') { throw(temp_w); }
380 w = obj.html2txt(temp_w);
382 dump('util.print: Could not use w.document.firstChild.innerHTML with ' + w + ': ' + E + '\n');
383 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
384 w.getSelection().selectAllChildren(w.document.firstChild);
385 w = w.getSelection().toString();
388 obj._NSPrint_custom_print(w,silent,params);
391 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
392 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
393 var originalPrinter = false;
394 if (prefs.prefHasUserValue('print.print_printer')) {
395 // This is for restoring print.print_printer after any print dialog, so that when
396 // window.print gets used again, it uses the configured printer for the right context
397 // (which should only be default--window.print is a kludge and is in limited use),
398 // rather than the printer last used.
399 originalPrinter = prefs.getCharPref('print.print_printer');
401 if (typeof w == 'object') {
403 if (originalPrinter) {
404 prefs.setCharPref('print.print_printer',originalPrinter);
407 if (params.content_type == 'text/plain') {
408 w = window.open('data:text/plain,'+escape(params.msg));
410 w = window.open('data:text/html,'+escape(params.msg));
415 if (originalPrinter) {
416 prefs.setCharPref('print.print_printer',originalPrinter);
427 case 'webBrowserPrint':
429 if (typeof w == 'object') {
430 obj._NSPrint_webBrowserPrint(w,silent,params);
432 if (params.content_type == 'text/plain') {
433 w = window.open('data:text/plain,'+escape(params.msg));
435 w = window.open('data:text/html,'+escape(params.msg));
439 obj._NSPrint_webBrowserPrint(w,silent,params);
453 obj._NSPrint_webBrowserPrint(w,silent,params);
457 alert('Probably not printing: ' + e);
458 this.error.sdump('D_ERROR','PRINT EXCEPTION: ' + js2JSON(e) + '\n');
463 '_NSPrint_custom_print' : function(w,silent,params) {
468 var html = params.msg || w;
470 var txt_file = new util.file('receipt.txt');
471 txt_file.write_content('truncate',text);
472 var text_path = '"' + txt_file._file.path + '"';
475 var html_file = new util.file('receipt.html');
476 html_file.write_content('truncate',html);
477 var html_path = '"' + html_file._file.path + '"';
480 var cmd = params.dos_print ?
481 'copy ' + text_path + ' lpt1 /b\n'
482 : obj.oils_printer_external_cmd.replace('%receipt.txt%',text_path).replace('%receipt.html%',html_path)
485 file = new util.file('receipt.bat');
486 file.write_content('truncate+exec',cmd);
488 file = new util.file('receipt.bat');
490 dump('print exec: ' + cmd + '\n');
491 var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
492 process.init(file._file);
496 dump('process.run = ' + process.run(true, args, args.length) + '\n');
501 //alert('Probably not printing: ' + e);
502 this.error.sdump('D_ERROR','_NSPrint_custom_print PRINT EXCEPTION: ' + js2JSON(e) + '\n');
506 '_NSPrint_webBrowserPrint' : function(w,silent,params) {
509 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
510 var webBrowserPrint = w
511 .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
512 .getInterface(Components.interfaces.nsIWebBrowserPrint);
513 this.error.sdump('D_PRINT','webBrowserPrint = ' + webBrowserPrint);
514 if (webBrowserPrint) {
515 var gPrintSettings = obj.GetPrintSettings();
516 if (silent) gPrintSettings.printSilent = true;
517 else gPrintSettings.printSilent = false;
519 if (params.marginLeft) gPrintSettings.marginLeft = params.marginLeft;
521 webBrowserPrint.print(gPrintSettings, null);
522 this.error.sdump('D_PRINT','Should be printing\n');
524 this.error.sdump('D_ERROR','Should not be printing\n');
527 //alert('Probably not printing: ' + e);
528 // Pressing cancel is expressed as an NS_ERROR_ABORT return value,
529 // causing an exception to be thrown which we catch here.
530 // Unfortunately this will also consume helpful failures
531 this.error.sdump('D_ERROR','_NSPrint_webBrowserPrint PRINT EXCEPTION: ' + js2JSON(e) + '\n');
535 'GetPrintSettings' : function() {
537 //alert('entering GetPrintSettings');
538 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
539 var pref = Components.classes["@mozilla.org/preferences-service;1"]
540 .getService(Components.interfaces.nsIPrefBranch);
541 //alert('pref = ' + pref);
543 this.gPrintSettingsAreGlobal = pref.getBoolPref("print.use_global_printsettings", false);
544 this.gSavePrintSettings = pref.getBoolPref("print.save_print_settings", false);
545 //alert('gPrintSettingsAreGlobal = ' + this.gPrintSettingsAreGlobal + ' gSavePrintSettings = ' + this.gSavePrintSettings);
548 var printService = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
549 .getService(Components.interfaces.nsIPrintSettingsService);
550 if (this.gPrintSettingsAreGlobal) {
551 this.gPrintSettings = printService.globalPrintSettings;
552 //alert('called setPrinterDefaultsForSelectedPrinter');
553 this.setPrinterDefaultsForSelectedPrinter(printService);
555 this.gPrintSettings = printService.newPrintSettings;
556 //alert('used printService.newPrintSettings');
559 this.error.sdump('D_ERROR',"GetPrintSettings() "+e+"\n");
560 //alert("GetPrintSettings() "+e+"\n");
563 return this.gPrintSettings;
566 'setPrinterDefaultsForSelectedPrinter' : function (aPrintService) {
568 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
569 if (this.gPrintSettings.printerName == "") {
570 this.gPrintSettings.printerName = aPrintService.defaultPrinterName;
571 //alert('used .defaultPrinterName');
573 //alert('printerName = ' + this.gPrintSettings.printerName);
575 // First get any defaults from the printer
576 aPrintService.initPrintSettingsFromPrinter(this.gPrintSettings.printerName, this.gPrintSettings);
578 // now augment them with any values from last time
579 aPrintService.initPrintSettingsFromPrefs(this.gPrintSettings, true, this.gPrintSettings.kInitSaveAll);
581 // now augment from our own saved settings if they exist
582 this.load_settings();
585 this.error.sdump('D_ERROR',"setPrinterDefaultsForSelectedPrinter() "+E+"\n");
589 'page_settings' : function() {
591 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
592 this.GetPrintSettings();
593 var PO = Components.classes["@mozilla.org/gfx/printsettings-service;1"].getService(Components.interfaces.nsIPrintOptions);
594 PO.ShowPrintSetupDialog(this.gPrintSettings);
596 this.error.standard_unexpected_error_alert("page_settings()",E);
600 'load_settings' : function() {
603 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
604 var file = new util.file('gPrintSettings.' + this.context);
605 if (file._file.exists()) {
606 temp = file.get_object(); file.close();
607 for (var i in temp) {
608 try { this.gPrintSettings[i] = temp[i]; } catch(E) { error_msg += 'Error trying to set gPrintSettings.'+i+'='+temp[i]+' : ' + js2JSON(E) + '\n'; }
610 } else if (this.context != 'default') {
611 var file = new util.file('gPrintSettings.default');
612 if (file._file.exists()) {
613 temp = file.get_object(); file.close();
614 for (var i in temp) {
615 try { this.gPrintSettings[i] = temp[i]; } catch(E) { error_msg += 'Error trying to set gPrintSettings.'+i+'='+temp[i]+' : ' + js2JSON(E) + '\n'; }
618 this.gPrintSettings.marginTop = 0;
619 this.gPrintSettings.marginLeft = 0;
620 this.gPrintSettings.marginBottom = 0;
621 this.gPrintSettings.marginRight = 0;
622 this.gPrintSettings.headerStrLeft = '';
623 this.gPrintSettings.headerStrCenter = '';
624 this.gPrintSettings.headerStrRight = '';
625 this.gPrintSettings.footerStrLeft = '';
626 this.gPrintSettings.footerStrCenter = '';
627 this.gPrintSettings.footerStrRight = '';
631 this.error.sdump('D_PRINT',error_msg);
632 this.error.yns_alert(
633 document.getElementById('offlineStrings').getString('load_printer_settings_error_description'),
634 document.getElementById('offlineStrings').getString('load_printer_settings_error_title'),
635 document.getElementById('offlineStrings').getString('common.ok'),
642 this.error.standard_unexpected_error_alert("load_settings()",E);
646 'save_settings' : function() {
649 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
650 var file = new util.file('gPrintSettings.' + this.context);
651 if (typeof obj.gPrintSettings == 'undefined') obj.GetPrintSettings();
652 if (obj.gPrintSettings) file.set_object(obj.gPrintSettings);
654 if (this.context == 'default') {
655 // print.print_printer gets used by bare window.print()'s. We sometimes use window.print for the
656 // WebBrowserPrint strategy to workaround bugs with the NSPrint xpcom, and only in the default context.
657 var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
658 prefs.setCharPref('print.print_printer',obj.gPrintSettings.printerName);
661 this.error.standard_unexpected_error_alert("save_settings()",E);
666 dump('exiting util/print.js\n');