9fd07c5f85a76b6d8f934495954c2762193e64ab
[working/Evergreen.git] / Open-ILS / src / templates / opac / parts / record / subjects.tt2
1 [% 
2     subjects = [
3         {
4             label => l('Subject: '),
5             xpath => '//*[@tag="600" or @tag="610" or @tag="611" or @tag="630" or @tag="650" or @tag="651"]'
6         }, {
7             label => l('Genre: '),
8             facet => 'identifier|genre',
9             joiner => ' -- ',
10             xpath => '//*[@tag="655"]',
11             subfields => '[abvxyz]'
12         }, {
13             label => l('Topic Heading: '),
14             xpath => '//*[@tag="690"]'
15         }, {
16             label => l('Geographic Setting: '),
17             xpath => '//*[@tag="691"]'
18         }, {
19             label => l('Biographical Subject: '),
20             xpath => '//*[@tag="692"]'
21         }, {
22             label => l('Character Attributes: '),
23             xpath => '//*[@tag="693"]'
24         }, {
25             label => l('Setting: '),
26             xpath => '//*[@tag="698"]'
27         }, {
28             label => l('Time Period: '),
29             xpath => '//*[@tag="699"]'
30         }
31     ];
32
33     BLOCK render_subject;
34         xpath = s.xpath || '//*[starts-with(@tag,"6")]';
35         FOR node IN ctx.marc_xml.findnodes(xpath);
36             '<span property="about">';
37             all_terms = [];
38             graphics = [];
39             FOR subfield IN node.childNodes;
40                 NEXT UNLESS subfield.nodeName == "subfield";
41                 code = subfield.getAttribute('code');
42                 IF code == '6';
43                    linked_fields = [subfield.textContent()];
44                    target_field = node.getAttribute('tag');
45                    get_linked_880s;
46                 END;
47
48                 NEXT UNLESS code.match('[a-z]');
49                 IF s.subfields; NEXT UNLESS code.match(s.subfields); END;
50
51                 IF code.match('[vxyz]'); " &gt; "; END;
52
53                 # at this point, we actually have a partial term to use.
54                 raw_term = subfield.textContent;
55                 single_term = raw_term | html;
56
57                 # facets should be used as-is
58                 IF !s.facet; raw_term = raw_term.replace('\-', ' ').replace('[#"^$\+,\.:;&|\[\]()]', ''); END;
59
60                 all_terms.push(raw_term);
61
62                 IF s.facet;
63                     total_term = s.facet _ '[' _ all_terms.join(s.joiner).replace('\s+$', '') _ ']';
64                 ELSE;
65                     total_term = all_terms.join(" ").replace('\s+$', '');
66                 END;
67
68                 %]<a href="[%-
69                        mkurl(ctx.opac_root _ '/results', {qtype=>'subject', query=>total_term}, stop_parms.merge(expert_search_parms, general_search_parms, browse_search_parms, facet_search_parms))
70                 -%]" rel="nofollow" vocab="">[% single_term %]</a> [%-
71
72             END;
73             IF all_terms.size; "<br/>"; END;
74             FOREACH link880 IN graphics;
75                 '<div class="graphic880"' _ link880.dir _ '>';
76                 link880.value | html;
77                 '</div>';
78             END;
79             '</span>';
80         END;
81     END 
82 %]
83
84 [%  BLOCK render_all_subjects;
85     FOREACH subj IN subjects;
86         content = PROCESS render_subject(s=subj);
87         IF content.match('\S');
88 %]
89         <table class='rdetail_subject'>
90             <tbody>
91                 <tr>
92                     <td class='rdetail_subject_type'>[% subj.label %]</td>
93                     <td class='rdetail_subject_value'>[% content %]</td>
94                 </tr>
95             </tbody>
96         </table>
97         [%- END; %]
98     [%- END; %]
99 [%- END %]
100
101 [%-  subject_html = PROCESS render_all_subjects;
102     IF subject_html.length > 0;
103 %]
104 <h2 class='rdetail_related_subjects'>[% l('Search for related items by subject') %]</h2>
105 [%- subject_html %]
106 [%- END %]