LP#1638299: improve display of related headings in browse
[working/Evergreen.git] / Open-ILS / src / templates / opac / browse.tt2
1 [%- # This is the bib and authority combined record browser.
2
3     PROCESS "opac/parts/header.tt2";
4     PROCESS "opac/parts/misc_util.tt2";
5     PROCESS "opac/parts/org_selector.tt2";
6     WRAPPER "opac/parts/base.tt2";
7     INCLUDE "opac/parts/topnav.tt2";
8
9     ctx.page_title = l("Browse the Catalog");
10     blimit = CGI.param('blimit') || ctx.opac_hits_per_page || 10;
11
12     depart_list = ['blimit', 'bterm', 'bpivot'];
13     ctx.metalinks.push('<meta name="robots" content="noindex,follow">');
14     MACRO heading_use_label BLOCK;
15         SWITCH use;
16             CASE 'variant';
17                l('See');
18             CASE 'broader';
19                l('Broader term');
20             CASE 'narrower';
21                l('Broader term');
22             CASE 'other';
23                l('Related term');
24             CASE;
25                l('See');
26         END;
27     END;
28 %]
29
30     <h2 class="sr-only">[% l('Catalog Browse') %]</h2>
31     <div id="search-wrapper">
32         [%# XXX TODO Give searchbar.tt2 more smarts so we can just do:
33           # INCLUDE "opac/parts/searchbar.tt2" %]
34         <div id="search-box">
35             <span class="search_catalog_lbl"><a href="[% mkurl(ctx.opac_root _ '/home', {}, depart_list) %]">[% l('Basic Search') %]</a></span>
36             <span class="adv_search_catalog_lbl"><a href="[% mkurl(ctx.opac_root _ '/advanced', {}, depart_list) %]"
37                     id="home_adv_search_link">[%l('Advanced Search')%]</a></span>
38         
39             <span class="browse_the_catalog_lbl mobile_hide">[% l('Browse the Catalog') %]</span>
40         </div>
41     </div>
42     <div id="content-wrapper">
43         <div id="main-content">
44             <div id="browse-the-catalog">
45                 <div id="browse-controls" class='searchbar'>
46                     <form method="get" onsubmit="$('browse-submit-spinner').className = ''; return true">
47                         <input type="hidden" name="blimit"
48                             value="[% blimit %]" />
49
50                         [% control_qtype = INCLUDE "opac/parts/qtype_selector.tt2"
51                             id="browse-search-class" browse_only=1 plural=1 %]
52
53                         [% control_bterm = BLOCK %]<input type="text" name="bterm" id="browse-term"
54                             value="[% CGI.param('bterm') | html %]" />[% END %]
55                         [% control_locg = INCLUDE build_org_selector id='browse-context'
56                             show_loc_groups=1
57                             arialabel=l('Select holding library') %]
58                         [% l('Browse for [_1] starting with [_2] in [_3]', control_qtype, control_bterm, control_locg) %]
59
60                         <input id='search-submit-go' type="submit" value="[% l('Browse') %]" alt="[% l('Browse') %]" class="opac-button"/>
61                         <img id="browse-submit-spinner" 
62                         src="[% ctx.media_prefix %]/opac/images/progressbar_green.gif[% ctx.cache_key %]"
63                         class="hidden" style="width: 16px; height: 16px;" 
64                         alt="[% l('Search in progress icon') %]" />
65                     </form>
66                 </div>
67
68                 [% BLOCK browse_pager %]
69                 <div class="browse-pager">
70                     [% IF ctx.back_pivot %]
71                     <a class="opac-button" href="[% mkurl('', {bpivot => ctx.back_pivot}) %]" onclick="$('browse-pager-spinner-[% id %]').className = '';">&larr; [%l ('Back') %]</a>
72                     [% END %]
73                     [% IF ctx.pager_shortcuts;
74                         current_qtype = CGI.param('qtype') || 'title' %]
75                     <span class="browse-shortcuts">
76                         [% FOR shortcut IN ctx.pager_shortcuts %]
77                             <a href="[% mkurl('', {qtype => current_qtype, bterm => shortcut.0}, ['bpivot','query']) %]">[% shortcut.1 %]</a>
78                         [% END %]
79                     </span>
80                     [% END %]
81
82                     [% IF ctx.forward_pivot %]
83                     <a class="opac-button" href="[% mkurl('', {bpivot => ctx.forward_pivot}) %]" onclick="$('browse-pager-spinner-[% id %]').className = '';">[%l ('Next') %] &rarr;</a>
84                     [% END %]
85
86                     <img id="browse-pager-spinner-[% id %]" 
87                         src="[% ctx.media_prefix %]/opac/images/progressbar_green.gif[% ctx.cache_key %]"
88                         class="hidden" style="width: 16px; height: 16px;" 
89                         alt="[% l('Search in progress icon') %]" />
90                 </div>
91                 [% END %]
92
93                 [% PROCESS browse_pager id=0 %]
94
95                 <div id="browse-results">
96                 [% IF ctx.browse_error %]
97                     <span class="browse-error">
98                         [% l("An error occurred browsing records. " _
99                         "Please try again in a moment or report the issue " _
100                         "to library staff.") %]
101                     </span>
102                 [% ELSE %]
103                     [% IF ctx.browse_leading_article_warning %]
104                     <div class="browse-leading-article-warning">
105                             [% l("Your browse term seems to begin with an article (a, an, the). You might get better results by omitting the article.") %]
106                             [% IF ctx.browse_leading_article_alternative %]
107                             <p>
108                             [% alternative_link = BLOCK %]
109                             <a href="[% mkurl('', {bterm => ctx.browse_leading_article_alternative}, ['bpivot']) %]">[% ctx.browse_leading_article_alternative | html %]</a>
110                             [%-  END; # alternative_link BLOCK
111                                 l("Did you mean [_1]?", alternative_link);
112                             END # IF %]
113                             </p>
114                     </div>
115                     [% END %]
116                     <ul class="browse-result-list">
117                     [% FOR result IN ctx.browse_results %]
118                         <li class="browse-result">
119                             <span class="browse-result-value[% result.row_number == 0 && !CGI.param('bpivot') ? ' browse-result-best-match' : '' %]">
120                                 [% IF result.sources > 0 %] <!-- bib-linked browse value -->
121                                     <a href="[% mkurl(
122                                         ctx.opac_root _ '/results', {
123                                             'fi:has_browse_entry' => (result.browse_entry _ ',' _ result.fields)
124                                         }) %]">[% result.value | html %]</a>
125                                     <span class="browse-result-sources">([%
126                                         IF result.accurate == 'f';
127                                             l("At least"); " ";
128                                         END;
129                                     result.sources %])</span>
130                                 [% ELSE %] <!-- only authority links -->
131                                     [% result.value | html %]
132                                 [% END %]
133                             </span>
134
135                             [% FOR a IN result.authorities;
136                                     PROCESS authority_notes authority=a IF !sees.grep(a.id);
137                                END %]
138                             [% auth_headings_ul_added = 0; %]
139                                 [% seenit = {}; # for headings we've rendered
140                                    FOR a IN result.sees;
141                                     # We can go no further sans control_set.
142                                     NEXT UNLESS a.control_set;
143
144                                     # get_authority_fields is fast and cache-y.
145                                     acs = ctx.get_authority_fields(a.control_set);
146                                     FOR field_group IN a.headings;
147                                         field_id = field_group.keys.0;
148                                         field = acs.$field_id;
149                                         headings = field_group.values.0;
150                                         FOR h IN headings;
151                                             # We could display headings without
152                                             # links here when h.target is
153                                             # undef, if we wanted to, but note
154                                             # that h.target_count is only
155                                             # defined when h.target is.
156
157                                             IF h.target AND h.target_count AND result.list_authorities.grep('^' _ h.target _ '$').size == 0 AND h.main_entry;
158                                                 id = h.target; NEXT IF seenit.$id; seenit.$id = 1; 
159                                                 IF !auth_headings_ul_added;
160                                                     # only add a <ul> if we have at least one <li> (WCAG 2.0)
161                                                     auth_headings_ul_added = 1; %]
162                                                 <ul class="browse-result-authority-headings"> 
163                                                 [% END %]
164
165                                                 <li><span class="browse-result-authority-field-name">[% heading_use_label(use=h.type) %]</span>
166                                                 <a href="[% mkurl(ctx.opac_root _ '/browse', {bterm => h.heading}, ['bpivot']) %]">[% h.heading | html %]</a>
167                                                 <span class="browse-result-authority-bib-links">([% h.target_count %])</span>
168                                                 </li>
169                                             [% END %]
170                                         [% END %]
171                                     [% END %]
172                                 [% END %]
173                                 [% FOR a IN result.authorities;
174                                     # We can go no further sans control_set.
175                                     NEXT UNLESS a.control_set;
176
177                                     # get_authority_fields is fast and cache-y.
178                                     acs = ctx.get_authority_fields(a.control_set);
179                                     FOR field_group IN a.headings;
180                                         field_id = field_group.keys.0;
181                                         field = acs.$field_id;
182                                         headings = field_group.values.0;
183                                         FOR h IN headings;
184                                             # We could display headings without
185                                             # links here when h.target is
186                                             # undef, if we wanted to, but note
187                                             # that h.target_count is only
188                                             # defined when h.target is.
189
190                                             IF h.target AND h.target_count AND result.list_sees.grep('^' _ h.target _ '$').size == 0 AND !h.main_entry AND ctx.get_cgf('opac.show_related_headings_in_browse').enabled == 't';
191                                                 id = h.target; NEXT IF seenit.$id; seenit.$id = 1; 
192                                                 IF !auth_headings_ul_added;
193                                                     # only add a <ul> if we have at least one <li> (WCAG 2.0)
194                                                     auth_headings_ul_added = 1; %]
195                                                 <ul class="browse-result-authority-headings"> 
196                                                 [% END %]
197                                                 <li><span class="browse-result-authority-field-name">[% heading_use_label(use=h.type) %]</span>
198                                                 <a href="[% mkurl(ctx.opac_root _ '/results', {query => 'identifier|authority_id[' _ h.target _ ']'}) %]">[% h.heading | html %]</a>
199                                                 <span class="browse-result-authority-bib-links">([% h.target_count %])</span>
200                                                 </li>
201                                             [% END %]
202                                         [% END %]
203                                     [% END %]
204                                 [% END %]
205                             [% IF auth_headings_ul_added %]</ul>[% END %]
206                         </li>
207                     [% END %]
208                     </ul>
209                 [% END %]
210                 </div>
211
212                 [% PROCESS browse_pager id=1 %]
213             </div>
214
215             <div class="common-full-pad"></div> 
216         </div>
217     </div>
218
219     [% BLOCK authority_notes;
220         # Displays public general notes (sometimes called "scope notes" ?)
221         FOR note IN authority.notes %]
222             <div class="browse-public-general-note">
223                 <span class="browse-public-general-note-label">
224                     [% l("Note:") %]
225                 </span>
226                 <span class="browse-public-general-note-body">
227                 [% FOR piece IN note; piece | html; END %]
228                 </span>
229             </div>
230         [% END;
231     END;    # end of BLOCK authority_notes %]
232
233 [% END %]