mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-11 00:14:50 +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
|
|
@ -56,118 +56,7 @@ function MailBoxMessageListViewModel()
|
|||
return '' === sValue ? '' : Utils.i18n('MESSAGE_LIST/SEARCH_RESULT_FOR', {'SEARCH': sValue});
|
||||
});
|
||||
|
||||
this.messageListPagenator = ko.computed(function () {
|
||||
|
||||
var
|
||||
iPrev = 0,
|
||||
iNext = 0,
|
||||
iLimit = 2,
|
||||
aResult = [],
|
||||
iCurrentPage = oData.messageListPage(),
|
||||
iPageCount = oData.messageListPageCount(),
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
}, this);
|
||||
this.messageListPagenator = ko.computed(Utils.computedPagenatorHelper(oData.messageListPage, oData.messageListPageCount));
|
||||
|
||||
this.checkAll = ko.computed({
|
||||
'read': function () {
|
||||
|
|
@ -804,7 +693,7 @@ MailBoxMessageListViewModel.prototype.onBuild = function (oDom)
|
|||
});
|
||||
|
||||
oDom
|
||||
.on('click', '.pagenator .page', function () {
|
||||
.on('click', '.e-pagenator .e-page', function () {
|
||||
var oPage = ko.dataFor(this);
|
||||
if (oPage)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,10 +25,19 @@ function PopupsContactsViewModel()
|
|||
;
|
||||
|
||||
this.search = ko.observable('');
|
||||
this.contactsCount = ko.observable(0);
|
||||
this.contacts = ko.observableArray([]);
|
||||
this.contacts.loading = ko.observable(false).extend({'throttle': 200});
|
||||
this.currentContact = ko.observable(null);
|
||||
|
||||
this.contactsPage = ko.observable(1);
|
||||
this.contactsPageCount = ko.computed(function () {
|
||||
var iPage = Math.ceil(this.contactsCount() / Consts.Defaults.ContactsPerPage);
|
||||
return 0 >= iPage ? 1 : iPage;
|
||||
}, this);
|
||||
|
||||
this.contactsPagenator = ko.computed(Utils.computedPagenatorHelper(this.contactsPage, this.contactsPageCount));
|
||||
|
||||
this.emptySelection = ko.observable(true);
|
||||
this.viewClearSearch = ko.observable(false);
|
||||
|
||||
|
|
@ -225,28 +234,24 @@ function PopupsContactsViewModel()
|
|||
var bV = this.viewHasNonEmptyRequaredProperties();
|
||||
return !this.viewSaving() && bV;
|
||||
});
|
||||
|
||||
this.bDropPageAfterDelete = false;
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('PopupsContactsViewModel', PopupsContactsViewModel);
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewEmail = function ()
|
||||
{
|
||||
// if (0 === this.viewPropertiesEmailsEmpty().length)
|
||||
// {
|
||||
var oItem = new ContactPropertyModel(Enums.ContactPropertyType.EmailPersonal, '');
|
||||
oItem.focused(true);
|
||||
this.viewProperties.push(oItem);
|
||||
// }
|
||||
var oItem = new ContactPropertyModel(Enums.ContactPropertyType.EmailPersonal, '');
|
||||
oItem.focused(true);
|
||||
this.viewProperties.push(oItem);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.addNewPhone = function ()
|
||||
{
|
||||
// if (0 === this.viewPropertiesPhonesEmpty().length)
|
||||
// {
|
||||
var oItem = new ContactPropertyModel(Enums.ContactPropertyType.PhonePersonal, '');
|
||||
oItem.focused(true);
|
||||
this.viewProperties.push(oItem);
|
||||
// }
|
||||
var oItem = new ContactPropertyModel(Enums.ContactPropertyType.PhonePersonal, '');
|
||||
oItem.focused(true);
|
||||
this.viewProperties.push(oItem);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.removeCheckedOrSelectedContactsFromList = function ()
|
||||
|
|
@ -255,6 +260,7 @@ PopupsContactsViewModel.prototype.removeCheckedOrSelectedContactsFromList = func
|
|||
self = this,
|
||||
oKoContacts = this.contacts,
|
||||
oCurrentContact = this.currentContact(),
|
||||
iCount = this.contacts().length,
|
||||
aContacts = this.contactsCheckedOrSelected()
|
||||
;
|
||||
|
||||
|
|
@ -269,8 +275,14 @@ PopupsContactsViewModel.prototype.removeCheckedOrSelectedContactsFromList = func
|
|||
}
|
||||
|
||||
oContact.deleted(true);
|
||||
iCount--;
|
||||
});
|
||||
|
||||
if (iCount <= 0)
|
||||
{
|
||||
this.bDropPageAfterDelete = true;
|
||||
}
|
||||
|
||||
_.delay(function () {
|
||||
|
||||
_.each(aContacts, function (oContact) {
|
||||
|
|
@ -302,13 +314,13 @@ PopupsContactsViewModel.prototype.deleteResponse = function (sResult, oData)
|
|||
{
|
||||
if (500 < (Enums.StorageResultType.Success === sResult && oData && oData.Time ? Utils.pInt(oData.Time) : 0))
|
||||
{
|
||||
this.reloadContactList();
|
||||
this.reloadContactList(this.bDropPageAfterDelete);
|
||||
}
|
||||
else
|
||||
{
|
||||
_.delay((function (self) {
|
||||
return function () {
|
||||
self.reloadContactList();
|
||||
self.reloadContactList(self.bDropPageAfterDelete);
|
||||
};
|
||||
}(this)), 500);
|
||||
}
|
||||
|
|
@ -361,12 +373,31 @@ PopupsContactsViewModel.prototype.populateViewContact = function (oContact)
|
|||
this.viewProperties(aList);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.reloadContactList = function ()
|
||||
/**
|
||||
* @param {boolean=} bDropPagePosition = false
|
||||
*/
|
||||
PopupsContactsViewModel.prototype.reloadContactList = function (bDropPagePosition)
|
||||
{
|
||||
var self = this;
|
||||
var
|
||||
self = this,
|
||||
iOffset = (this.contactsPage() - 1) * Consts.Defaults.ContactsPerPage
|
||||
;
|
||||
|
||||
this.bDropPageAfterDelete = false;
|
||||
|
||||
if (Utils.isUnd(bDropPagePosition) ? false : !!bDropPagePosition)
|
||||
{
|
||||
this.contactsPage(1);
|
||||
iOffset = 0;
|
||||
}
|
||||
|
||||
this.contacts.loading(true);
|
||||
RL.remote().contacts(function (sResult, oData) {
|
||||
var aList = [];
|
||||
var
|
||||
iCount = 0,
|
||||
aList = []
|
||||
;
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result && oData.Result.List)
|
||||
{
|
||||
if (Utils.isNonEmptyArray(oData.Result.List))
|
||||
|
|
@ -377,9 +408,14 @@ PopupsContactsViewModel.prototype.reloadContactList = function ()
|
|||
});
|
||||
|
||||
aList = _.compact(aList);
|
||||
|
||||
iCount = Utils.pInt(oData.Result.Count);
|
||||
iCount = 0 < iCount ? iCount : 0;
|
||||
}
|
||||
}
|
||||
|
||||
self.contactsCount(iCount);
|
||||
|
||||
self.contacts(aList);
|
||||
self.viewClearSearch('' !== self.search());
|
||||
self.contacts.loading(false);
|
||||
|
|
@ -389,7 +425,7 @@ PopupsContactsViewModel.prototype.reloadContactList = function ()
|
|||
self.contacts.setSelectedByUid('' + self.viewID());
|
||||
}
|
||||
|
||||
}, 0, 20, this.search());
|
||||
}, iOffset, Consts.Defaults.ContactsPerPage, this.search());
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
||||
|
|
@ -399,6 +435,8 @@ PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
|||
|
||||
this.selector.init(this.oContentVisible, this.oContentScrollable);
|
||||
|
||||
var self = this;
|
||||
|
||||
ko.computed(function () {
|
||||
var
|
||||
bModalVisibility = this.modalVisibility(),
|
||||
|
|
@ -406,12 +444,23 @@ PopupsContactsViewModel.prototype.onBuild = function (oDom)
|
|||
;
|
||||
this.selector.useKeyboard(bModalVisibility && bUseKeyboardShortcuts);
|
||||
}, this).extend({'notify': 'always'});
|
||||
|
||||
oDom
|
||||
.on('click', '.e-pagenator .e-page', function () {
|
||||
var oPage = ko.dataFor(this);
|
||||
if (oPage)
|
||||
{
|
||||
self.contactsPage(Utils.pInt(oPage.value));
|
||||
self.reloadContactList();
|
||||
}
|
||||
})
|
||||
;
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.onShow = function ()
|
||||
{
|
||||
kn.routeOff();
|
||||
this.reloadContactList();
|
||||
this.reloadContactList(true);
|
||||
};
|
||||
|
||||
PopupsContactsViewModel.prototype.onHide = function ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue