infrastructure for context sensitive print setting
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 30 Aug 2010 15:36:16 +0000 (15:36 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 30 Aug 2010 15:36:16 +0000 (15:36 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@17375 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/locale/en-US/lang.dtd
Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js
Open-ILS/xul/staff_client/chrome/content/util/browser.js
Open-ILS/xul/staff_client/chrome/content/util/print.js
Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties
Open-ILS/xul/staff_client/server/admin/printer_settings.html
Open-ILS/xul/staff_client/server/admin/printer_settings.js

index ac37e14..9c48de5 100644 (file)
 <!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.context.header "Printer Context">
+<!ENTITY staff.printing.context.desc "Different printer settings may be configured for different contexts within the staff client (such as circulation, label printing, etc.).  If settings have not been made for a given context, the staff client will fall back on the 'default' context.">
+<!ENTITY staff.printing.context.radio.default.label "Default">
+<!ENTITY staff.printing.context.radio.receipt.label "Receipt">
+<!ENTITY staff.printing.context.radio.label.label "Label">
+<!ENTITY staff.printing.context.radio.mail.label "Mail">
 <!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)">
index 40f2d9a..ad74593 100644 (file)
@@ -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. ');
index 16d6253..de33afa 100644 (file)
@@ -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(
@@ -60,7 +61,13 @@ 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) {
+                                    if (
+                                        !data.print_strategy
+                                        || !data.print_strategy[obj.printer_context]
+                                        || (data.print_strategy[obj.printer_context] && data.print_strategy[obj.printer_context] == 'webBrowserPrint')
+                                        || !data.print_strategy['default']
+                                        || (data.print_strategy['default'] && data.print_strategy['default'] == 'webBrowserPrint')
+                                    ) {
                                         // Override the print strategy temporarily in this context
                                         print_params.print_strategy = 'window.print';
                                     }
index 8265d3a..b297043 100644 (file)
@@ -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();
index d6d4acd..e7d0425 100644 (file)
@@ -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.):
index bd7d228..8f6ac18 100644 (file)
     <script type="text/javascript" src="printer_settings.js"></script>
 </head><body onload="try { my_init(); } catch(E) { alert(E); }" style="background: white;">
     <div class="messagecatalog" id="offlineStrings" src="/xul/server/locale/<!--#echo var='locale'-->/offline.properties" />
+    <h1>&staff.printing.context.header;</h1>
+    <p>&staff.printing.context.desc;</p>
+    <form>
+        <input type="radio" name="context" value="default" checked="checked" onclick="g.set_printer_context('default');">&staff.printing.context.radio.default.label;</input>
+        <input type="radio" name="context" value="receipt" onclick="g.set_printer_context('receipt');">&staff.printing.context.radio.receipt.label;</input>
+        <input type="radio" name="context" value="label" onclick="g.set_printer_context('label');">&staff.printing.context.radio.label.label;</input>
+        <input type="radio" name="context" value="mail" onclick="g.set_printer_context('mail');">&staff.printing.context.radio.mail.label;</input>
+    </form> 
     <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); }">&staff.printing.set_default;</button>
index 45028a2..eb0b572 100644 (file)
@@ -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])
     );
 }