<!ENTITY staff.util.timestamp_dialog.remove_btn.accesskey "R">
<!ENTITY staff.util.timestamp_dialog.apply_btn.label "Apply">
<!ENTITY staff.util.timestamp_dialog.apply_btn.accesskey "A">
-
-
+<!ENTITY staff.printing.set_default "Set Default Printer and Print Test Page">
+<!ENTITY staff.printing.page_settings "Page Settings">
+<!ENTITY staff.printing.normal_settings.header "Normal Settings">
+<!ENTITY staff.printing.advanced_settings.header "Advanced Settings">
+<!ENTITY staff.printing.advanced.mozilla_print "Use default print strategy (Mozilla Print)">
+<!ENTITY staff.printing.advanced.dos_print "Use alternate print strategy (DOS LPT1 Print)">
+<!ENTITY staff.printing.advanced.custom_print "Use alternate print strategy (Custom/External Print)">
+<!ENTITY staff.printing.advanced.dos_print.warning.header "Note on DOS LPT1 Print">
+<!ENTITY staff.printing.advanced.dos_print.warning.text "This print strategy will ignore the printer settings 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, and any advanced templates using Javascript will not work. Data is sent to the printer as simple text. This option is here for legacy purposes, and the Custom/External Print strategy is more flexible.">
+<!ENTITY staff.printing.advanced.custom_print.warning.header "Note on Custom/External Print">
+<!ENTITY staff.printing.advanced.custom_print.warning.text "This print strategy will ignore the printer settings in the "Normal Settings" section. Advanced templates using Javascript may not work, even if the external tool can take the receipt.html file.">
+<!ENTITY staff.printing.advanced.html_templates.warning.header "Also...">
+<!ENTITY staff.printing.advanced.html_templates.warning.text "If using Receipt Templates with either the DOS LPT1 Print strategy or the Custom/External Print strategy (with "receipt.txt"), the client will try to translate any HTML markup to text, but this process may be imperfect, and for the best fidelity you should consider reworking your templates to be plain text if you are using a plain text print strategy. However, if using a plain text print strategy with HTML markup, you may include special character codes in 2-digit hexadecimal in a "hex" attribute for any given element. Such codes will be converted to actual characters and inserted at the place of the tag. For example, &lt;p hex=&quot;0C&quot;&gt;Hello World&lt;/p&gt; will translate to form feed control character + Hello World. &lt;p&gt;Hello World&lt;/p hex=&quot;0C&quot;&gt; will translate to Hello World + form feed control character.">
obj.url = params['url'];
obj.push_xulG = params['push_xulG'];
- obj.alt_print = params['alt_print'];
+ obj.html_source = params['html_source'];
obj.browser_id = params['browser_id'];
obj.debug_label = params['debug_label'];
obj.passthru_content_params = params['passthru_content_params'];
'cmd_print' : [
['command'],
function() {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
- if (obj.alt_print) {
+ try {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+ var content = obj.get_content();
JSAN.use('util.print'); var p = new util.print();
- p.NSPrint(obj.get_content(),false,{});
- } else {
- obj.get_content().print();
+ var print_params = {};
+ if (obj.html_source) {
+ print_params.msg = obj.html_source;
+ }
+ JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
+ if (data.print_strategy == 'webBrowserPrint') {
+ // Override the print strategy temporarily in this context
+ print_params.print_strategy = 'window.print';
+ }
+ p.NSPrint(content,false,print_params);
+ } catch(E) {
+ alert('browser.js, cmd_print exception: ' + E);
}
}
],
var push_xulG = true;
if (xul_param('no_xulG')) push_xulG = false;
- var alt_print = false;
- if (xul_param('alternate_print')) alt_print = true;
-
var p = {
'url' : url,
'push_xulG' : push_xulG,
- 'alt_print' : alt_print,
+ 'html_source' : xul_param('html_source'),
'debug_label' : 'debug'
};
if (typeof window.xulG == 'object' && typeof window.xulG.passthru_content_params == 'object') {
JSAN.use('util.functional');
JSAN.use('util.file');
+ var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
+ var key = 'oils.printer.external.cmd';
+ var has_key = prefs.prefHasUserValue(key);
+ this.oils_printer_external_cmd = has_key ? prefs.getCharPref(key) : '';
+
return this;
};
try {
var obj = this; obj.data.init({'via':'stash'});
if (!obj.data.last_print) {
- alert('Nothing to re-print');
+ alert(
+ document.getElementById('offlineStrings').getString('printing.nothing_to_reprint')
+ );
return;
}
var msg = obj.data.last_print.msg;
}
},
+ 'html2txt' : function(html) {
+ JSAN.use('util.text');
+ //dump('html2txt, before:\n' + html + '\n');
+ var lines = html.split(/\n/);
+ var new_lines = [];
+ for (var i = 0; i < lines.length; i++) {
+ var line = lines[i];
+ if (line) {
+ // This undoes the util.text.preserve_string_in_html call that spine_label.js does
+ line = util.text.reverse_preserve_string_in_html(line);
+ // This looks for @hex attributes containing 2-digit hex codes, and converts them into real characters
+ line = line.replace(/(<.+?)hex=['"](.+?)['"](.*?>)/gi, function(str,p1,p2,p3,offset,s) {
+ var raw_chars = '';
+ var hex_chars = p2.match(/[0-9,a-f,A-F][0-9,a-f,A-F]/g);
+ for (var j = 0; j < hex_chars.length; j++) {
+ raw_chars += String.fromCharCode( parseInt(hex_chars[j],16) );
+ }
+ return p1 + p3 + raw_chars;
+ });
+ line = line.replace(/<head.*?>.*?<\/head>/gi, '');
+ line = line.replace(/<br.*?>/gi,'\r\n');
+ line = line.replace(/<table.*?>/gi,'');
+ line = line.replace(/<tr.*?>/gi,'');
+ line = line.replace(/<hr.*?>/gi,'\r\n');
+ line = line.replace(/<p.*?>/gi,'');
+ line = line.replace(/<block.*?>/gi,'');
+ line = line.replace(/<li.*?>/gi,' * ');
+ line = line.replace(/<.+?>/gi,'');
+ if (line) { new_lines.push(line); }
+ } else {
+ new_lines.push(line);
+ }
+ }
+ var new_html = new_lines.join('\n');
+ //dump('html2txt, after:\n' + new_html + '\nhtml2txt, done.\n');
+ return new_html;
+ },
+
'simple' : function(msg,params) {
try {
if (!params) params = {};
+ params.msg = msg;
var obj = this;
switch(params.print_strategy || obj.data.print_strategy) {
case 'dos.print':
+ params.dos_print = true;
+ case 'custom.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 */
+ /* templates aren't guaranteed to be valid xml. The unadulterated msg is still preserved in */
+ /* params */
if (content_type=='text/html') {
- w = msg.replace(/<br.*?>/gi,'\r\n').replace(/<table.*?>/gi,'\r\n').replace(/<tr.*?>/gi,'\r\n').replace(/<hr.*?>/gi,'\r\n').replace(/<p.*?>/gi,'\r\n').replace(/<block.*?>/gi,'\r\n').replace(/<li.*?>/gi,'\r\n * ').replace(/<.+?>/gi,'');
+ w = obj.html2txt(msg);
} else {
w = msg;
}
- if (! params.no_form_feed) { w = w + '\r\n\r\n\r\n\r\n\r\n\r\n\f'; }
+ if (! params.no_form_feed) { w = w + '\f'; }
obj.NSPrint(w, silent, params);
return;
break;
if (params.print_strategy || obj.data.print_strategy) {
+dump('params.print_strategy = ' + params.print_strategy + ' || obj.data.print_strategy = ' + obj.data.print_strategy + ' => ' + ( params.print_strategy || obj.data.print_strategy ) + '\n');
switch(params.print_strategy || obj.data.print_strategy) {
case 'dos.print':
+ case 'custom.print':
if (typeof w != 'string') {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
- w.getSelection().selectAllChildren(w.document.firstChild);
- w = w.getSelection().toString();
+ try {
+ var temp_w = params.msg || w.document.firstChild.innerHTML;
+ if (!params.msg) { params.msg = temp_w; }
+ if (typeof temp_w != 'string') { throw(temp_w); }
+ w = obj.html2txt(temp_w);
+ } catch(E) {
+ dump('util.print: Could not use w.document.firstChild.innerHTML with ' + w + ': ' + E + '\n');
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+ w.getSelection().selectAllChildren(w.document.firstChild);
+ w = w.getSelection().toString();
+ }
}
- obj._NSPrint_dos_print(w,silent,params);
+ obj._NSPrint_custom_print(w,silent,params);
break;
case 'window.print':
w.print();
},
- '_NSPrint_dos_print' : function(w,silent,params) {
+ '_NSPrint_custom_print' : function(w,silent,params) {
var obj = this;
try {
- /* 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 */
-
- /* NEW way: we just pass in the text */
-
var text = w;
+ var html = params.msg || w;
- var file = new util.file('receipt.txt');
- file.write_content('truncate',text);
- var path = file._file.path;
- file.close();
+ var txt_file = new util.file('receipt.txt');
+ txt_file.write_content('truncate',text);
+ var text_path = '"' + txt_file._file.path + '"';
+ txt_file.close();
+
+ var html_file = new util.file('receipt.html');
+ html_file.write_content('truncate',html);
+ var html_path = '"' + html_file._file.path + '"';
+ html_file.close();
+ var cmd = params.dos_print ?
+ 'copy ' + text_path + ' lpt1 /b\n'
+ : obj.oils_printer_external_cmd.replace('%receipt.txt%',text_path).replace('%receipt.html%',html_path)
+ ;
+
file = new util.file('receipt.bat');
- file.write_content('truncate+exec','#!/bin/sh\ncopy "' + path + '" lpt1 /b\nlpr ' + path + '\n');
+ file.write_content('truncate+exec',cmd);
file.close();
file = new util.file('receipt.bat');
+ dump('print exec: ' + cmd + '\n');
var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(file._file);
} catch (e) {
//alert('Probably not printing: ' + e);
- this.error.sdump('D_ERROR','_NSPrint_dos_print PRINT EXCEPTION: ' + js2JSON(e) + '\n');
+ this.error.sdump('D_ERROR','_NSPrint_custom_print PRINT EXCEPTION: ' + js2JSON(e) + '\n');
}
},
var push_xulG = true;
if (xul_param('no_xulG')) push_xulG = false;
- var alt_print = false;
- if (xul_param('alternate_print')) alt_print = true;
-
var p = {
'url' : url,
'push_xulG' : push_xulG,
- 'alt_print' : alt_print,
+ 'html_source' : xul_param('html_source'),
'debug_label' : 'debug'
}
if (typeof window.xulG == 'object' && typeof window.xulG.passthru_content_params == 'object') {
return text;
}
+util.text.reverse_preserve_string_in_html = function( text ) {
+ text = text.replace(/&/g, '&');
+ text = text.replace(/"/g, '"');
+ text = text.replace(/'/g, "'");
+ text = text.replace(/ /g, ' ');
+ text = text.replace(/</g, '<');
+ text = text.replace(/>/g, '>');
+ return text;
+}
+
dump('exiting util/text.js\n');
staff.cat.opac.title_for_hold_transfer.success.label=Holds transferred.
staff.cat.opac.title_for_hold_transfer.failure.label=Holds not transferred.
staff.cat.create_or_rebarcode_items=Create or Re-barcode Items
+printing.nothing_to_reprint=Nothing to re-print
+printing.prompt_for_external_print_cmd=Enter external print command and parameters (use %receipt.txt% or %receipt.html% as the file containing the print data. Those values will be substituted with the proper path.):
+printing.print_strategy_saved=Print strategy (%1$s) saved to file system.
-<html><head>
+<?xml version='1.0' encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC
+ "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
+ <!--#include virtual="/opac/locale/${locale}/lang.dtd"-->
+]>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <style type='text/css'>
+ .messagecatalog { -moz-binding: url( /xul/server/main/bindings.xml#messagecatalog ) }
+ </style>
<script type="text/javascript" src="/opac/common/js/utils.js"></script>
<script type="text/javascript" src="/opac/common/js/CGI.js"></script>
<script type="text/javascript" src="/opac/common/js/md5.js"></script>
<script type="text/javascript" src="/xul/server/main/JSAN.js"></script>
<script type="text/javascript" src="printer_settings.js"></script>
</head><body onload="try { my_init(); } catch(E) { alert(E); }" style="background: white;">
- <h1>Normal Settings</h1>
+ <div class="messagecatalog" id="offlineStrings" src="/xul/server/locale/<!--#echo var='locale'-->/offline.properties" />
+ <h1>&staff.printing.normal_settings.header;</h1>
<iframe id="sample" src="printer_settings.txt"></iframe><br />
- <button onclick="try { g.printer_settings(); } catch(E) { alert(E); }">Set Default Printer and Print Test Page</button>
- <button onclick="try { g.page_settings(); } catch(E) { alert(E); }">Page Settings</button><br />
- <h1>Advanced Settings</h1>
- <button onclick="try { g.set_print_strategy('webBrowserPrint'); } catch(E) { alert(E); }">Use default print strategy (Mozilla Print)</button>
- <button onclick="try { g.set_print_strategy('dos.print'); } catch(E) { alert(E); }">Use alternate print strategy (DOS LPT1 Print)</button>
+ <button onclick="try { g.printer_settings(); } catch(E) { alert(E); }">&staff.printing.set_default;</button>
+ <button onclick="try { g.page_settings(); } catch(E) { alert(E); }">&staff.printing.page_settings;</button><br />
+ <h1>&staff.printing.advanced_settings.header;</h1>
+ <button onclick="try { g.set_print_strategy('webBrowserPrint'); } catch(E) { alert(E); }">&staff.printing.advanced.mozilla_print;</button>
+ <button onclick="try { g.set_print_strategy('dos.print'); } catch(E) { alert(E); }">&staff.printing.advanced.dos_print;</button>
+ <button onclick="try { g.set_print_strategy('custom.print'); } catch(E) { alert(E); }">&staff.printing.advanced.custom_print;</button>
<p>
- <b>Warning:</b> 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.
+ <dl>
+ <dt><b>&staff.printing.advanced.dos_print.warning.header;</b></dt>
+ <dd>&staff.printing.advanced.dos_print.warning.text;</dd>
+ <dt><b>&staff.printing.advanced.custom_print.warning.header;</b></dt>
+ <dd>&staff.printing.advanced.custom_print.warning.text;</dd>
+ <dt><b>&staff.printing.advanced.html_templates.warning.header;</b></dt>
+ <dd>&staff.printing.advanced.html_templates.warning.text;</dd>
+ </dl>
</p>
</body></html>
JSAN.use('util.print'); g.print = new util.print();
+ g.prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
+
/*
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
g.PSSVC = Components.classes["@mozilla.org/gfx/printsettings-service;1"].getService(Components.interfaces.nsIPrintSettingsService);
g.set_print_strategy = function(which) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+ if (which == 'custom.print') {
+ var key = 'oils.printer.external.cmd';
+ var has_key = g.prefs.prefHasUserValue(key);
+ var value = has_key ? g.prefs.getCharPref(key) : '';
+ var cmd = window.prompt(
+ document.getElementById('offlineStrings').getString('printing.prompt_for_external_print_cmd'),
+ value
+ );
+ if (!cmd) { return; }
+ g.prefs.setCharPref(key,cmd);
+ }
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.');
+ alert(
+ document.getElementById('offlineStrings').getFormattedString('printing.print_strategy_saved',[which])
+ );
}
g.save_settings = function() { g.print.save_settings(); }
}
html += '\n';
}
- html += '</pre>\n';
+ html += '</pre hex="0C">\n';
}
}
html += '</body></html>';
'tab_name' : $("catStrings").getString('staff.cat.spine_labels.preview.title')
},
{
- 'url' : 'data:text/html,'+html,
+ 'url' : 'data:text/html;charset=utf-8,'+window.escape(html),
+ 'html_source' : html,
'show_print_button' : 1,
'no_xulG' : 1
}