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

pagination -> package/quiqqer/bricks/bin/Controls/Pagination -> useAjax

Übergeordneter f5327747
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
/**
* Ajax pagination
*
* @module package/quiqqer/bricks/bin/Controls/Pagination
* @author www.pcsg.de (Henning Leutz)
*
* @require qui/QUI
* @require qui/controls/Control
* @require qui/utils/String
*/
define('package/quiqqer/bricks/bin/Controls/Pagination', [
'qui/QUI',
'qui/controls/Control'
'qui/controls/Control',
'qui/utils/String'
], function(QUI, QUIControl)
], function(QUI, QUIControl, QUIStringUtils)
{
"use strict";
......@@ -17,15 +25,24 @@ define('package/quiqqer/bricks/bin/Controls/Pagination', [
Type : 'package/quiqqer/bricks/bin/Controls/Pagination',
Binds : [
'$onImport'
'$onImport',
'$onMouseOver'
],
initialize : function(options)
{
this.parent(options);
this.$Current = null;
this.$Prev = null;
this.$Next = null;
this.$First = null;
this.$Last = null;
this.$sheets = [];
this.addEvents({
onInsert : this.$onImport
onImport : this.$onImport
});
},
......@@ -34,8 +51,164 @@ define('package/quiqqer/bricks/bin/Controls/Pagination', [
*/
$onImport : function()
{
console.log(this.$Elm);
}
this.$First = this.$Elm.getElement('.quiqqer-sheets-first');
this.$Prev = this.$Elm.getElement('.quiqqer-sheets-prev');
this.$Last = this.$Elm.getElement('.quiqqer-sheets-last');
this.$Next = this.$Elm.getElement('.quiqqer-sheets-next');
this.$Current = this.$Elm.getElement('.quiqqer-sheets-desktop-current');
this.$sheets = this.$Elm.getElements('.quiqqer-sheets-sheet');
this.$registerEvents();
this.first();
},
/**
* register all js events
*/
$registerEvents : function()
{
var self = this,
aElms = this.$Elm.getElements('a');
aElms.addEvent('click', function(event) {
event.stop();
if (this.hasClass('quiqqer-sheets-first')) {
self.first();
} else if (this.hasClass('quiqqer-sheets-last')) {
self.last();
} else if (this.hasClass('quiqqer-sheets-prev')) {
self.prev();
} else if (this.hasClass('quiqqer-sheets-next')) {
self.next();
} else {
self.openPage(parseInt(this.get('data-page')-1));
}
});
},
/**
* Open page number and trigger the change event when it is necessary
*
* @param {Number} no - page number
* @fire change [this, Sheet, query]
*/
openPage : function(no)
{
if (typeof this.$sheets[no] === 'undefined') {
return;
}
var Sheet = this.$sheets[no];
var query = QUIStringUtils.getUrlParams(Sheet.search);
if (this.$Current === Sheet) {
return;
}
this.setPage(no);
this.fireEvent('change', [this, Sheet, query]);
},
/**
* Open page number and does not trigger the change event
*
* @param {Number} no - page number
*/
setPage : function(no)
{
if (typeof this.$sheets[no] === 'undefined') {
return;
}
var Sheet = this.$sheets[no];
if (this.$Current === Sheet) {
return;
}
if (this.$Current) {
this.$Current.removeClass('quiqqer-sheets-desktop-current');
}
this.$Current = Sheet;
this.$Current.addClass('quiqqer-sheets-desktop-current');
this.$First.removeClass('quiqqer-sheets-desktop-disabled');
this.$Prev.removeClass('quiqqer-sheets-desktop-disabled');
this.$Last.removeClass('quiqqer-sheets-desktop-disabled');
this.$Next.removeClass('quiqqer-sheets-desktop-disabled');
if (no === 0) {
// disable first and prev
this.$First.addClass('quiqqer-sheets-desktop-disabled');
this.$Prev.addClass('quiqqer-sheets-desktop-disabled');
} else if (no >= this.$sheets.length-1) {
// disable last and next
this.$Last.addClass('quiqqer-sheets-desktop-disabled');
this.$Next.addClass('quiqqer-sheets-desktop-disabled');
}
},
/**
* Go to the next page
*/
next : function()
{
if (!this.$Current) {
this.first();
return;
}
var currentPage = this.$Current.get('data-page');
if (currentPage < this.$sheets.length) {
this.openPage(currentPage);
}
},
/**
* Go to the previous page
*/
prev : function()
{
if (!this.$Current) {
this.first();
return;
}
var currentPage = this.$Current.get('data-page');
if (currentPage-2) {
this.openPage(currentPage-2);
return;
}
this.first();
},
/**
* Go to the first page
*/
first : function()
{
this.openPage(0);
},
/**
* Go to the last page
*/
last : function()
{
this.openPage(this.$sheets.length-1);
}
});
});
\ No newline at end of file
});
......@@ -20,21 +20,25 @@
</div>
<div class="quiqqer-sheets-desktop hide-on-mobile">
{if !isset($smarty.request.sheet) || $active == 1}
<span class="quiqqer-sheets-desktop-disabled fa fa-angle-double-left"
{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"
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}
<span class="quiqqer-sheets-desktop-disabled fa fa-angle-left"
{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}
......@@ -42,13 +46,13 @@
{if $backward == 1}
{$getParams['limit'] = $limit}
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
class="fa fa-angle-left"
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"
class="fa fa-angle-left quiqqer-sheets-prev"
title="{t}quiqqer/bricks controls.pagination.back{/t}">
</a>
{/if}
......@@ -61,16 +65,26 @@
{section name=sheets start=$start loop=$end+1}
{assign var=num value=$smarty.section.sheets.index}
{if $num == $active}
{if $num == $active && $this->getAttribute('useAjax') === false}
<span class="quiqqer-sheets-desktop-current">{$num}</span>
{else}
{$getParams['limit'] = $limit}
{if $num == 1}
{$getParams['sheet'] = false}
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}">{$num}</a>
<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}">{$num}</a>
<a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}"
class="quiqqer-sheets-sheet"
data-page="{$num}"
>
{$num}
</a>
{/if}
{/if}
{/section}
......@@ -80,8 +94,8 @@
<span class="more">...</span>
{/if}
{if $active >= $count}
<span class="quiqqer-sheets-desktop-disabled fa fa-angle-right"
{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>
......@@ -89,21 +103,21 @@
{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"
class="fa fa-angle-right quiqqer-sheets-next"
title="{t}quiqqer/bricks controls.pagination.next{/t}"
>
</a>
{/if}
{if $active >= $count}
<span class="quiqqer-sheets-desktop-disabled fa fa-angle-double-right"
{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"
class="fa fa-angle-double-right quiqqer-sheets-last"
></a>
{/if}
</div>
......
......@@ -42,7 +42,8 @@ public function __construct($attributes = array())
'limits' => '[10,20,50]',
'limit' => 10,
'order' => false,
'sheet' => 1
'sheet' => 1,
'useAjax' => false
));
parent::__construct($attributes);
......@@ -51,8 +52,17 @@ public function __construct($attributes = array())
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');
$this->setAttribute('data-qui', 'package/quiqqer/bricks/bin/Controls/Pagination');
}
/**
......@@ -68,11 +78,15 @@ public function getBody()
$count = $this->getAttribute('sheets');
$showmax = $this->getAttribute('showmax');
$limit = $this->getAttribute('limit');
$limits = $this->getAttribute('limits');
if ($this->getAttribute('showLimit') === false) {
$limit = false;
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)) {
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren