<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$this->htmlElement('body')->appendAttribute('class', 'jobs browse');
?>

<?php echo $this->pageTitle($translate('Jobs')); ?>

<div class="browse-controls">
    <?php echo $this->pagination(); ?>
    <?php echo $this->browse()->renderSortSelector('jobs'); ?>
</div>
<?php $this->trigger('view.browse.before'); ?>

<?php if (count($jobs)): ?>
<table class="tablesaw" data-tablesaw-mode="stack">
    <thead>
        <tr>
            <th><?php echo $translate('ID'); ?></th>
            <th><?php echo $translate('Class'); ?></th>
            <th><?php echo $translate('Status'); ?></th>
            <th><?php echo $translate('Owner'); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($jobs as $job): ?>
        <?php
        if ($owner = $job->owner()) {
            $ownerText = $this->hyperlink($owner->email(), $this->url(
                'admin/id',
                [
                    'controller' => 'user',
                    'action' => 'show',
                    'id' => $owner->id()]
                )
            );
        } else {
            $ownerText = $translate('[No owner]');
        }
        ?>
        <tr>
            <td>
                <?php echo $job->link($escape($job->id())); ?>
            </td>
            <td><?php echo $escape($job->jobClass()); ?></td>
            <td><?php echo $escape($translate($job->statusLabel())); ?></td>
            <td><?php echo $ownerText; ?></td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php $this->trigger('view.browse.after'); ?>
<div class="browse-controls">
    <?php echo $this->pagination(); ?>
</div>

<?php else: ?>

<div class="no-resources">
    <p><?php echo $translate('Omeka could not find any jobs.'); ?></p>
</div>

<?php endif; ?>
