
<%def name="namedpager(pager)">
<div class="pager_wrapper">
    %if (pager.enable_pages and len(pager.items)) or hasattr(pager.sorts, 'render') or (len(pager.sorts.keys()) > 1 and pager.enable_sorts):
        <div class="floatbox">
            %if pager.enable_pages:
                <span class="pager_items">
                    %if len(pager.items):
                    ${_("%(start)s-%(end)s out of %(total)s") % dict(start=pager.offset+1, end=pager.offset+len(pager.items), total=pager.total_num_items())}
                    %endif
                </span>
            %endif
            %if hasattr(pager.sorts, 'render'):
            ## New style NamedSorts-object
            ${pager.sorts.render()}
            %elif len(pager.sorts.keys()) > 1 and pager.enable_sorts:
            ## Old style index based sort
            ${index_based_sort_dropdown(pager.sorts, pager)}
            %endif
        </div>
    %endif
    %if pager.enable_pages or pager.enable_sorts:
    <ul class="content_list ${pager.name}_pager">
    %endif
    %if not (pager.enable_pages or pager.enable_sorts):
    <ul class="content_list ${pager.name}_pager without_paging">
    %endif
    %if not len(pager.items):
        <li class="infobox">${_("No entries.")}</li>
    %endif
    %for item in pager.items:
        ${pager.itemfunc(item)}
    %endfor
      </ul>
    %if pager.enable_pages:
        %if pager.pages > 1:
        <div class="pager">
            <div class="prev_page">
                %if pager.page > 1:
                <a href="${pager.build_url(page=pager.page-1)|n}#top"
                   target="_self">&laquo; ${_("previous")}</a>
                %else:
                <span>&laquo; ${_("previous")}</span>
                %endif
            </div>
            %for page in pager.pages_items():
                %if page['seperator']:
                    <span class="seperator">...</span>
                %else:
                    %if page['current']:
                        <span class="current">${page['label']}</span>
                    %else:
                        <a href="${page['url']|n}#top"
                           target="_self"
                           class="${page['class']}">${page['label']}</a>
                    %endif
                %endif
            %endfor
            <div class="next_page">
                %if pager.page < pager.pages:
                <a href="${pager.build_url(page=pager.page+1)|n}#top"
                   target="_self">${_("next")} &raquo;</a>
                %else:
                <span>${_("next")} &raquo;</span>
                %endif
            </div>
        </div>
        %endif
        %if pager.page_sizes():
        <div class="pager_sorts bottom">
            %for size in pager.page_sizes():
            %if size['current']:
            ${size['size']}
            %else:
            <a href="${size['url']|n}#top" rel="nofollow" target="_self">${size['size']}</a>
            %endif
            ${'|' if not size['last'] else ''}
            %endfor
            ${_("entries")}
        </div>
        %endif
    %endif
</div>
</%def>

<%def name="facets(pager, cls=None)">
<% is_admin = can.instance.any_admin() %>
%if any(facet.available(is_admin) for facet in pager.facets):
<div id="facets" ${'class=%s'%cls if cls is not None else ''}>
<h3 id="facets-heading">${_("Filter list")}</h3>

  %for facet in pager.facets:
    %if facet.available(is_admin):
    <div class="facet facet-${facet.name}">
        ${facet.render()}
    </div>
    %endif
  %endfor
%endif
</div>
</%def>

<%def name="facet(facet)">
<h4>
    ${facet.title}
    %if facet.used:
    <a class="remove"
       href="${facet.unselect_all_link()|n}"
       rel="nofollow">(${_("reset")})</a>
    %endif

    %if facet.badge_type is not None and can.instance.any_admin():
    <a class="button_small edit"
        href="${h.base_url('/badge/%s' % facet.badge_type)}"
        rel="#overlay-form">${_(u"Edit")}</a>
    %endif
</h4>
%if facet.description:
<p>${facet.description}</p>
%endif

${facet_items(facet.current_items)}
</%def>

<%def name="facet_items(items, indent=True)">
<ul${'' if indent else ' class="noindent"' | n}>
    %if not items:
    ${_(u'None')}
    %endif
    %for item in items:
    <li class="facet-item-level-${item['level']}${' expanded' if item['open'] else ''}">
        %if item['visible']:
        %if item['disabled']:
        <span class="disabled">
            %if not item['hide_checkbox']:
            <input type="checkbox" disabled="disabled" />
            %endif
            <span class="facet_item_text">${item['link_text']}</span>
            <span>(${item['current_count']})</span>
        </span>
        %else:
            %if item['selected']:
            <span class="selected">
                <input type="checkbox" class="facet_check" checked="checked" />
                <a class="facet_item_text remove" href="${item['url']|n}"
                  rel="nofollow">${item['link_text']}</a>
                <span>(${item['current_count']})</span>
            </span>
            %else:
            <span class="selected">
              <input type="checkbox" class="facet_check" />
              <a class="facet_item_text ${item['selected']}"
                 href="${item['url']|n}"
                 rel="nofollow">${item['link_text']}</a>
               <span>(${item['current_count']})</span>
            </span>
            %endif
        %endif

        ${h.literal(item['thumbnail'])}

        %if item["children"]:
        <a class="expand_arrow" href="#"></a>
        ${facet_items(item["children"], indent=not item['hide_checkbox'])}
        %endif
        %endif

    </li>
    %endfor
</ul>
</%def>

<%def name="overlay_pager(render_facets=True)">

<div>${pager.render_pager()}</div>
%if render_facets:
<div>${pager.render_facets()}</div>
%endif
</%def>


<%def name="index_based_sort_dropdown(sorts, pager)">

%if len(sorts.keys()):

<%
zipped = zip(pager.sorts.keys(), xrange(1, len(pager.sorts.keys()) + 1))
help = lib.pager.help_strings()
%>

<div class="filter_box">
    <div class="only-js">
        ${_('Sort:')}
        <select class="sort_options autoreload"
                name="${pager.sort_param}">
            %for sort, i in zipped:
            <% selected = i == pager.selected_sort %>
            <option value="${i}"
                    %if selected:
                    selected="selected"
                    %endif
                    title='${help.get(sort, '')}'
                    data-url="${pager.build_url(sort=i)|n}">
                ${sort}
            </option>
            %endfor
        </select>
    </div>
</div>
%endif

</%def>

<%def name="sort_dropdown(sorts)">
<%
help = lib.pager.help_strings()
%>
%if len(sorts):
<div class="filter_box">
    <div class="only-js">
        ${_('Sort:')}
        <% selected = sorts.selected() %>
        <select class="sort_options autoreload"
                name="${sorts.pager.sort_param}">
            %for (group, options) in sorts.grouped_options():
            %if group is not None:
            <optgroup label="${group}">
            %endif
                %for sort in options:
                <%
                selected_attr = ''
                if (sort == selected):
                    selected_attr = 'selected="selected"'
                %>
                <option value="${sort.value}"
                        ${selected_attr|n}
                        title='${help.get(sort.label, '')}'
                        data-url="${sorts.pager.build_url(sort=sort.value)}">
                    ${sort.label}
                </option>
                %endfor
            %if group is not None:
            </optgroup>
            %endif
            %endfor
        </select>
    </div>
</div>
%endif
</%def>


<%def name="sort_slidedown(sorts)">
%if len(sorts):
<%
selected = sorts.selected()
param = sorts.pager.sort_param
%>
<div class="filter_box">
    <div class="only-js">
        ${_('Sort:')}
        <span class="btn-group"
             id="${param}_btn_group">
            <a id="${param}_btn"
               class="button_round showhide_button"
               data-target="#${param}_options"
               data-target-speed="fast"
               data-toggle-class="less"
               href="#">
                ${selected.label}
            </a>
        </span>
    </div>
</div>
<div id="${param}_options" style="display: none">
    %for (group, options) in sorts.grouped_options():
    <div class="sort_group">
        %if group is not None:
        <h6><em>${group}</em></h6>
        %else:
        <h6>&nbsp;</h6>
        %endif
        <ul class="nobullet">
            %for sort in options:
            <li data-sort-key="${sort.value}"
                %if sort is selected:
                class="active_sort"
                %endif
            >
                %if sort is selected:
                <em>${sort.label}</em>
                %else:
                <a href="${sorts.pager.build_url(sort=sort.value)}"
                   title="${sort.description or ''}"
                   class="${sort.description and 'ttip' or ''}">
                ${sort.label}
                </a>
                %endif
            </li>
        %endfor
        </ul>
    </div>
    %endfor
</div>

%endif
</%def>

