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