From: phasefx Date: Mon, 30 Aug 2010 15:39:52 +0000 (+0000) Subject: backport 17375-17379 for context sensitive (role-based) print settings X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=94b9586024adb8df85a7f0a392a8d764ab737bd9;p=contrib%2FConifer.git backport 17375-17379 for context sensitive (role-based) print settings git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_2_0@17380 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index f32e937960..1b906857a3 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -3357,6 +3357,12 @@ + + + + + + diff --git a/Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js b/Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js index 40f2d9a15f..ad7459375a 100644 --- a/Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js +++ b/Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js @@ -431,20 +431,24 @@ OpenILS.data.prototype = { } file.close(); - JSAN.use('util.file'); var file = new util.file('print_strategy'); - if (file._file.exists()) { - try { - var x = file.get_content(); - if (x) { - obj.print_strategy = x; - obj.stash('print_strategy'); - obj.data_progress('Print strategy retrieved from file. '); + obj.print_strategy = {}; + var print_contexts = [ 'default', 'receipt', 'label', 'mail' ]; + for (var i in print_contexts) { + JSAN.use('util.file'); var file = new util.file('print_strategy.' + print_contexts[i]); + if (file._file.exists()) { + try { + var x = file.get_content(); + if (x) { + obj.print_strategy[ print_contexts[i] ] = x; + obj.data_progress('Print strategy ' + print_contexts[i] + ' retrieved from file. '); + } + } catch(E) { + alert(E); } - } catch(E) { - alert(E); } + file.close(); } - file.close(); + obj.stash('print_strategy'); JSAN.use('util.print'); (new util.print()).GetPrintSettings(); obj.data_progress('Printer settings retrieved. '); diff --git a/Open-ILS/xul/staff_client/chrome/content/util/browser.js b/Open-ILS/xul/staff_client/chrome/content/util/browser.js index 16d6253ee3..5759e36a69 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/browser.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/browser.js @@ -26,6 +26,7 @@ util.browser.prototype = { obj.debug_label = params['debug_label']; obj.passthru_content_params = params['passthru_content_params']; obj.on_url_load = params['on_url_load']; + obj.printer_context = params['printer_context'] || 'default'; JSAN.use('util.controller'); obj.controller = new util.controller(); obj.controller.init( @@ -49,7 +50,7 @@ util.browser.prototype = { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var content = obj.get_content(); - JSAN.use('util.print'); var p = new util.print(); + JSAN.use('util.print'); var p = new util.print(obj.printer_context); var print_params = {}; if (obj.html_source) { print_params.msg = obj.html_source; @@ -60,8 +61,22 @@ util.browser.prototype = { print_params.content_type = 'text/plain'; } JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve(); - if (data.print_strategy == 'webBrowserPrint' || !data.print_strategy) { - // Override the print strategy temporarily in this context + // Override the print strategy temporarily if it's not set or is equal to webBrowserPrint (which is buggy here) + if (data.print_strategy) { + if (data.print_strategy[obj.printer_context] || data.print_strategy['default']) { + if (data.print_strategy[obj.printer_context]) { + if (data.print_strategy[obj.printer_context] == 'webBrowserPrint') { + print_params.print_strategy = 'window.print'; + } + } else { + if (data.print_strategy['default'] == 'webBrowserPrint') { + print_params.print_strategy = 'window.print'; + } + } + } else { + print_params.print_strategy = 'window.print'; + } + } else { print_params.print_strategy = 'window.print'; } p.NSPrint(content,false,print_params); diff --git a/Open-ILS/xul/staff_client/chrome/content/util/browser.xul b/Open-ILS/xul/staff_client/chrome/content/util/browser.xul index 1bba3f3e12..01a10e64bb 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/browser.xul +++ b/Open-ILS/xul/staff_client/chrome/content/util/browser.xul @@ -54,6 +54,7 @@ var p = { 'url' : url, 'push_xulG' : push_xulG, + 'printer_context' : xul_param('printer_context'), 'html_source' : xul_param('html_source'), 'debug_label' : 'debug' }; diff --git a/Open-ILS/xul/staff_client/chrome/content/util/list.js b/Open-ILS/xul/staff_client/chrome/content/util/list.js index 421139c43d..e0568a15f6 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/list.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/list.js @@ -33,6 +33,8 @@ util.list.prototype = { JSAN.use('util.widgets'); + obj.printer_context = params.printer_context; + if (typeof params.map_row_to_column == 'function') obj.map_row_to_column = params.map_row_to_column; if (typeof params.map_row_to_columns == 'function') { obj.map_row_to_columns = params.map_row_to_columns; @@ -1265,7 +1267,7 @@ util.list.prototype = { 'dump_csv_to_printer' : function(params) { var obj = this; - JSAN.use('util.print'); var print = new util.print(); + JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context); if (typeof params == 'undefined') params = {}; if (params.no_full_retrieve) { print.simple( obj.dump_csv( params ), {'content_type':'text/plain'} ); @@ -1280,7 +1282,7 @@ util.list.prototype = { 'dump_extended_format_to_printer' : function(params) { var obj = this; - JSAN.use('util.print'); var print = new util.print(); + JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context); if (typeof params == 'undefined') params = {}; if (params.no_full_retrieve) { print.simple( obj.dump_extended_format( params ), {'content_type':'text/plain'} ); @@ -1341,7 +1343,7 @@ util.list.prototype = { function() { try { if (!params.list) params.list = obj.dump_with_keys(); - JSAN.use('util.print'); var print = new util.print(); + JSAN.use('util.print'); var print = new util.print(params.printer_context || obj.printer_context); print.tree_list( params ); if (typeof params.callback == 'function') params.callback(); } catch(E) { 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 8265d3a106..b2970433aa 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/print.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/print.js @@ -1,7 +1,7 @@ dump('entering util/print.js\n'); if (typeof util == 'undefined') util = {}; -util.print = function () { +util.print = function (context) { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); @@ -11,8 +11,10 @@ util.print = function () { JSAN.use('util.functional'); JSAN.use('util.file'); + this.context = context || 'default'; + var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']); - var key = 'oils.printer.external.cmd'; + var key = 'oils.printer.external.cmd.' + this.context; var has_key = prefs.prefHasUserValue(key); this.oils_printer_external_cmd = has_key ? prefs.getCharPref(key) : ''; @@ -83,7 +85,8 @@ util.print.prototype = { var obj = this; - obj.data.last_print = { 'msg' : msg, 'params' : params}; obj.data.stash('last_print'); + obj.data.last_print = { 'msg' : msg, 'params' : params, 'context' : this.context}; + obj.data.stash('last_print'); var silent = false; if ( params && params.no_prompt && (params.no_prompt == true || params.no_prompt == 'true') ) { @@ -102,9 +105,9 @@ util.print.prototype = { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); obj.data.init({'via':'stash'}); - if (params.print_strategy || obj.data.print_strategy) { + if (params.print_strategy || obj.data.print_strategy[obj.context] || obj.data.print_strategy['default']) { - switch(params.print_strategy || obj.data.print_strategy) { + switch(params.print_strategy || obj.data.print_strategy[obj.context] || obj.data.print_strategy['default']) { case 'dos.print': params.dos_print = true; case 'custom.print': @@ -296,10 +299,13 @@ util.print.prototype = { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); obj.data.init({'via':'stash'}); - if (params.print_strategy || obj.data.print_strategy) { + if (params.print_strategy || obj.data.print_strategy[obj.context] || obj.data.print_strategy['default']) { -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) { + dump('params.print_strategy = ' + params.print_strategy + + ' || obj.data.print_strategy[' + obj.context + '] = ' + obj.data.print_strategy[obj.context] + + ' || obj.data.print_strategy[default] = ' + obj.data.print_strategy['default'] + + ' => ' + ( params.print_strategy || obj.data.print_strategy[obj.context] || obj.data.print_strategy['default'] ) + '\n'); + switch(params.print_strategy || obj.data.print_strategy[obj.context] || obj.data.print_strategy['default']) { case 'dos.print': case 'custom.print': if (typeof w != 'string') { @@ -515,23 +521,31 @@ dump('params.print_strategy = ' + params.print_strategy + ' || obj.data.print_st try { var error_msg = ''; netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); - var file = new util.file('gPrintSettings'); + var file = new util.file('gPrintSettings.' + this.context); if (file._file.exists()) { temp = file.get_object(); file.close(); for (var i in temp) { try { this.gPrintSettings[i] = temp[i]; } catch(E) { error_msg += 'Error trying to set gPrintSettings.'+i+'='+temp[i]+' : ' + js2JSON(E) + '\n'; } } - } else { - this.gPrintSettings.marginTop = 0; - this.gPrintSettings.marginLeft = 0; - this.gPrintSettings.marginBottom = 0; - this.gPrintSettings.marginRight = 0; - this.gPrintSettings.headerStrLeft = ''; - this.gPrintSettings.headerStrCenter = ''; - this.gPrintSettings.headerStrRight = ''; - this.gPrintSettings.footerStrLeft = ''; - this.gPrintSettings.footerStrCenter = ''; - this.gPrintSettings.footerStrRight = ''; + } else if (this.context != 'default') { + var file = new util.file('gPrintSettings.default'); + if (file._file.exists()) { + temp = file.get_object(); file.close(); + for (var i in temp) { + try { this.gPrintSettings[i] = temp[i]; } catch(E) { error_msg += 'Error trying to set gPrintSettings.'+i+'='+temp[i]+' : ' + js2JSON(E) + '\n'; } + } + } else { + this.gPrintSettings.marginTop = 0; + this.gPrintSettings.marginLeft = 0; + this.gPrintSettings.marginBottom = 0; + this.gPrintSettings.marginRight = 0; + this.gPrintSettings.headerStrLeft = ''; + this.gPrintSettings.headerStrCenter = ''; + this.gPrintSettings.headerStrRight = ''; + this.gPrintSettings.footerStrLeft = ''; + this.gPrintSettings.footerStrCenter = ''; + this.gPrintSettings.footerStrRight = ''; + } } if (error_msg) { this.error.sdump('D_PRINT',error_msg); @@ -553,7 +567,7 @@ dump('params.print_strategy = ' + params.print_strategy + ' || obj.data.print_st try { var obj = this; netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); - var file = new util.file('gPrintSettings'); + var file = new util.file('gPrintSettings.' + this.context); if (typeof obj.gPrintSettings == 'undefined') obj.GetPrintSettings(); if (obj.gPrintSettings) file.set_object(obj.gPrintSettings); file.close(); diff --git a/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul b/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul index fc4e4f51bf..5099a4c32b 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul +++ b/Open-ILS/xul/staff_client/chrome/content/util/rbrowser.xul @@ -57,6 +57,7 @@ var p = { 'url' : url, 'push_xulG' : push_xulG, + 'printer_context' : xul_param('printer_context'), 'html_source' : xul_param('html_source'), 'debug_label' : 'debug' } diff --git a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties index d6d4acd632..e7d0425066 100644 --- a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties +++ b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties @@ -264,5 +264,5 @@ staff.cat.opac.related_items=Related Lineitems 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. +printing.print_strategy_saved=Print strategy (%1$s) for %2$s context saved to file system. text_editor.prompt_for_external_cmd=Enter external text editor command and parameters (use %letter.txt% as the file containing the text. This value will be substituted with the proper path.): 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 bd7d228739..8f6ac18c46 100644 --- a/Open-ILS/xul/staff_client/server/admin/printer_settings.html +++ b/Open-ILS/xul/staff_client/server/admin/printer_settings.html @@ -27,6 +27,14 @@
+

&staff.printing.context.header;

+

&staff.printing.context.desc;

+
+ &staff.printing.context.radio.default.label; + &staff.printing.context.radio.receipt.label; + &staff.printing.context.radio.label.label; + &staff.printing.context.radio.mail.label; +

&staff.printing.normal_settings.header;


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 45028a262d..eb0b572592 100644 --- a/Open-ILS/xul/staff_client/server/admin/printer_settings.js +++ b/Open-ILS/xul/staff_client/server/admin/printer_settings.js @@ -9,7 +9,7 @@ function my_init() { JSAN.use('util.error'); g.error = new util.error(); g.error.sdump('D_TRACE','my_init() for printer_settings.xul'); - JSAN.use('util.print'); g.print = new util.print(); + g.set_printer_context(); g.prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']); @@ -26,6 +26,11 @@ function my_init() { } } +g.set_printer_context = function(context) { + g.context = context || 'default'; + JSAN.use('util.print'); g.print = new util.print(g.context); +} + g.page_settings = function() { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); g.print.page_settings(); @@ -42,7 +47,7 @@ g.printer_settings = function() { g.set_print_strategy = function(which) { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); if (which == 'custom.print') { - var key = 'oils.printer.external.cmd'; + var key = 'oils.printer.external.cmd.' + g.context; var has_key = g.prefs.prefHasUserValue(key); var value = has_key ? g.prefs.getCharPref(key) : ''; var cmd = window.prompt( @@ -52,13 +57,17 @@ g.set_print_strategy = function(which) { if (!cmd) { return; } g.prefs.setCharPref(key,cmd); } - JSAN.use('util.file'); var file = new util.file('print_strategy'); + JSAN.use('util.file'); var file = new util.file('print_strategy.' + g.context); 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'); + if (!data.print_strategy) { + data.print_strategy = {}; + } + data.print_strategy[g.context] = which; + data.stash('print_strategy'); alert( - document.getElementById('offlineStrings').getFormattedString('printing.print_strategy_saved',[which]) + document.getElementById('offlineStrings').getFormattedString('printing.print_strategy_saved',[which,g.context]) ); } diff --git a/Open-ILS/xul/staff_client/server/circ/checkin.js b/Open-ILS/xul/staff_client/server/circ/checkin.js index 80441ec79a..72d11632df 100644 --- a/Open-ILS/xul/staff_client/server/circ/checkin.js +++ b/Open-ILS/xul/staff_client/server/circ/checkin.js @@ -314,6 +314,7 @@ circ.checkin.prototype = { ['command'], function() { var p = { + 'printer_context' : 'receipt', 'template' : 'checkin' }; obj.list.print(p); diff --git a/Open-ILS/xul/staff_client/server/circ/checkout.js b/Open-ILS/xul/staff_client/server/circ/checkout.js index d2706eff9a..88412fd969 100644 --- a/Open-ILS/xul/staff_client/server/circ/checkout.js +++ b/Open-ILS/xul/staff_client/server/circ/checkout.js @@ -307,6 +307,7 @@ circ.checkout.prototype = { 'data' : { 'balance_owed' : util.money.sanitize( obj.most_recent_balance_owed ), }, + 'printer_context' : 'receipt', 'template' : 'checkout', 'callback' : function() { setTimeout( diff --git a/Open-ILS/xul/staff_client/server/patron/bill2.js b/Open-ILS/xul/staff_client/server/patron/bill2.js index 1206275a1d..059267b501 100644 --- a/Open-ILS/xul/staff_client/server/patron/bill2.js +++ b/Open-ILS/xul/staff_client/server/patron/bill2.js @@ -649,6 +649,7 @@ function print_bills() { JSAN.use('patron.util'); var params = { 'patron' : patron.util.retrieve_au_via_id(ses(),g.patron_id), + 'printer_context' : 'receipt', 'template' : template }; g.bill_list.print(params); @@ -782,7 +783,7 @@ function apply_payment() { }; g.error.sdump('D_DEBUG',js2JSON(params)); if (! $('printer_prompt').hasAttribute('checked')) params.no_prompt = true; - JSAN.use('util.print'); var print = new util.print(); + JSAN.use('util.print'); var print = new util.print('receipt'); print.tree_list( params ); } catch(E) { g.error.standard_unexpected_error_alert('bill receipt', E); diff --git a/Open-ILS/xul/staff_client/server/patron/bills.js b/Open-ILS/xul/staff_client/server/patron/bills.js index 7f72ea0abf..82c3b8b607 100644 --- a/Open-ILS/xul/staff_client/server/patron/bills.js +++ b/Open-ILS/xul/staff_client/server/patron/bills.js @@ -540,7 +540,7 @@ patron.bills.prototype = { }; obj.error.sdump('D_DEBUG',js2JSON(params)); if (document.getElementById('auto_print').checked) params.no_prompt = true; - JSAN.use('util.print'); var print = new util.print(); + JSAN.use('util.print'); var print = new util.print('receipt'); print.tree_list( params ); } catch(E) { obj.error.standard_unexpected_error_alert('bill receipt', E); @@ -707,7 +707,7 @@ patron.bills.prototype = { } ) }; - JSAN.use('util.print'); var print = new util.print(); + JSAN.use('util.print'); var print = new util.print('receipt'); print.tree_list( params ); } catch(E) { diff --git a/Open-ILS/xul/staff_client/server/patron/items.js b/Open-ILS/xul/staff_client/server/patron/items.js index d9a804e49c..462318ac06 100644 --- a/Open-ILS/xul/staff_client/server/patron/items.js +++ b/Open-ILS/xul/staff_client/server/patron/items.js @@ -251,6 +251,7 @@ patron.items.prototype = { JSAN.use('patron.util'); var params = { 'patron' : patron.util.retrieve_fleshed_au_via_id(ses(),obj.patron_id), + 'printer_context' : 'receipt', 'template' : 'items_out' }; list.print( params ); diff --git a/Open-ILS/xul/staff_client/server/patron/summary.xul b/Open-ILS/xul/staff_client/server/patron/summary.xul index 290d57edc4..df1671febb 100644 --- a/Open-ILS/xul/staff_client/server/patron/summary.xul +++ b/Open-ILS/xul/staff_client/server/patron/summary.xul @@ -110,7 +110,7 @@ case 'addr_export_print': // Replace literal instances of '\n' and excessive whitespace. s = s.replace(/(\\n)+/g, "
").replace(/ {2,}/g, " "); - JSAN.use('util.print'); var print = new util.print(); print.simple(s); + JSAN.use('util.print'); var print = new util.print('mail'); print.simple(s); break; }; }