From: phasefx Date: Sun, 19 Sep 2010 03:50:28 +0000 (+0000) Subject: Make sure offline interfaces correctly load printer settings outside of logins. ... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=23407a88d6d93520811bd282f65cf3130b35e4e0;p=evergreen%2Fmasslnc.git Make sure offline interfaces correctly load printer settings outside of logins. Some refactoring git-svn-id: svn://svn.open-ils.org/ILS/trunk@17815 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- 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 803e1077fe..d318ddb55d 100644 --- a/Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js +++ b/Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js @@ -244,6 +244,56 @@ OpenILS.data.prototype = { } }, + 'load_saved_print_templates' : function() { + var obj = this; + try { + JSAN.use('util.file'); var file = new util.file('print_list_templates'); + if (file._file.exists()) { + try { + var x = file.get_object(); + if (x) { + for (var i in x) { + obj.print_list_templates[i] = x[i]; + } + obj.stash('print_list_templates'); + obj.data_progress('Saved print templates retrieved from file. '); + } + } catch(E) { + alert(E); + } + } + file.close(); + } catch(E) { + alert("Error in OpenILS.data, load_saved_print_templates(): " + E); + } + }, + + 'fetch_print_strategy' : function() { + var obj = this; + try { + 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); + } + } + file.close(); + } + obj.stash('print_strategy'); + } catch(E) { + alert('Error in OpenILS.data, fetch_print_strategy(): ' + E); + } + }, + 'print_list_defaults' : function() { var obj = this; //if (typeof obj.print_list_templates == 'undefined') { @@ -384,26 +434,6 @@ OpenILS.data.prototype = { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var obj = this; - - JSAN.use('util.file'); var file = new util.file('print_list_templates'); - obj.print_list_defaults(); - obj.data_progress('Default print templates set. '); - if (file._file.exists()) { - try { - var x = file.get_object(); - if (x) { - for (var i in x) { - obj.print_list_templates[i] = x[i]; - } - obj.stash('print_list_templates'); - obj.data_progress('Saved print templates retrieved from file. '); - } - } catch(E) { - alert(E); - } - } - file.close(); - JSAN.use('util.file'); var file = new util.file('global_font_adjust'); if (file._file.exists()) { try { @@ -434,25 +464,10 @@ OpenILS.data.prototype = { } file.close(); - 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); - } - } - file.close(); - } - obj.stash('print_strategy'); - + obj.print_list_defaults(); + obj.data_progress('Default print templates set. '); + obj.load_saved_print_templates(); + obj.fetch_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/circ/offline.js b/Open-ILS/xul/staff_client/chrome/content/circ/offline.js index e34e7930f8..5fdf26e37e 100644 --- a/Open-ILS/xul/staff_client/chrome/content/circ/offline.js +++ b/Open-ILS/xul/staff_client/chrome/content/circ/offline.js @@ -74,55 +74,11 @@ circ.offline.prototype = { }, 'receipt_init' : function() { - function backup_receipt_templates() { - data.print_list_templates = { - 'offline_checkout' : { - 'type' : 'offline_checkout', - 'header' : 'Patron %patron_barcode%
\r\nYou checked out the following items:
    ', - 'line_item' : '
  1. Barcode: %barcode%
    \r\nDue: %due_date%\r\n', - 'footer' : '

%TODAY_TRIM%
\r\n
\r\n', - }, - 'offline_checkin' : { - 'type' : 'offline_checkin', - 'header' : 'You checked in the following items:
    ', - 'line_item' : '
  1. Barcode: %barcode%\r\n', - 'footer' : '

%TODAY_TRIM%
\r\n
\r\n', - }, - 'offline_renew' : { - 'type' : 'offline_renew', - 'header' : 'You renewed the following items:
    ', - 'line_item' : '
  1. Barcode: %barcode%\r\n', - 'footer' : '

%TODAY_TRIM%
\r\n
\r\n', - }, - 'offline_inhouse_use' : { - 'type' : 'offline_inhouse_use', - 'header' : 'You marked the following in-house items used:
    ', - 'line_item' : '
  1. Barcode: %barcode%\r\nUses: %count%', - 'footer' : '

%TODAY_TRIM%
\r\n
\r\n', - }, - }; - data.stash('print_list_templates'); - } - JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); - JSAN.use('util.file'); var file = new util.file('print_list_templates'); - if (file._file.exists()) { - try { - var x = file.get_object(); - if (x) { - data.print_list_templates = x; - data.stash('print_list_templates'); - } else { - backup_receipt_templates(); - } - } catch(E) { - alert(E); - backup_receipt_templates(); - } - } else { - backup_receipt_templates(); - } - file.close(); + data.print_list_defaults(); + data.load_saved_print_templates(); + data.fetch_print_strategy(); + JSAN.use('util.print'); (new util.print()).GetPrintSettings(); }, 'patron_init' : function() { 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 b2970433aa..87e161852e 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/print.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/print.js @@ -105,6 +105,11 @@ util.print.prototype = { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); obj.data.init({'via':'stash'}); + if (typeof obj.data.print_strategy == 'undefined') { + obj.data.print_strategy = {}; + obj.data.stash('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[obj.context] || obj.data.print_strategy['default']) {