show No Subjects when, well, there are no subjects; cleanup
authorberick <berick@esilibrary.com>
Wed, 20 Apr 2011 21:50:29 +0000 (17:50 -0400)
committerberick <berick@esilibrary.com>
Wed, 20 Apr 2011 21:50:29 +0000 (17:50 -0400)
Open-ILS/web/templates/default/opac/parts/record/subjects.tt2

index 64cc3c4..98c8b1a 100644 (file)
@@ -1,77 +1,67 @@
-<div id='rdetail_subject_div'>
-    <table cellpadding="0" cellspacing="0" border="0">
-        <tr>
-            <td width="1" style="padding-right:7px;" valign="top">
-                <strong>[% l('Subject:') %] </strong>
-            </td>
-            <td>
-                [% BLOCK render_subject;
-                loc = CGI.param('loc') | uri;
-                xpath = xpath || '//*[starts-with(@tag,"6")]';
-                FOR node IN ctx.marc_xml.findnodes(xpath);
-                    all_terms = [];
-                    FOR subfield IN node.childNodes;
-                        NEXT UNLESS subfield.nodeName == "subfield";
-                        code = 0;
-                        FOR a IN subfield.attributes;
-                            IF a.nodeName == "code";
-                                code = a.nodeValue;
-                            END;
-                        END;
-                        NEXT UNLESS code.match('[a-z]');
-
-                        IF code.match('[vxyz]');
-                            " &mdash; ";
-                        END;
-                        # at this point, we actually have a partial term to use.
-                        single_term = subfield.textContent | html;
-                        all_terms.push(subfield.textContent);
-                        total_term = all_terms.join(" ").replace('\s+$', '') ; # XXX need to take care of any &'s, right?
-                        '<a href="' _ ctx.opac_root _ '/results?qtype=subject&query=' _ total_term _ '&loc=' _ loc _ '">' _ single_term _ '</a>';
-                    END;
-                    "<br />";
-                END %]
-                [% END %]
-                [% s = PROCESS render_subject; IF s.match('\S'); s; END; %]
-            </td>
-        </tr>
+[% 
+    subjects = [
+        {
+            label => l('Genre: '),
+            xpath => '//*[@tag="655"]|//*[@tag="659"]'
+        }, {
+            label => l('Topic Heading: '),
+            xpath => '//*[@tag="690"]'
+        }, {
+            label => l('Geographic Setting: '),
+            xpath => '//*[@tag="691"]'
+        }, {
+            label => l('Biographical Subject: '),
+            xpath => '//*[@tag="692"]'
+        }, {
+            label => l('Character Attributes: '),
+            xpath => '//*[@tag="693"]'
+        }, {
+            label => l('Setting: '),
+            xpath => '//*[@tag="698"]'
+        }, {
+            label => l('Time Period: '),
+            xpath => '//*[@tag="699"]'
+        }
+    ];
 
-        [%
-            subjects = [
-                {
-                    label => l('Genre: '),
-                    xpath => '//*[@tag="655"]|//*[@tag="659"]'
-                }, {
-                    label => l('Topic Heading: '),
-                    xpath => '//*[@tag="690"]'
-                }, {
-                    label => l('Geographic Setting: '),
-                    xpath => '//*[@tag="691"]'
-                }, {
-                    label => l('Biographical Subject: '),
-                    xpath => '//*[@tag="692"]'
-                }, {
-                    label => l('Character Attributes: '),
-                    xpath => '//*[@tag="693"]'
-                }, {
-                    label => l('Setting: '),
-                    xpath => '//*[@tag="698"]'
-                }, {
-                    label => l('Time Period: '),
-                    xpath => '//*[@tag="699"]'
-                }
-            ];
+    BLOCK render_subject;
+        loc = CGI.param('loc') | uri;
+        xpath = xpath || '//*[starts-with(@tag,"6")]';
+        FOR node IN ctx.marc_xml.findnodes(xpath);
+            all_terms = [];
+            FOR subfield IN node.childNodes;
+                NEXT UNLESS subfield.nodeName == "subfield";
+                code = subfield.getAttribute('code');
+                NEXT UNLESS code.match('[a-z]');
+                IF code.match('[vxyz]'); " &mdash; "; END;
+                # at this point, we actually have a partial term to use.
+                single_term = subfield.textContent | html;
+                all_terms.push(subfield.textContent);
+                total_term = all_terms.join(" ").replace('\s+$', '') | uri;
+                '<a href="' _ ctx.opac_root _ '/results?qtype=subject&query=' _ total_term _ '&loc=' _ loc _ '">' _ single_term _ '</a>';
+            END;
+            IF all_terms.size; "<br/>"; END;
+        END;
+    END 
+%]
 
-            FOREACH subj IN subjects;
-                '<!-- SUBJECT = ' _ subj.label _ ' : xpath = ' _ subj.xpath _ ' -->';
-                content = PROCESS render_subject(xpath=subj.xpath);
-                IF content.match('\S') %]
-                <tr>
-                    <td width="1" style="padding:5px 7px 0px 0px;" valign="top">
-                        <strong>[% subj.label %]</strong>
-                    </td>
-                    <td style="padding-top:5px;"><div>[% content %] </div></td>
-                </tr>
-        [% END; END; %]
+<div id='rdetail_subject_div'>
+    <table cellpadding="0" cellspacing="0" border="0">
+    [%  any_subjects = 0;
+        FOREACH subj IN subjects;
+            content = PROCESS render_subject(xpath=subj.xpath);
+            IF content.match('\S');
+                any_subjects = 1; %]
+            <tr>
+                <td width="1" style="padding:5px 7px 0px 0px;" valign="top">
+                    <strong>[% subj.label %]</strong>
+                </td>
+                <td style="padding-top:5px;"><div>[% content %] </div></td>
+            </tr>
+            [% END; %]
+        [% END; %]
+    [% IF any_subjects == 0 %]
+        <tr><td><i>No Subjects</i></td></tr>
+    [% END; %]
     </table>
 </div>