Skip to content
Code-Schnipsel Gruppen Projekte
Commit 3b9bd7c6 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

refactor: Pagination in quiqqer/controls mit aufgenommen

Übergeordneter 4e30e9e4
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
@CHARSET "UTF-8";
.quiqqer-sheets-mobile select {
width: 100%;
}
.quiqqer-sheets-desktop {
clear: both;
float: left;
margin: 0;
width: calc(100% - 120px);
}
.quiqqer-sheets-desktop__100 {
width: 100%;
}
.quiqqer-sheets-desktop:last-child {
margin: 20px 0;
}
.quiqqer-sheets-desktop a,
.quiqqer-sheets-desktop span {
border: 1px solid #D0D3D3;
border-top: 1px solid #D0D3D3;
border-bottom: 1px solid #D0D3D3;
float: left;
line-height: 30px;
margin: 0;
text-align: center;
text-decoration: none;
}
.quiqqer-sheets-desktop-disabled {
color: #AAAAAA;
cursor: default;
border-color: #DDDDDD;
}
.quiqqer-sheets-desktop-current {
color: #FFFFFF;
cursor: default;
background: #666;
border-color: #666;
}
.quiqqer-sheets-desktop a:hover {
color: #FFFFFF;
text-decoration: none;
}
.quiqqer-sheets-desktop-limits {
float: right;
line-height: 40px;
text-align: center;
width: 120px;
}
.quiqqer-sheets-desktop .more {
border: none;
}
\ No newline at end of file
<div class="quiqqer-sheets-mobile hide-on-desktop">
<select name="select-sheet" class="hide-on-desktop" onchange="window.location = this.value">
{section name=sheets start=0 loop=$count}
{assign var=num value=$smarty.section.sheets.index+1}
{$getParams['limit'] = $limit}
{$getParams['sheet'] = $num}
<option value="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
{if $num == $active}
selected="selected"
{/if}
>{locale group="quiqqer/bricks"
value="controls.pagination.mobile.option"
from=$num
max=$count
}</option>
{/section}
</select>
</div>
<div class="quiqqer-sheets-desktop hide-on-mobile{if !$this->getAttribute('showLimit')} quiqqer-sheets-desktop__100{/if}"
{if $this->getAttribute('useAjax')}style="opacity:0"{/if}
>
{if (!isset($smarty.request.sheet) || $active == 1)
&& $this->getAttribute('useAjax') === false
}
<span class="quiqqer-sheets-desktop-disabled fa fa-angle-double-left quiqqer-sheets-first"
title="{t}quiqqer/bricks controls.pagination.first.page{/t}">
</span>
{else}
{$getParams['limit'] = $limit}
{$getParams['sheet'] = false}
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
class="fa fa-angle-double-left quiqqer-sheets-first"
title="{t}quiqqer/bricks controls.pagination.first.page{/t}">
</a>
{/if}
{if (!isset($smarty.request.sheet) || $active <= 1)
&& $this->getAttribute('useAjax') === false
}
<span class="quiqqer-sheets-desktop-disabled fa fa-angle-left quiqqer-sheets-prev"
title="{t}quiqqer/bricks controls.pagination.back{/t}">
</span>
{else}
{math assign=backward equation="x - y" x=$active y=1}
{if $backward == 1}
{$getParams['limit'] = $limit}
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
class="fa fa-angle-left quiqqer-sheets-prev"
title="{t}quiqqer/bricks controls.pagination.back{/t}">
</a>
{else}
{$getParams['sheet'] = $backward}
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
class="fa fa-angle-left quiqqer-sheets-prev"
title="{t}quiqqer/bricks controls.pagination.back{/t}">
</a>
{/if}
{/if}
{if $start > 1}
<span class="more">...</span>
{/if}
{section name=sheets start=$start loop=$end+1}
{assign var=num value=$smarty.section.sheets.index}
{if $num == $active}
{if $this->getAttribute('useAjax') === false}
<span class="quiqqer-sheets-desktop-current">{$num}</span>
{else}
{$getParams['limit'] = $limit}
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
class="quiqqer-sheets-sheet quiqqer-sheets-desktop-current"
data-page="{$num}"
>
{$num}
</a>
{/if}
{else}
{$getParams['limit'] = $limit}
{if $num == 1}
{$getParams['sheet'] = false}
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
class="quiqqer-sheets-sheet"
data-page="{$num}"
>
{$num}
</a>
{else}
{$getParams['sheet'] = $num}
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
class="quiqqer-sheets-sheet"
data-page="{$num}"
>
{$num}
</a>
{/if}
{/if}
{/section}
{if $end < $count}
<span class="more">...</span>
{/if}
{if $active >= $count && $this->getAttribute('useAjax') === false}
<span class="quiqqer-sheets-desktop-disabled fa fa-angle-right quiqqer-sheets-next"
title="{t}quiqqer/bricks controls.pagination.next{/t}"
>
</span>
{else}
{math assign=forward equation="x + y" x=$active y=1 }
{$getParams['sheet'] = $forward}
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
class="fa fa-angle-right quiqqer-sheets-next"
title="{t}quiqqer/bricks controls.pagination.next{/t}"
>
</a>
{/if}
{if $active >= $count && $this->getAttribute('useAjax') === false}
<span class="quiqqer-sheets-desktop-disabled fa fa-angle-double-right quiqqer-sheets-last"
title="{t}quiqqer/bricks controls.pagination.last.page{/t}"
></span>
{else}
{$getParams['sheet'] = $count}
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
title="{t}quiqqer/bricks controls.pagination.last.page{/t}"
class="fa fa-angle-double-right quiqqer-sheets-last"
></a>
{/if}
</div>
{if $this->getAttribute('showLimit') && $limits}
<div class="quiqqer-sheets-desktop-limits">
{foreach from=$limits item=limitEntry name=limits}
{$getParams['limit'] = $limitEntry}
{$getParams['sheet'] = false}
<a href="{$Site->getUrl($pathParams, $getParams)}" data-limit="{$limitEntry}">
{$limitEntry}
</a>
{if not $smarty.foreach.limits.last} | {/if}
{/foreach}
</div>
{/if}
......@@ -13,288 +13,8 @@
*
* @author www.pcsg.de (Henning Leutz)
* @licence For copyright and license information, please view the /README.md
* @deprecated use QUI\Controls\Navigating\Pagination
*/
class Pagination extends QUI\Control
class Pagination extends QUI\Controls\Navigating\Pagination
{
/**
* GET Params
*
* @var array
*/
protected $getParams = array();
/**
* URL Params
*
* @var array
*/
protected $urlParams = array();
/**
* constructor
*
* @param array $attributes
*/
public function __construct($attributes = array())
{
$this->setAttributes(array(
'showLimit' => false,
'limits' => '[10,20,50]',
'limit' => 10,
'order' => false,
'sheet' => 1,
'useAjax' => false,
'showmax' => 10,
'anchor' => false
));
parent::__construct($attributes);
$this->addCSSFile(
dirname(__FILE__) . '/Pagination.css'
);
if ($this->getAttribute('useAjax')) {
$this->setAttribute(
'data-qui',
'package/quiqqer/bricks/bin/Controls/Pagination'
);
} else {
$this->setAttribute('data-qui', false);
}
$this->setAttribute('class', 'quiqqer-pagination grid-100 grid-parent');
}
/**
* (non-PHPdoc)
*
* @see \QUI\Control::create()
*/
public function getBody()
{
$Engine = QUI::getTemplateManager()->getEngine();
$Site = $this->getAttribute('Site');
$Project = $Site->getProject();
$count = $this->getAttribute('sheets');
if ($count === false) {
if ($this->getAttribute('limit') &&
$this->getAttribute('count')
) {
$count = ceil(
(int)$this->getAttribute('count') /
(int)$this->getAttribute('limit')
);
$this->setAttribute('sheets', $count);
}
}
$showmax = $this->getAttribute('showmax');
$limits = $this->getAttribute('limits');
if ($this->getAttribute('useAjax')) {
$this->setAttribute(
'data-qui',
'package/quiqqer/bricks/bin/Controls/Pagination'
);
} else {
$this->setAttribute('data-qui', false);
}
if ($limits && is_string($limits)) {
$limits = json_decode($limits, true);
if (!is_array($limits)) {
$limits = false;
}
}
$active = $this->getAttribute('sheet');
$anchor = '';
if ($this->getAttribute('anchor')) {
$anchor = $this->getAttribute('anchor');
}
if ($showmax >= $count) {
$showmax = false;
}
if (!$showmax) {
$showmax = $count * 2;
}
$gap = floor($showmax / 2);
$start = $active - $gap;
$end = $active + $gap;
if ($showmax % 2 === 0) {
$end--; // -1, weil aktuelle seite nicht mit berechnet werden soll
}
if ($start <= 0) {
$start = 1;
$end = $showmax;
}
if ($end >= $count) {
$end = $count;
$start = $end - $showmax + 1;
if ($start <= 0) {
$start = 1;
}
}
// get params
$limit = $this->getAttribute('limit');
$order = $this->getAttribute('order');
$sheet = $this->getAttribute('sheet');
$this->getParams['sheet'] = $sheet;
$this->getParams['limit'] = $limit;
if (!empty($order)) {
$this->getParams['order'] = $order;
}
if ((!$count || $count == 1)
&& $this->getAttribute('limit') === false
) {
return '';
}
$Engine->assign(array(
'this' => $this,
'count' => $count,
'start' => $start,
'end' => $end,
'active' => $active,
'pathParams' => $this->urlParams,
'getParams' => $this->getParams,
'anchor' => $anchor,
'limit' => $limit,
'limits' => $limits,
'Site' => $Site,
'Project' => $Project
));
return $Engine->fetch(dirname(__FILE__) . '/Pagination.html');
}
/**
* Load the GET request variables into the sheet
*/
public function loadFromRequest()
{
$limit = $this->getAttribute('limit');
$order = $this->getAttribute('order');
$sheet = $this->getAttribute('sheet');
if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
$limit = (int)$_GET['limit'];
}
if (isset($_GET['order'])) {
$order = $_GET['order'];
}
if (isset($_GET['sheet'])) {
$sheet = $_GET['sheet'];
}
$this->setAttribute('limit', $limit);
$this->setAttribute('order', $order);
$this->setAttribute('sheet', $sheet);
$this->urlParams = QUI::getRewrite()->getUrlParamsList();
}
/**
* Return SQL params
*
* @example $this->getSQLParams() : array(
* 'limit' => '0,20',
* 'order' => 'field'
* )
*
* @return array
*/
public function getSQLParams()
{
$result = array();
if ($this->getAttribute('limit')) {
$result['limit'] = $this->getStart()
. ',' . $this->getAttribute('limit');
}
if ($this->getAttribute('order')) {
$result['order'] = $this->getAttribute('order');
}
return $result;
}
/**
* Return the start
*
* @return integer
*/
public function getStart()
{
$limit = $this->getAttribute('limit');
$sheet = $this->getAttribute('sheet');
return ($sheet - 1) * $limit;
}
/**
* Set GET parameter to the links
*
* @param $name
* @param $value
*/
public function setGetParams($name, $value)
{
$name = QUI\Utils\Security\Orthos::clear($name);
$value = QUI\Utils\Security\Orthos::clearFormRequest($value);
if (empty($value)) {
if (isset($this->getParams[$name])) {
unset($this->getParams[$name]);
}
return;
}
$this->getParams[$name] = urlencode($value);
}
/**
* Set URL parameter to the links
*
* @param $name
* @param $value
*/
public function setUrlParams($name, $value)
{
$name = QUI\Utils\Security\Orthos::clear($name);
$value = QUI\Utils\Security\Orthos::clear($value);
if (empty($value)) {
if (isset($this->urlParams[$name])) {
unset($this->urlParams[$name]);
}
return;
}
$this->urlParams[$name] = $value;
}
}
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren