From: Bill Erickson Date: Wed, 14 Nov 2018 19:57:16 +0000 (-0500) Subject: JBAS-2101 Re-print lost/paid dialog repairs X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=720367af04a3560a5c420fed9ec3b9ac7dd8a1cf;p=working%2FEvergreen.git JBAS-2101 Re-print lost/paid dialog repairs Improve handling of setting and clearing the silent-print mode when printing lost/paid receipts. Add a slight delay to the re-enable-silent step to allow the print call to complete before re-applying the value. Unclear if this is strictly necessary, but combined with the above may help. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/xul/staff_client/server/patron/bill2.js b/Open-ILS/xul/staff_client/server/patron/bill2.js index fe8b696c5a..685868d318 100644 --- a/Open-ILS/xul/staff_client/server/patron/bill2.js +++ b/Open-ILS/xul/staff_client/server/patron/bill2.js @@ -909,10 +909,39 @@ function handle_printthis() { g.bill_list.print(params); } +// Temporarily override the forced silent print option for lost & +// paid receipts where we /always/ want to show the print dialog. +// Returns true if silent printing is enabled. +function disable_silent_print() { + var prefs = Components.classes['@mozilla.org/preferences-service;1'] + .getService(Components.interfaces['nsIPrefBranch']); + + var silentPrintApplied = ( + prefs.prefHasUserValue('print.always_print_silent') + && prefs.getBoolPref('print.always_print_silent') + ); + + if (silentPrintApplied) { + // Note setting the value to 'false' does not work. + prefs.clearUserPref('print.always_print_silent'); + } + + return silentPrintApplied; +} + +function enable_silent_print() { + var prefs = Components.classes['@mozilla.org/preferences-service;1'] + .getService(Components.interfaces['nsIPrefBranch']); + + prefs.setBoolPref('print.always_print_silent', true); +} + function handle_printlostpaid() { var selected = g.bill_list.dump_selected_with_keys(0); var xact_ids = selected.map(function(sel) { return sel.mbts_id }); + var silentPrintApplied = disable_silent_print(); + for (var i = 0; i < xact_ids.length; i++) { xact_id = xact_ids[i]; @@ -937,33 +966,17 @@ function handle_printlostpaid() { JSAN.use('util.print'); var print = new util.print('default'); - // Temporarily override the forced silent print option for lost & - // paid receipts where we /always/ want to show the print dialog. - var prefs = Components.classes['@mozilla.org/preferences-service;1'] - .getService(Components.interfaces['nsIPrefBranch']); - - var silentPrintApplied = ( - prefs.prefHasUserValue('print.always_print_silent') - && prefs.getBoolPref('print.always_print_silent') - ); - - if (silentPrintApplied) { - // Note setting the value to 'false' does not work. - prefs.clearUserPref('print.always_print_silent'); - } print.simple(html , { no_prompt: false, content_type: 'text/html' }); + } - if (silentPrintApplied) { - // Re-apply the silent print preference after the - // current thread is done. - setTimeout(function() { - prefs.setBoolPref('print.always_print_silent', true); - }); - } + if (silentPrintApplied) { + // Re-apply the silent print preference after the + // current thread is done. + setTimeout(enable_silent_print, 200); } } @@ -1328,6 +1341,9 @@ function pay(payment_blob) { } function print_refundable_payments_receipt(mrp_ids) { + + var silentPrintApplied = disable_silent_print(); + for (var i = 0; i < mrp_ids.length; i++) { mrp_id = mrp_ids[0]; var receipt = g.network.request( @@ -1345,36 +1361,21 @@ function print_refundable_payments_receipt(mrp_ids) { JSAN.use('util.print'); var print = new util.print('default'); - // Temporarily override the forced silent print option for lost & - // paid receipts where we /always/ want to show the print dialog. - var prefs = Components.classes['@mozilla.org/preferences-service;1'] - .getService(Components.interfaces['nsIPrefBranch']); - - var silentPrintApplied = ( - prefs.prefHasUserValue('print.always_print_silent') - && prefs.getBoolPref('print.always_print_silent') - ); - - if (silentPrintApplied) { - // Note setting the value to 'false' does not work. - prefs.clearUserPref('print.always_print_silent'); - } print.simple(html , { no_prompt: false, // always prompt for lost payment receipts content_type: 'text/html' }); + } - if (silentPrintApplied) { - // Re-apply the silent print preference after the - // current thread is done. - setTimeout(function() { - prefs.setBoolPref('print.always_print_silent', true); - }); - } + if (silentPrintApplied) { + // Re-apply the silent print preference after the + // current thread is done. + setTimeout(enable_silent_print, 200); } } + function refresh(params) { try { if (g.safe_for_refresh) { diff --git a/Open-ILS/xul/staff_client/server/patron/bill_history.js b/Open-ILS/xul/staff_client/server/patron/bill_history.js index 3bd942190d..ae1eb7397d 100644 --- a/Open-ILS/xul/staff_client/server/patron/bill_history.js +++ b/Open-ILS/xul/staff_client/server/patron/bill_history.js @@ -416,6 +416,21 @@ function print_lostpaid_from_history() { var selected = g.payments_list.dump_selected_with_keys(0); var pay_ids = selected.map(function(sel) { return sel.mp_id }); + // Temporarily override the forced silent print option for lost & + // paid receipts where we /always/ want to show the print dialog. + var prefs = Components.classes['@mozilla.org/preferences-service;1'] + .getService(Components.interfaces['nsIPrefBranch']); + + var silentPrintApplied = ( + prefs.prefHasUserValue('print.always_print_silent') + && prefs.getBoolPref('print.always_print_silent') + ); + + if (silentPrintApplied) { + // Note setting the value to 'false' does not work. + prefs.clearUserPref('print.always_print_silent'); + } + for (var i = 0; i < pay_ids.length; i++) { pay_id = pay_ids[i]; @@ -440,33 +455,19 @@ function print_lostpaid_from_history() { JSAN.use('util.print'); var print = new util.print('default'); - // Temporarily override the forced silent print option for lost & - // paid receipts where we /always/ want to show the print dialog. - var prefs = Components.classes['@mozilla.org/preferences-service;1'] - .getService(Components.interfaces['nsIPrefBranch']); - - var silentPrintApplied = ( - prefs.prefHasUserValue('print.always_print_silent') - && prefs.getBoolPref('print.always_print_silent') - ); - - if (silentPrintApplied) { - // Note setting the value to 'false' does not work. - prefs.clearUserPref('print.always_print_silent'); - } print.simple(html , { no_prompt: false, // always prompt for lost payment receipts content_type: 'text/html' }); + } - if (silentPrintApplied) { - // Re-apply the silent print preference after the - // current thread is done. - setTimeout(function() { - prefs.setBoolPref('print.always_print_silent', true); - }); - } + if (silentPrintApplied) { + // Re-apply the silent print preference after the + // current thread is done. + setTimeout(function() { + prefs.setBoolPref('print.always_print_silent', true); + }, 200); } }