]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/templates/opac/parts/record/subjects.tt2
LP#1752434: Use display fields even when not highlighting
[Evergreen.git] / Open-ILS / src / templates / opac / parts / record / subjects.tt2
1 [% 
2     subjects = [
3         {
4             display_field => 'subject',
5             label => l('Subject: '),
6             xpath => '//*[@tag="600" or @tag="610" or @tag="611" or @tag="630" or @tag="650" or @tag="651"]'
7         }, {
8             display_field => 'genre',
9             label => l('Genre: '),
10             facet => 'identifier|genre',
11             joiner => ' -- ',
12             xpath => '//*[@tag="655"]',
13             subfields => '[abvxyz]'
14         }, {
15             label => l('Topic Heading: '),
16             xpath => '//*[@tag="690"]'
17         }, {
18             label => l('Geographic Setting: '),
19             xpath => '//*[@tag="691"]'
20         }, {
21             label => l('Biographical Subject: '),
22             xpath => '//*[@tag="692"]'
23         }, {
24             label => l('Character Attributes: '),
25             xpath => '//*[@tag="693"]'
26         }, {
27             label => l('Setting: '),
28             xpath => '//*[@tag="698"]'
29         }, {
30             label => l('Time Period: '),
31             xpath => '//*[@tag="699"]'
32         }
33     ];
34
35     BLOCK render_subject;
36         xpath = s.xpath || '//*[starts-with(@tag,"6")]';
37         FOR node IN ctx.marc_xml.findnodes(xpath);
38             '<span property="about">';
39             all_terms = [];
40             graphics = [];
41             FOR subfield IN node.childNodes;
42                 NEXT UNLESS subfield.nodeName == "subfield";
43                 code = subfield.getAttribute('code');
44                 IF code == '6';
45                    linked_fields = [subfield.textContent()];
46                    target_field = node.getAttribute('tag');
47                    get_linked_880s;
48                 END;
49
50                 NEXT UNLESS code.match('[a-z]');
51                 IF s.subfields; NEXT UNLESS code.match(s.subfields); END;
52
53                 IF code.match('[vxyz]'); " &gt; "; END;
54
55                 # at this point, we actually have a partial term to use.
56                 raw_term = subfield.textContent;
57                 single_term = raw_term | html;
58
59                 # facets should be used as-is
60                 IF !s.facet; raw_term = raw_term.replace('\-', ' ').replace('[#"^$\+,:;&|\[\]()]', ''); END;
61
62                 all_terms.push(raw_term);
63
64                 IF s.facet;
65                     total_term = s.facet _ '[' _ all_terms.join(s.joiner).replace('\s+$', '') _ ']';
66                 ELSE;
67                     total_term = all_terms.join(" ").replace('\s+$', '');
68                 END;
69
70                 %]<a href="[%-
71                        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))
72                 -%]">[% single_term %]</a> [%-
73
74             END;
75             IF all_terms.size; "<br/>"; END;
76             FOREACH link880 IN graphics;
77                 '<div class="graphic880"' _ link880.dir _ '>';
78                 link880.value | html;
79                 '</div>';
80             END;
81             '</span>';
82         END;
83     END;
84
85     BLOCK render_hl_subject;
86         total_term = s.value;
87         IF s.facet;
88             total_term = s.facet _ '[' _ s.value _ ']';
89         END;
90
91         '<span property="about"><!-- highlighted -->';
92         %]<a href="[%-
93                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))
94         -%]">[% s.$f %]</a> [%-
95         '</span>';
96     END;
97 %]
98
99 [%  BLOCK render_all_subjects;
100     FOREACH subj IN subjects;
101         content = '';
102         df = subj.display_field;
103         IF df AND attrs.hl_display_fields.$df.size;
104             content = [];
105             FOREACH hl_s IN attrs.hl_display_fields.$df;
106                 hl_s.facet = subj.facet;
107                 next_s = PROCESS render_hl_subject(s=hl_s,f=attrs.hl_field);
108                 content.push(next_s);
109             END;
110
111             content = content.join('<br/>');
112 %]
113             <table class='rdetail_subject'>
114                 <tbody>
115                     <tr>
116                         <td class='rdetail_subject_type'>[% subj.label %]</td>
117                         <td class='rdetail_subject_value'>[% content %]</td>
118                     </tr>
119                 </tbody>
120             </table>
121 [%          
122         ELSE;
123             content = PROCESS render_subject(s=subj);
124             IF content.match('\S');
125 %]
126         <table class='rdetail_subject'>
127             <tbody>
128                 <tr>
129                     <td class='rdetail_subject_type'>[% subj.label %]</td>
130                     <td class='rdetail_subject_value'>[% content %]</td>
131                 </tr>
132             </tbody>
133         </table>
134             [%- END; %]
135         [%- END; %]
136     [%- END; %]
137 [%- END %]
138
139 [%-  subject_html = PROCESS render_all_subjects;
140     IF subject_html.length > 0;
141 %]
142 <h2 class='rdetail_related_subjects'>[% l('Search for related items by subject') %]</h2>
143 [%- subject_html %]
144 [%- END %]