mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 13:09:21 +03:00
Add pagenator to contact list
Move contacts from plugin back to core
This commit is contained in:
parent
daa958ed44
commit
0ec4fc89d4
44 changed files with 1250 additions and 889 deletions
|
|
@ -10,6 +10,12 @@ Consts.DataImages = {};
|
|||
*/
|
||||
Consts.Defaults.MessagesPerPage = 20;
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
*/
|
||||
Consts.Defaults.ContactsPerPage = 20;
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Array}
|
||||
|
|
|
|||
|
|
@ -1342,3 +1342,117 @@ Utils.resizeAndCrop = function (sUrl, iValue, fCallback)
|
|||
|
||||
oTempImg.src = sUrl;
|
||||
};
|
||||
|
||||
Utils.computedPagenatorHelper = function (koCurrentPage, koPageCount) {
|
||||
|
||||
return function() {
|
||||
var
|
||||
iPrev = 0,
|
||||
iNext = 0,
|
||||
iLimit = 2,
|
||||
aResult = [],
|
||||
iCurrentPage = koCurrentPage(),
|
||||
iPageCount = koPageCount(),
|
||||
|
||||
/**
|
||||
* @param {number} iIndex
|
||||
* @param {boolean=} bPush
|
||||
* @param {string=} sCustomName
|
||||
*/
|
||||
fAdd = function (iIndex, bPush, sCustomName) {
|
||||
|
||||
var oData = {
|
||||
'current': iIndex === iCurrentPage,
|
||||
'name': Utils.isUnd(sCustomName) ? iIndex.toString() : sCustomName.toString(),
|
||||
'custom': Utils.isUnd(sCustomName) ? false : true,
|
||||
'title': Utils.isUnd(sCustomName) ? '' : iIndex.toString(),
|
||||
'value': iIndex.toString()
|
||||
};
|
||||
|
||||
if (Utils.isUnd(bPush) ? true : !!bPush)
|
||||
{
|
||||
aResult.push(oData);
|
||||
}
|
||||
else
|
||||
{
|
||||
aResult.unshift(oData);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
if (1 < iPageCount || (0 < iPageCount && iPageCount < iCurrentPage))
|
||||
// if (0 < iPageCount && 0 < iCurrentPage)
|
||||
{
|
||||
if (iPageCount < iCurrentPage)
|
||||
{
|
||||
fAdd(iPageCount);
|
||||
iPrev = iPageCount;
|
||||
iNext = iPageCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (3 >= iCurrentPage || iPageCount - 2 <= iCurrentPage)
|
||||
{
|
||||
iLimit += 2;
|
||||
}
|
||||
|
||||
fAdd(iCurrentPage);
|
||||
iPrev = iCurrentPage;
|
||||
iNext = iCurrentPage;
|
||||
}
|
||||
|
||||
while (0 < iLimit) {
|
||||
|
||||
iPrev -= 1;
|
||||
iNext += 1;
|
||||
|
||||
if (0 < iPrev)
|
||||
{
|
||||
fAdd(iPrev, false);
|
||||
iLimit--;
|
||||
}
|
||||
|
||||
if (iPageCount >= iNext)
|
||||
{
|
||||
fAdd(iNext, true);
|
||||
iLimit--;
|
||||
}
|
||||
else if (0 >= iPrev)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (3 === iPrev)
|
||||
{
|
||||
fAdd(2, false);
|
||||
}
|
||||
else if (3 < iPrev)
|
||||
{
|
||||
fAdd(Math.round((iPrev - 1) / 2), false, '...');
|
||||
}
|
||||
|
||||
if (iPageCount - 2 === iNext)
|
||||
{
|
||||
fAdd(iPageCount - 1, true);
|
||||
}
|
||||
else if (iPageCount - 2 > iNext)
|
||||
{
|
||||
fAdd(Math.round((iPageCount + iNext) / 2), true, '...');
|
||||
}
|
||||
|
||||
// first and last
|
||||
if (1 < iPrev)
|
||||
{
|
||||
fAdd(1, false);
|
||||
}
|
||||
|
||||
if (iPageCount > iNext)
|
||||
{
|
||||
fAdd(iPageCount, true);
|
||||
}
|
||||
}
|
||||
|
||||
return aResult;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue