Receipt Macros: %INCLUDE()%
authorThomas Berezansky <tsbere@mvlc.org>
Mon, 22 Aug 2011 00:00:55 +0000 (20:00 -0400)
committerJason Etheridge <jason@esilibrary.com>
Fri, 26 Aug 2011 19:57:36 +0000 (15:57 -0400)
Takes a single parameter: The name of the include.

Each include is an OU setting: circ.staff_client.receipt.<name>

The includes are done as the first substitution. This has the benefit
of allowing other substitutions within them (including additional calls
to %INCLUDE()%) and the downside of not allowing dynamic includes.

Because an include can contain includes the code keeps track of all
includes already done, skipping those already included. This prevents
infinite loops when A includes B and B includes A, or longer variants
thereof.

Primary intended use would be for libraries to place frequently changed
notices and such in their templates. Instead of having to edit every
template on every workstation they use the %INCLUDE()% macro and edit
the org unit settings. At the next login the updated text appears on
every workstation.

Due to the includes being processed first a library could use them to
centrally administer templates by using an include for each piece of
each template.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/xul/staff_client/chrome/content/util/print.js

index 45f531f..d520776 100644 (file)
@@ -280,6 +280,23 @@ util.print.prototype = {
             JSAN.use('util.date');
             var s = msg; var b;
 
+            // Includes
+            // Note that we keep track of already included settings
+            // This ensures that we don't infinite loop through includes
+            try {
+                var match;
+                var include_patt=/%INCLUDE\(\s*([^)]*?)\s*\)%/;
+                var included = {};
+                while(match = include_patt.exec(s)) {
+                    if(match[1] == '' || included[match[1]]) {
+                        s = s.replace(match[0], '');
+                    } else {
+                        included[match[1]] = true;
+                        s = s.replace(new RegExp("%INCLUDE\\(\\s*" + match[1].replace(/([.?*+^$[\]\\(){}-])/g, "\\$1") + "\\s*\\)%","g"), obj.data.hash.aous['circ.staff_client.receipt.' + match[1]] || '');
+                    }
+                }
+            } catch(E) { dump(E+'\n'); }
+
             try{b = s; s = s.replace(/%LINE_NO%/g,Number(params.row_idx)+1);}
                 catch(E){s = b; this.error.sdump('D_WARN','string = <' + s + '> error = ' + js2JSON(E)+'\n');}
 
@@ -369,7 +386,7 @@ util.print.prototype = {
             // Date Format
             try {
                 var match;
-                var date_format_patt=/%DATE_FORMAT\(\s*([^,]*?)\s*,\s*([^)]*?)\s*\)%/
+                var date_format_patt=/%DATE_FORMAT\(\s*([^,]*?)\s*,\s*([^)]*?)\s*\)%/;
                 while(match = date_format_patt.exec(s)) {
                     if(match[1] == '' || match[2] == '')
                         s = s.replace(match[0], '');