protect templated slots from errors when there are no template variables
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 23 Jun 2010 18:03:42 +0000 (18:03 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 23 Jun 2010 18:03:42 +0000 (18:03 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@16790 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/BibTemplate.js

index 1b0f833..fdc3577 100644 (file)
@@ -133,6 +133,7 @@ if(!dojo._hasResource["openils.BibTemplate"]) {
                                     if (templated) {
                                         if (debug) alert('BibTemplate debug -- slot template innerHTML:\n' + slot.innerHTML);
                                         var template_values = {};
+                                        var template_value_count = 0;
 
                                         dojo.query(
                                             '*[type=opac/template-value]',
@@ -140,11 +141,14 @@ if(!dojo._hasResource["openils.BibTemplate"]) {
                                         ).orphan().forEach(function(x) {
                                             var name = x.getAttribute('name');
                                             var value = (new Function( 'item_list', 'BT', 'slotXML', 'slot', unescape(x.innerHTML) ))(item_list,BT,bib,slot);
-                                            if (name && (value || value == '')) template_values[name] = value;
+                                            if (name && (value || value == '')) {
+                                                template_values[name] = value;
+                                                template_value_count++;
+                                            }
                                         });
 
                                         if (debug) alert('BibTemplate debug -- template values:\n' + dojo.toJson( template_values ));
-                                        slot.innerHTML = dojo.string.substitute( unescape(slot.innerHTML), template_values );
+                                        if (template_value_count > 0) slot.innerHTML = dojo.string.substitute( unescape(slot.innerHTML), template_values );
                                     }
 
                                     var handler_node = dojo.query( '*[type=opac/slot-format]', slot )[0];