inlining json into the print window's data url, to give the templates data that inlin...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 16 Jun 2006 20:35:46 +0000 (20:35 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 16 Jun 2006 20:35:46 +0000 (20:35 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4658 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/util/print.js

index afcd861..9a6025b 100644 (file)
@@ -53,7 +53,8 @@ util.print.prototype = {
                        var w;
                        switch(content_type) {
                                case 'text/html' :
-                                       w = obj.win.open('data:text/html,<html>' + window.escape(msg) + '</html>','receipt_temp','chrome,resizable');
+                                       var jsrc = 'data:text/javascript,' + window.escape('var params = { "data" : ' + js2JSON(params.data) + ', "list" : ' + js2JSON(params.list) + '};');
+                                       w = obj.win.open('data:text/html,<html><head><script src="' + window.escape(jsrc) + '"></script></head><body>' + window.escape(msg) + '</body></html>','receipt_temp','chrome,resizable');
                                break;
                                default:
                                        w = obj.win.open('data:' + content_type + ',' + window.escape(msg),'receipt_temp','chrome,resizable');
@@ -144,6 +145,9 @@ util.print.prototype = {
                                        }
                                );
                        break;
+                       case 'payment':
+                               cols = [ '%bill_id%','%payment%'];
+                       break;
                        case 'holds':
                                JSAN.use('circ.util');
                                cols = util.functional.map_list(
@@ -172,7 +176,8 @@ util.print.prototype = {
                s += this.template_sub( params.footer, cols, params );
 
                if (params.sample_frame) {
-                       params.sample_frame.setAttribute('src','data:text/html,<html>' + window.escape(s) + '</html>');
+                       var jsrc = 'data:text/javascript,' + window.escape('var params = { "data" : ' + js2JSON(params.data) + ', "list" : ' + js2JSON(params.list) + '};');
+                       params.sample_frame.setAttribute('src','data:text/html,<html><head><script src="' + window.escape(jsrc) + '"></script></head><body>' + window.escape(s) + '</body></html>');
                } else {
                        this.simple(s,params);
                }
@@ -225,7 +230,7 @@ util.print.prototype = {
                        catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
 
                try {
-                       if (params.row) {
+                       if (typeof params.row != 'undefined') {
                                if (params.row.length >= 0) {
                                        for (var i = 0; i < cols.length; i++) {
                                                var re = new RegExp(cols[i],"g");
@@ -241,6 +246,14 @@ util.print.prototype = {
                                        }
                                }
                        }
+
+                       if (typeof params.data != 'undefined') {
+                               for (var i in params.data) {
+                                       var re = new RegExp('%'+i+'%',"g");
+                                       try{b = s; s=s.replace(re, params.data[i]);}
+                                               catch(E){s = b; this.error.standard_unexpected_error_alert('string = <' + s + '> error = ' + js2JSON(E)+'\n',E);}
+                               }
+                       }
                } catch(E) { dump(E+'\n'); }
 
                return s;