]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/templates-bootstrap/opac/parts/result/facets-hz.tt2
LP#1778972: (follow-up) use OILSWebTemplatePath to enable/disable the bootstrap OPAC
[Evergreen.git] / Open-ILS / src / templates-bootstrap / opac / parts / result / facets-hz.tt2
1 <div class="container-fluid my-3">
2 <div class="facet_box_wrapper row">
3 [% 
4
5 long_facets = CGI.param('long_facet') || [];
6 selected_facets = CGI.param('facet') || [];
7
8 # sorted list of search facets
9 sorted_facets = [];
10
11 # we'll clobber the facet. "namespace" later
12 # Provide a default value if unset in config.tt2
13 DEFAULT_DISPLAY_COUNT = facet.default_display_count || 5;
14
15 IF facet.display;
16
17     # facet display configuration present.  Traverse the 
18     # configuration lists, find the matching facets from 
19     # search facet data, and append them to the sorted 
20     # list of facets.
21
22     FOR display_chunk IN facet.display;
23         FOR display_field IN display_chunk.facet_order;
24             # find the matching facet in the facet data
25             FOR facet IN ctx.search_facets.values;
26                 IF facet.cmf.field_class == display_chunk.facet_class 
27                         AND facet.cmf.name == display_field;
28                     sorted_facets.push(facet);
29                 END;
30             END;
31         END;
32     END;
33
34 ELSE; 
35
36     # No facet display configuration is present.
37     # show all facets, sorted by name.
38
39     # collect facet type labels for easier sorting
40     labels = []; 
41     FOR facet IN ctx.search_facets.values;
42         labels.push(facet.cmf.label);
43     END;
44     
45     # We used to do a sort here, but now that's handled in EGCatLoader.
46     sorted_facets = ctx.search_facets.values;
47 END;
48
49 display_count_by_cmf = {};
50
51 FOR facet IN sorted_facets;
52     fclass = facet.cmf.field_class;
53     fname = facet.cmf.name;
54     fid = facet.cmf.id;
55     long_key = fclass _ fname %]
56
57     <div id="facets" class="col-xs-12 col-sm-12 col-md-6 col-lg-3">
58     <div class="card">
59         <div class="card-header">
60                 <h4 class="title text-center">[% facet.cmf.label %]</h4>
61             <span class="float-right">
62                 [% IF long_facets.grep(long_key).0;
63                     new_long = [];
64                     FOR fct IN long_facets;
65                         IF fct != long_key;
66                             new_long.push(fct);
67                         END;
68                     END;
69                     expand_url = mkurl('', {long_facet => new_long});
70                     IF new_long.size == 0;
71                         expand_url  = mkurl('', {}, ['long_facet']);
72                     END;
73                 %]
74                     <a class="button" href="[% expand_url %]#facets"
75                       title="[% l('Show Fewer [_1] Entries', facet.cmf.label) %]" rel="nofollow" vocab="">
76                       [% l("Fewer") %]
77                     </a>
78                 [% ELSIF facet.data.size > DEFAULT_DISPLAY_COUNT %]
79                     <a class="button" 
80                       title="[% l('Show More [_1] Entries', facet.cmf.label) %]"
81                       href="[% mkurl('', {long_facet => long_facets.merge([long_key])}) %]#facets" rel="nofollow" vocab="">
82                       [% l("More") %]
83                     </a>
84                 [% END %]
85             </span>
86         </div>
87         <div class="card-body" style="max-height:250px;overflow-x:overlay;">
88             <div>
89             [% FOR facet_data IN facet.data;
90                 display_value = facet_data.value | html;
91                 param_string = fclass _ '|' _ fname _ '[' _ facet_data.value _ ']';
92                 new_facets = [];
93                 this_selected = 0;
94                 FOR selected IN selected_facets;
95                     IF selected == param_string; 
96                         this_selected = 1; 
97                     ELSE;
98                         new_facets.push(selected);
99                     END;
100                 END;
101
102                 display_count_by_cmf.$fid = display_count_by_cmf.$fid || 0;
103
104                 NEXT UNLESS long_facets.grep(long_key).0 OR
105                     display_count_by_cmf.$fid < DEFAULT_DISPLAY_COUNT;
106
107                 # fix syntax highlighting: >
108
109                 display_count_by_cmf.$fid = display_count_by_cmf.$fid + 1;
110
111                 IF this_selected;
112                     # This facet is already selected by the user. 
113                     # Link removes the facet from the set of selected facets.
114                 %] 
115                     <div class="facet_template facet_template_selected">
116                         <div class="facet">
117                             [% IF new_facets.size == 0 %]
118                             <a
119                               title="[% l('Show all results, not just those matching this term') %]"
120                               href="[% mkurl('', {}, ['facet']) %]" rel="nofollow" vocab="">[% display_value %]</a>
121                             [% ELSE %]
122                             <a
123                               title="[% l('Expand to also show results not matching this term') %]"
124                               href="[% mkurl('', {facet => new_facets}) %]" rel="nofollow" vocab="">[% display_value %]</a>
125                             [% END %]
126                         </div>
127                         <div class="count">([% facet_data.count; IF facet_data.count == (ctx.superpage + 1) * ctx.superpage_size; '+'; END %])</div>
128                     </div>
129                 [% 
130                     ELSE;
131                     # This facet is not currently selected.  If selected, 
132                     # append this facet to the list of currently active facets.
133                 %]
134                     <div class="facet_template">
135                         <div class="facet">
136                             <a
137                               title="[% l('Limit to results matching this term') %]"
138                               href='[% mkurl('', {facet => selected_facets.merge([param_string])}, ['page']) %]' rel="nofollow" vocab="">
139                               [% display_value %]
140                             </a>
141                         </div>
142                         <div class="count">([% facet_data.count %])</div>
143                     </div>
144                     
145                 [% END %]
146             [% END %]
147             </div>
148             </div>
149         </div> <!-- box_wrapper -->
150     </div> <!-- facet_box_temp -->
151 [% END %]
152 </div> <!-- facet_box_wrapper -->
153 </div>