<%!
    from crab.util.string import alphanum
    from crab.util.web import abbr

    scripts = ['crontabs']
%>
<%inherit file="base.html"/>

<%block name="links">
% if user is not None:
<span>${user | h}</span>
% elif host is not None:
<span>${host | h}</span>
% endif
</%block>

% for (key, joblist) in sorted(jobs.items()):
<h2>
% if user is None:
<a href="/user/${key | h}">
% else:
<a href="/host/${key | h}">
% endif
${key | h}
</a></h2>

<% hasDeleted = False %>
<table id="table_${key | alphanum}">
    <tr>
        <th>Time</th>
        <th>Job ID</th>
        <th>Command</th>
    </tr>
% for job in joblist:
% if job['deleted'] is None:
    <tr>
% else:
    <tr class="deleted_${key | alphanum} hidden">
    <% hasDeleted = True %>
% endif
% if job.get('time') is not None:
        <td>${job['time'] | h}</td>
% else:
        <td class="status_unknown">Unspecified</td>
% endif
% if job.get('crabid') is not None:
        <td class="linkcell"><a href="/job/${job['id'] | h}" id="crabid_${job["id"] | h}">${job["crabid"] | h}</a></td>
% else:
        <td class="status_unknown" id="crabid_${job["id"] | h}">Unspecified</td>
% endif
        <td class="linkcell"><a href="/job/${job['id'] | h}">${job['command'] | abbr}</a></td>
    </tr>
% endfor
</table>

<p>
% if hasDeleted:
<a href="#" id="show_deleted_${key | alphanum}"><span class="icon-trash"></span> Show deleted.</a>
<a href="#" id="hide_deleted_${key | alphanum}" class="hidden"><span class="icon-trash"></span> Hide deleted.</a>
% endif
% if raw[key] is not None:
<a href="#" id="show_raw_${key | alphanum}"><span class="icon-file"></span> Show raw crontab.</a>
<a href="#" id="hide_raw_${key | alphanum}" class="hidden"><span class="icon-file"></span> Hide raw crontab.</a>
% endif
</p>

% if raw[key] is not None:
<pre id="raw_${key | alphanum}" class="hidden">
% for line in raw[key]:
${line | h}
% endfor
</pre>
% endif

% endfor

<p>
<a href="#" id="show_all_table" class="hidden"><span class="icon-table"></span> Show all tables.</a>
<a href="#" id="hide_all_table"><span class="icon-table"></span> Hide all tables.</a>

<a href="#" id="show_all_raw"><span class="icon-file"></span> Show all raw crontabs.</a>
<a href="#" id="hide_all_raw" class="hidden"><span class="icon-file"></span> Hide all raw crontabs.</a>
</p>
