[% long_facets = CGI.param('long_facet') || []; selected_facets = CGI.param('facet') || []; # sorted list of search facets sorted_facets = []; # we'll clobber the facet. "namespace" later # Provide a default value if unset in config.tt2 DEFAULT_DISPLAY_COUNT = facet.default_display_count || 5; IF facet.display; # facet display configuration present. Traverse the # configuration lists, find the matching facets from # search facet data, and append them to the sorted # list of facets. FOR display_chunk IN facet.display; FOR display_field IN display_chunk.facet_order; # find the matching facet in the facet data FOR facet IN ctx.search_facets.values; IF facet.cmf.field_class == display_chunk.facet_class AND facet.cmf.name == display_field; sorted_facets.push(facet); END; END; END; END; ELSE; # No facet display configuration is present. # show all facets, sorted by name. # collect facet type labels for easier sorting labels = []; FOR facet IN ctx.search_facets.values; labels.push(facet.cmf.label); END; # We used to do a sort here, but now that's handled in EGCatLoader. sorted_facets = ctx.search_facets.values; END; display_count_by_cmf = {}; FOR facet IN sorted_facets; fclass = facet.cmf.field_class; fname = facet.cmf.name; fid = facet.cmf.id; long_key = fclass _ fname %]
[% IF long_facets.grep(long_key).0; new_long = []; FOR fct IN long_facets; IF fct != long_key; new_long.push(fct); END; END; expand_url = mkurl('', {long_facet => new_long}); IF new_long.size == 0; expand_url = mkurl('', {}, ['long_facet']); END; %] [% l("Fewer") %] [% ELSIF facet.data.size > DEFAULT_DISPLAY_COUNT %] [% l("More") %] [% END %]

[% facet.cmf.label %]

[% FOR facet_data IN facet.data; display_value = facet_data.value | html; param_string = fclass _ '|' _ fname _ '[' _ facet_data.value _ ']'; new_facets = []; this_selected = 0; FOR selected IN selected_facets; IF selected == param_string; this_selected = 1; ELSE; new_facets.push(selected); END; END; display_count_by_cmf.$fid = display_count_by_cmf.$fid || 0; NEXT UNLESS long_facets.grep(long_key).0 OR display_count_by_cmf.$fid < DEFAULT_DISPLAY_COUNT; # fix syntax highlighting: > display_count_by_cmf.$fid = display_count_by_cmf.$fid + 1; IF this_selected; # This facet is already selected by the user. # Link removes the facet from the set of selected facets. %]
[% IF new_facets.size == 0 %] [% display_value %] [% ELSE %] [% display_value %] [% END %]
([% facet_data.count %])
[% ELSE; # This facet is not currently selected. If selected, # append this facet to the list of currently active facets. %] [% END %] [% END %]
[% END %]