Pagination cleanup, prepared for new CSS

This commit is contained in:
Thomas Gelf 2014-02-18 17:42:00 +00:00
parent 6fdb7e15d8
commit aa821d9cd4
1 changed files with 56 additions and 37 deletions

View File

@ -1,8 +1,17 @@
<?php <?php
use Icinga\Web\Url; use Icinga\Web\Url;
// Please note that there is a reason for the strange way of writing ><.
// It was the best compromise that came to my mind to get rid of whitespaces
// between inline-block elements. Found no better hack - and table-cell seems
// to be less supported.
if ($this->pageCount <= 1) return; if ($this->pageCount <= 1) return;
?><ul class="pagination"
<?php
$fromto = $this->translate('%d to %d of %d'); $fromto = $this->translate('%d to %d of %d');
$total = $this->totalItemCount; $total = $this->totalItemCount;
$limit = $this->itemCountPerPage; $limit = $this->itemCountPerPage;
@ -19,25 +28,27 @@ $title_next = sprintf(
($this->current + 1) * $limit, ($this->current + 1) * $limit,
$total $total
); );
$li = ' ><li%s><a href="%s" title="%s">%s</a></li
';
?> ?>
<ul class="pagination">
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<li>
<a href="<?= Url::fromRequest()->overwriteParams(array('page' => $this->previous))->getAbsoluteUrl() ?>"
title="<?= $title_prev ?>">« <?= $this->translate('Prev') ?>
</a>
</li>
<?php else: ?>
<li class="disabled"><span>« <?= $this->translate('Prev') ?></span></li>
<?php endif ?>
<!-- Numbered page links -->
<?php <?php
foreach ($this->pagesInRange as $page):
if (isset($this->previous)) {
printf(
$li,
'',
Url::fromRequest()->overwriteParams(
array('page' => $this->previous)
)->getAbsoluteUrl(),
$title_prev,
'« ' . $this->translate('Prev')
);
} else {
echo ' ><li class="disabled"><span>« ' . $this->translate('Prev') . '</span></li';
}
foreach ($this->pagesInRange as $page) {
$start = ($page - 1) * $limit + 1; $start = ($page - 1) * $limit + 1;
$end = $page * $limit; $end = $page * $limit;
if ($end > $total) { if ($end > $total) {
@ -46,26 +57,34 @@ foreach ($this->pagesInRange as $page):
$title = sprintf($fromto, $start, $end, $total); $title = sprintf($fromto, $start, $end, $total);
$class = $page === $this->current ? ' class="active"' : ''; $class = $page === $this->current ? ' class="active"' : '';
if ($page === '...'): ?> if ($page === '...') {
<li class="disabled"><span>...</span></li> echo ' ><li class="disabled"><span>...</span></li';
<?php else: ?> } else {
<li <?= $class ?>> printf(
<a href="<?= Url::fromRequest()->overwriteParams(array('page' => $page))->getAbsoluteUrl() ?>" title="<?= $title ?>"> $li,
<?= $page ?> $class,
</a> Url::fromRequest()->overwriteParams(
</li> array('page' => $page)
<?php )->getAbsoluteUrl(),
endif; $title,
endforeach; $page
);
}
}
if (isset($this->next)) {
printf(
$li,
'',
Url::fromRequest()->overwriteParams(
array('page' => $this->next)
)->getAbsoluteUrl(),
$title_next,
$this->translate('Next') . ' »'
);
} else {
echo ' ><li class="disabled"><span>' . $this->translate('Next') . ' »</span></li';
}
?> ?>
<!-- Next page link --> ></ul>
<? if (isset($this->next)): ?>
<li>
<a href="<?= Url::fromRequest()->overwriteParams(array('page' => $this->next))->getAbsoluteUrl() ?>"
title="<?= $title_next ?>"><?= t('Next') ?> »
</a>
</li>
<? else: ?>
<li class="disabled"><span><?= t('Next') ?> »</span></li>
<? endif ?>
</ul>