From a1681de689a55638154662e0e9158468456e2543 Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Sun, 21 Aug 2011 20:00:55 -0400 Subject: [PATCH] Receipt Macros: %INCLUDE()% Takes a single parameter: The name of the include. Each include is an OU setting: circ.staff_client.receipt. 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 Signed-off-by: Jason Etheridge --- .../staff_client/chrome/content/util/print.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 45f531f92f..d520776149 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/print.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/print.js @@ -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], ''); -- 2.43.2