<%inherit file="/template.html" />

<%def name="title()">
    ${_("Delegations: %s") % c.page_user.name}
</%def>

<%def name="breadcrumbs()">
    ${h.user.breadcrumbs(c.page_user)|n} &raquo; ${_("Delegations")}
</%def>

<%block name="headline">
${tiles.user.header(c.page_user, active='delegations')}
</%block>

<%block name="main_content">

<% dcount = 0 %>
<table class="delegations">
    <tr>
        <th>${_("Topic")}</th>
        <th>${_("Given")}</th>
        <th>${_("Received")}</th>
    </tr>
    %for delegateable in c.dgbs:
        %if h.contains_delegations(c.page_user, delegateable, recurse=False):
        <tr>
            <td>
                ${h.delegateable.link(delegateable)|n}
            </td>
            <td>
                <ul>
                %for delegation in filter(lambda d: d.scope==delegateable and not d.revoke_time, c.page_user.delegated):
                    <% dcount += 1 %>
                    <li class="nobullet">${tiles.delegation.outbound(delegation)}</li>
                %endfor
                </ul>
            </td>
            <td>
                <ul>
                %for delegation in filter(lambda d: d.scope==delegateable and not d.revoke_time, c.page_user.agencies):
                    <% dcount += 1 %>
                    <li class="nobullet">${tiles.delegation.inbound(delegation)}</li>
                %endfor
                </ul>
            </td>
        </tr>
        %endif
    %endfor
</table>

<!-- Fixme: Move logic to controller so we don't print the table if there are no
     delegations -->

%if dcount < 1:
    <p>${_("There are no delegations.")} </p>
%endif

</%block>
