<html xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      i18n:domain="senaite.core">

<body>

<div metal:define-macro="portlet"
     tal:define="member python: context.portal_membership.getAuthenticatedMember()"
     tal:condition="python:member.has_role(('LabManager', 'LabClerk', 'Analyst'))">

<tal:late
     tal:define="portal context/portal_url/getPortalObject;
                 plone_view context/@@plone;
                 DateTime python:modules['DateTime'].DateTime;
                 sm python:modules['AccessControl'].getSecurityManager();
                 now python: DateTime();
                 rs python:context.bika_analysis_catalog(
                    portal_type='Analysis',
                    getDueDate={'query': [now,], 'range': 'max'},
                    sort_on='getDateReceived',
                    review_state=['sample_received',
                                  'sample_due'],
                    cancellation_state='active');
                 results python:[p.getObject() for p in rs[:5]];"
     tal:condition="python:results">

    <dl class="portlet" id="portlet-late-analysis">

        <dt class="portletHeader portletLateAnalyses">
        <img src="" tal:attributes="src string:${context/portal_url}/++resource++bika.lims.images/late.png"/>
        <span i18n:translate="">Late Analyses</span></dt>

        <tal:block repeat="o results">
        <dd style="padding-top:4px;padding-bottom:0px;">

            <a href="#" class="marker"
                tal:attributes="href python: sm.checkPermission('BIKA: Edit Results', o) and o.aq_parent.absolute_url() + '/manage_results' or o.aq_parent.absolute_url();
                                title python: o.aq_parent.getId();
                                id python:'late_analyses_'+o.Title();">
                <img src="" height="16" width="16"
                        tal:attributes="src string:${context/portal_url}/++resource++bika.lims.images/analysisservice.png"/>
                <span tal:replace="o/Title|o/getId"/>
            </a>

            <div class="portletDetails"
                 style="text-align:right"
                 tal:define="moddate o/ModificationDate;"
                 tal:content="python:plone_view.toLocalizedTime(moddate)"/>
        </dd>
        </tal:block>

        <dd class="portletFooter" tal:condition="python:len(rs) > 5">

            <a href=""
                class="portletMore"
                tal:attributes="href string:${context/portal_url}/late_analyses"
                >
                <span tal:content="python:str(len(rs)-5)"/>
                <span i18n:translate="">More</span>
            </a>

        </dd>

    </dl>
</tal:late>

</div>

</body>

</html>
