close_facets = CGI.param('close_facet') || [];
selected_facets = CGI.param('facet') || [];
-# collect facet type labels for easier sorting
-labels = [];
-FOR facet IN ctx.search_facets.values;
- labels.push(facet.cmf.label);
-END;
+# sorted list of search facets
+sorted_facets = [];
+
+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;
-FOR facet_label IN labels.sort;
+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;
- IF facet.cmf.label == facet_label;
- fclass = facet.cmf.field_class;
- fname = facet.cmf.name;
- close_key = fclass _ fname %]
+ labels.push(facet.cmf.label);
+ END;
+
+ FOR facet_label IN labels.sort;
+ FOR facet IN ctx.search_facets.values;
+ IF facet.cmf.label == facet_label;
+ sorted_facets.push(facet);
+ END;
+ END;
+ END;
+END;
- <div class="facet_box_temp">
- <div class="header">
- <span class="button">
+FOR facet IN sorted_facets;
+ fclass = facet.cmf.field_class;
+ fname = facet.cmf.name;
+ close_key = fclass _ fname %]
- [% IF close_facets.grep(close_key).0;
- new_close = [];
- FOR fct IN close_facets;
- IF fct != close_key;
- new_close.push(fct);
- END;
- END;
- expand_url = mkurl('', {close_facet => new_close});
- IF new_close.size == 0;
- expand_url = mkurl('', {}, ['close_facet']);
- END;
- %]
- <a href="[% expand_url %]"><img
- src="[% ctx.media_prefix %]/images/adv_search_plus_btn.png" alt="[% l('Expand') %]" /></a>
- [% ELSE %]
- <a href="[% mkurl('', {close_facet => close_facets.merge([close_key])}) %]"><img
- src="[% ctx.media_prefix %]/images/adv_search_minus_btn.png" alt="[% l('Collapse') %]" /></a>
- [% END %]
- </span>
- <div class="title">[% facet.cmf.label %]</div>
- </div>
- [% IF !close_facets.grep(close_key).0 %]
- <div class="box_wrapper">
- <div class="box">
- [% 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);
+ <div class="facet_box_temp">
+ <div class="header">
+ <span class="button">
+
+ [% IF close_facets.grep(close_key).0;
+ new_close = [];
+ FOR fct IN close_facets;
+ IF fct != close_key;
+ new_close.push(fct);
END;
END;
- IF this_selected;
- # This facet is already selected by the user.
- # Link removes the facet from the set of selected facets.
- %]
- <div class="facet_template facet_template_selected">
- <div class="facet">
- [% IF new_facets.size == 0 %]
- <a href="[% mkurl('', {}, ['facet']) %]">[% display_value %]</a>
- [% ELSE %]
- <a href="[% mkurl('', {facet => new_facets}) %]">[% display_value %]</a>
- [% END %]
- </div>
- <div class="count">([% facet_data.count %])</div>
- <div class="clear"> </div>
+ expand_url = mkurl('', {close_facet => new_close});
+ IF new_close.size == 0;
+ expand_url = mkurl('', {}, ['close_facet']);
+ END;
+ %]
+ <a href="[% expand_url %]"><img
+ src="[% ctx.media_prefix %]/images/adv_search_plus_btn.png" alt="[% l('Expand') %]" /></a>
+ [% ELSE %]
+ <a href="[% mkurl('', {close_facet => close_facets.merge([close_key])}) %]"><img
+ src="[% ctx.media_prefix %]/images/adv_search_minus_btn.png" alt="[% l('Collapse') %]" /></a>
+ [% END %]
+ </span>
+ <div class="title">[% facet.cmf.label %]</div>
+ </div>
+ [% IF !close_facets.grep(close_key).0 %]
+ <div class="box_wrapper">
+ <div class="box">
+ [% 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;
+ IF this_selected;
+ # This facet is already selected by the user.
+ # Link removes the facet from the set of selected facets.
+ %]
+ <div class="facet_template facet_template_selected">
+ <div class="facet">
+ [% IF new_facets.size == 0 %]
+ <a href="[% mkurl('', {}, ['facet']) %]">[% display_value %]</a>
+ [% ELSE %]
+ <a href="[% mkurl('', {facet => new_facets}) %]">[% display_value %]</a>
+ [% END %]
</div>
- [%
- ELSE;
- # This facet is not currently selected. If selected,
- # append this facet to the list of currently active facets.
- %]
- <div class="facet_template">
- <div class="facet">
- <a href='[% mkurl('', {facet => selected_facets.merge([param_string])}, ['page']) %]'>[% display_value %]</a>
- </div>
- <div class="count">([% facet_data.count %])</div>
- <div class="clear"> </div>
+ <div class="count">([% facet_data.count %])</div>
+ <div class="clear"> </div>
+ </div>
+ [%
+ ELSE;
+ # This facet is not currently selected. If selected,
+ # append this facet to the list of currently active facets.
+ %]
+ <div class="facet_template">
+ <div class="facet">
+ <a href='[% mkurl('', {facet => selected_facets.merge([param_string])}, ['page']) %]'>[% display_value %]</a>
</div>
- [% END %]
+ <div class="count">([% facet_data.count %])</div>
+ <div class="clear"> </div>
+ </div>
[% END %]
- </div>
- </div> <!-- box_wrapper -->
[% END %]
- </div> <!-- facet_box_temp -->
+ </div>
+ </div> <!-- box_wrapper -->
[% END %]
- [% END %]
+ </div> <!-- facet_box_temp -->
[% END %]
</div> <!-- facet_box_wrapper -->