mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-01 08:16:03 +00:00
Uploading and preparing the repository to the dev version.
Original unminified source code (dev folder - js, css, less) (fixes #6) Grunt build system Multiple identities correction (fixes #9) Compose html editor (fixes #12) New general settings - Loading Description New warning about default admin password Split general and login screen settings
This commit is contained in:
935
dev/ViewModels/MailBoxMessageListViewModel.js
Normal file
935
dev/ViewModels/MailBoxMessageListViewModel.js
Normal file
@@ -0,0 +1,935 @@
|
||||
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends KnoinAbstractViewModel
|
||||
*/
|
||||
function MailBoxMessageListViewModel()
|
||||
{
|
||||
KnoinAbstractViewModel.call(this, 'Right', 'MailMessageList');
|
||||
|
||||
this.sLastUid = null;
|
||||
this.emptySubjectValue = '';
|
||||
|
||||
var oData = RL.data();
|
||||
|
||||
this.popupVisibility = RL.popupVisibility;
|
||||
|
||||
this.messageList = oData.messageList;
|
||||
this.currentMessage = oData.currentMessage;
|
||||
this.isMessageSelected = oData.isMessageSelected;
|
||||
this.messageListSearch = oData.messageListSearch;
|
||||
this.messageListError = oData.messageListError;
|
||||
this.folderMenuForMove = oData.folderMenuForMove;
|
||||
|
||||
this.useCheckboxesInList = oData.useCheckboxesInList;
|
||||
|
||||
this.mainMessageListSearch = oData.mainMessageListSearch;
|
||||
this.messageListEndFolder = oData.messageListEndFolder;
|
||||
|
||||
this.messageListChecked = oData.messageListChecked;
|
||||
this.messageListCheckedOrSelected = oData.messageListCheckedOrSelected;
|
||||
this.messageListCheckedOrSelectedUidsWithSubMails = oData.messageListCheckedOrSelectedUidsWithSubMails;
|
||||
this.messageListCompleteLoadingThrottle = oData.messageListCompleteLoadingThrottle;
|
||||
|
||||
Utils.initOnStartOrLangChange(function () {
|
||||
this.emptySubjectValue = Utils.i18n('MESSAGE_LIST/EMPTY_SUBJECT_TEXT');
|
||||
}, this);
|
||||
|
||||
this.userQuota = oData.userQuota;
|
||||
this.userUsageSize = oData.userUsageSize;
|
||||
this.userUsageProc = oData.userUsageProc;
|
||||
|
||||
// append drag and drop
|
||||
this.dragOver = ko.observable(false).extend({'throttle': 1});
|
||||
this.dragOverEnter = ko.observable(false).extend({'throttle': 1});
|
||||
this.dragOverArea = ko.observable(null);
|
||||
this.dragOverBodyArea = ko.observable(null);
|
||||
|
||||
this.messageListItemTemplate = ko.computed(function () {
|
||||
return oData.usePreviewPane() ?
|
||||
'MailMessageListItem' : 'MailMessageListItemNoPreviewPane';
|
||||
});
|
||||
|
||||
this.messageListSearchDesc = ko.computed(function () {
|
||||
var sValue = oData.messageListEndSearch();
|
||||
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.checkAll = ko.computed({
|
||||
'read': function () {
|
||||
return 0 < RL.data().messageListCheckedOrSelected().length;
|
||||
},
|
||||
|
||||
'write': function (bValue) {
|
||||
bValue = !!bValue;
|
||||
_.each(RL.data().messageList(), function (oMessage) {
|
||||
oMessage.checked(bValue);
|
||||
});
|
||||
|
||||
if (!bValue)
|
||||
{
|
||||
RL.data().message(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.inputMessageListSearchFocus = ko.observable(false);
|
||||
|
||||
this.sLastSearchValue = '';
|
||||
this.inputProxyMessageListSearch = ko.computed({
|
||||
'read': this.mainMessageListSearch,
|
||||
'write': function (sValue) {
|
||||
this.sLastSearchValue = sValue;
|
||||
},
|
||||
'owner': this
|
||||
});
|
||||
|
||||
this.isIncompleteChecked = ko.computed(function () {
|
||||
var
|
||||
iM = RL.data().messageList().length,
|
||||
iC = RL.data().messageListCheckedOrSelected().length
|
||||
;
|
||||
return 0 < iM && 0 < iC && iM > iC;
|
||||
}, this);
|
||||
|
||||
this.hasMessages = ko.computed(function () {
|
||||
return 0 < this.messageList().length;
|
||||
}, this);
|
||||
|
||||
this.hasCheckedLines = ko.computed(function () {
|
||||
return 0 < this.messageListChecked().length;
|
||||
}, this);
|
||||
|
||||
this.hasCheckedOrSelectedLines = ko.computed(function () {
|
||||
return 0 < this.messageListCheckedOrSelected().length;
|
||||
}, this);
|
||||
|
||||
this.isSpamFolder = ko.computed(function () {
|
||||
return RL.data().spamFolder() === this.messageListEndFolder();
|
||||
}, this);
|
||||
|
||||
this.isTrashFolder = ko.computed(function () {
|
||||
return RL.data().trashFolder() === this.messageListEndFolder();
|
||||
}, this);
|
||||
|
||||
this.canBeMoved = this.hasCheckedOrSelectedLines;
|
||||
|
||||
this.clearCommand = Utils.createCommand(this, function () {
|
||||
kn.showScreenPopup(PopupsFolderClearViewModel, [RL.data().currentFolder()]);
|
||||
});
|
||||
|
||||
this.multyForwardCommand = Utils.createCommand(this, function () {
|
||||
kn.showScreenPopup(PopupsComposeViewModel, [Enums.ComposeType.ForwardAsAttachment, RL.data().messageListCheckedOrSelected()]);
|
||||
}, this.canBeMoved);
|
||||
|
||||
this.deleteWithoutMoveCommand = Utils.createCommand(this, function () {
|
||||
this.deleteSelectedMessageFromCurrentFolder(Enums.FolderType.Trash, false);
|
||||
}, this.canBeMoved);
|
||||
|
||||
this.deleteCommand = Utils.createCommand(this, function () {
|
||||
this.deleteSelectedMessageFromCurrentFolder(Enums.FolderType.Trash, true);
|
||||
}, this.canBeMoved);
|
||||
|
||||
this.spamCommand = Utils.createCommand(this, function () {
|
||||
this.deleteSelectedMessageFromCurrentFolder(Enums.FolderType.Spam, true);
|
||||
}, this.canBeMoved);
|
||||
|
||||
this.moveCommand = Utils.createCommand(this, Utils.emptyFunction, this.canBeMoved);
|
||||
|
||||
this.setCommand = Utils.createCommand(this, Utils.emptyFunction, this.hasCheckedLines);
|
||||
|
||||
this.checkCommand = Utils.createCommand(this, Utils.emptyFunction, this.hasCheckedLines);
|
||||
|
||||
this.reloadCommand = Utils.createCommand(this, function () {
|
||||
if (!RL.data().messageListCompleteLoadingThrottle())
|
||||
{
|
||||
RL.reloadMessageList(false, true);
|
||||
}
|
||||
});
|
||||
|
||||
this.quotaTooltip = _.bind(this.quotaTooltip, this);
|
||||
|
||||
this.selector = new Selector(this.messageList, this.currentMessage,
|
||||
'.messageListItem .actionHandle', '.messageListItem.selected', '.messageListItem .checkboxMessage');
|
||||
|
||||
this.selector.on('onItemSelect', _.bind(function (oMessage) {
|
||||
if (oMessage)
|
||||
{
|
||||
oData.message(oData.staticMessageList.populateByMessageListItem(oMessage));
|
||||
this.populateMessageBody(oData.message());
|
||||
}
|
||||
else
|
||||
{
|
||||
oData.message(null);
|
||||
}
|
||||
}, this));
|
||||
|
||||
this.selector.on('onItemGetUid', function (oMessage) {
|
||||
return oMessage ? oMessage.generateUid() : '';
|
||||
});
|
||||
|
||||
this.selector.on('onDelete', _.bind(function () {
|
||||
if (0 < RL.data().messageListCheckedOrSelected().length)
|
||||
{
|
||||
this.deleteCommand();
|
||||
}
|
||||
}, this));
|
||||
}
|
||||
|
||||
Utils.extendAsViewModel('MailBoxMessageListViewModel', MailBoxMessageListViewModel);
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.emptySubjectValue = '';
|
||||
|
||||
MailBoxMessageListViewModel.prototype.searchEnterAction = function ()
|
||||
{
|
||||
this.mainMessageListSearch(this.sLastSearchValue);
|
||||
this.inputMessageListSearchFocus(false);
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.cancelSearch = function ()
|
||||
{
|
||||
this.mainMessageListSearch('');
|
||||
this.inputMessageListSearchFocus(false);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sFromFolderFullNameRaw
|
||||
* @param {Array} aUidForRemove
|
||||
* @param {string=} sToFolderFullNameRaw
|
||||
* @param {boolean=} bVisialEffectOnly = false
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.removeMessagesFromList = function (sFromFolderFullNameRaw, aUidForRemove, sToFolderFullNameRaw, bVisialEffectOnly)
|
||||
{
|
||||
sToFolderFullNameRaw = Utils.isNormal(sToFolderFullNameRaw) ? sToFolderFullNameRaw : '';
|
||||
bVisialEffectOnly = Utils.isUnd(bVisialEffectOnly) ? false : !!bVisialEffectOnly;
|
||||
|
||||
var
|
||||
iUnseenCount = 0 ,
|
||||
oData = RL.data(),
|
||||
oFromFolder = RL.cache().getFolderFromCacheList(sFromFolderFullNameRaw),
|
||||
oToFolder = '' === sToFolderFullNameRaw ? null : RL.cache().getFolderFromCacheList(sToFolderFullNameRaw || ''),
|
||||
sCurrentFolderFullNameRaw = oData.currentFolderFullNameRaw(),
|
||||
oCurrentMessage = oData.message(),
|
||||
aMessages = sCurrentFolderFullNameRaw === sFromFolderFullNameRaw ? _.filter(oData.messageList(), function (oMessage) {
|
||||
return oMessage && -1 < Utils.inArray(oMessage.uid, aUidForRemove);
|
||||
}) : []
|
||||
;
|
||||
|
||||
if (!bVisialEffectOnly)
|
||||
{
|
||||
_.each(aMessages, function (oMessage) {
|
||||
if (oMessage && oMessage.unseen())
|
||||
{
|
||||
iUnseenCount++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (oFromFolder && !bVisialEffectOnly)
|
||||
{
|
||||
oFromFolder.messageCountAll(0 <= oFromFolder.messageCountAll() - aUidForRemove.length ?
|
||||
oFromFolder.messageCountAll() - aUidForRemove.length : 0);
|
||||
|
||||
if (0 < iUnseenCount)
|
||||
{
|
||||
oFromFolder.messageCountUnread(0 <= oFromFolder.messageCountUnread() - iUnseenCount ?
|
||||
oFromFolder.messageCountUnread() - iUnseenCount : 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (oToFolder && !bVisialEffectOnly)
|
||||
{
|
||||
oToFolder.messageCountAll(oToFolder.messageCountAll() + aUidForRemove.length);
|
||||
if (0 < iUnseenCount)
|
||||
{
|
||||
oToFolder.messageCountUnread(oToFolder.messageCountUnread() + iUnseenCount);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < aMessages.length)
|
||||
{
|
||||
_.each(aMessages, function (oMessage) {
|
||||
if (oCurrentMessage && oCurrentMessage.requestHash === oMessage.requestHash)
|
||||
{
|
||||
oCurrentMessage = null;
|
||||
oData.message(null);
|
||||
}
|
||||
|
||||
oMessage.deleted(true);
|
||||
});
|
||||
|
||||
_.delay(function () {
|
||||
_.each(aMessages, function (oMessage) {
|
||||
oData.messageList.remove(oMessage);
|
||||
});
|
||||
}, 400);
|
||||
|
||||
if (!bVisialEffectOnly)
|
||||
{
|
||||
RL.data().messageListIsNotCompleted(true);
|
||||
RL.cache().setFolderHash(sFromFolderFullNameRaw, '');
|
||||
|
||||
if (Utils.isNormal(sToFolderFullNameRaw))
|
||||
{
|
||||
RL.cache().setFolderHash(sToFolderFullNameRaw || '', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string=} sToFolderFullNameRaw
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.removeCheckedOrSelectedMessagesFromList = function (sToFolderFullNameRaw)
|
||||
{
|
||||
this.removeMessagesFromList(RL.data().currentFolderFullNameRaw(), _.map(RL.data().messageListCheckedOrSelected(), function (oMessage) {
|
||||
return oMessage.uid;
|
||||
}), sToFolderFullNameRaw);
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.moveOrDeleteResponse = function (sResult, oData)
|
||||
{
|
||||
if (Enums.StorageResultType.Success === sResult && RL.data().currentFolder())
|
||||
{
|
||||
if (oData && Utils.isArray(oData.Result) && 2 === oData.Result.length)
|
||||
{
|
||||
RL.cache().setFolderHash(oData.Result[0], oData.Result[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oData && Enums.Notification.CantMoveMessage === oData.ErrorCode)
|
||||
{
|
||||
window.alert(Utils.getNotification(Enums.Notification.CantMoveMessage));
|
||||
}
|
||||
|
||||
RL.cache().setFolderHash(RL.data().currentFolderFullNameRaw(), '');
|
||||
}
|
||||
|
||||
RL.reloadMessageList();
|
||||
|
||||
RL.quotaDebounce();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sFromFolderFullNameRaw
|
||||
* @param {Array} aUidForRemove
|
||||
* @param {string} sToFolderFullNameRaw
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.moveMessagesToFolder = function (sFromFolderFullNameRaw, aUidForRemove, sToFolderFullNameRaw)
|
||||
{
|
||||
if (sFromFolderFullNameRaw !== sToFolderFullNameRaw && Utils.isArray(aUidForRemove) && 0 < aUidForRemove.length)
|
||||
{
|
||||
var
|
||||
oFromFolder = RL.cache().getFolderFromCacheList(sFromFolderFullNameRaw),
|
||||
oToFolder = RL.cache().getFolderFromCacheList(sToFolderFullNameRaw)
|
||||
;
|
||||
|
||||
if (oFromFolder && oToFolder)
|
||||
{
|
||||
RL.remote().messagesMove(
|
||||
_.bind(this.moveOrDeleteResponse, this),
|
||||
oFromFolder.fullNameRaw,
|
||||
oToFolder.fullNameRaw,
|
||||
aUidForRemove
|
||||
);
|
||||
|
||||
oToFolder.actionBlink(true);
|
||||
|
||||
this.removeMessagesFromList(sFromFolderFullNameRaw, aUidForRemove, sToFolderFullNameRaw);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sToFolderFullNameRaw
|
||||
* @return {boolean}
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.moveSelectedMessagesToFolder = function (sToFolderFullNameRaw)
|
||||
{
|
||||
if (this.canBeMoved())
|
||||
{
|
||||
return this.moveMessagesToFolder(RL.data().currentFolderFullNameRaw(),
|
||||
RL.data().messageListCheckedOrSelectedUidsWithSubMails(), sToFolderFullNameRaw);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} iType
|
||||
* @param {boolean=} bUseFolder = true
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.deleteSelectedMessageFromCurrentFolder = function (iType, bUseFolder)
|
||||
{
|
||||
if (this.canBeMoved())
|
||||
{
|
||||
bUseFolder = Utils.isUnd(bUseFolder) ? true : !!bUseFolder;
|
||||
var oTrashOrSpamFolder = RL.cache().getFolderFromCacheList(
|
||||
Enums.FolderType.Spam === iType ? RL.data().spamFolder() : RL.data().trashFolder());
|
||||
|
||||
if (!oTrashOrSpamFolder && bUseFolder)
|
||||
{
|
||||
kn.showScreenPopup(PopupsFolderSystemViewModel, [
|
||||
Enums.FolderType.Spam === iType ? Enums.SetSystemFoldersNotification.Spam : Enums.SetSystemFoldersNotification.Trash]);
|
||||
}
|
||||
else if (!bUseFolder || (oTrashOrSpamFolder && (Consts.Values.UnuseOptionValue === oTrashOrSpamFolder.fullNameRaw ||
|
||||
RL.data().currentFolderFullNameRaw() === oTrashOrSpamFolder.fullNameRaw)))
|
||||
{
|
||||
RL.remote().messagesDelete(
|
||||
_.bind(this.moveOrDeleteResponse, this),
|
||||
RL.data().currentFolderFullNameRaw(),
|
||||
RL.data().messageListCheckedOrSelectedUidsWithSubMails()
|
||||
);
|
||||
|
||||
this.removeCheckedOrSelectedMessagesFromList();
|
||||
}
|
||||
else if (oTrashOrSpamFolder)
|
||||
{
|
||||
RL.remote().messagesMove(
|
||||
_.bind(this.moveOrDeleteResponse, this),
|
||||
RL.data().currentFolderFullNameRaw(),
|
||||
oTrashOrSpamFolder.fullNameRaw,
|
||||
RL.data().messageListCheckedOrSelectedUidsWithSubMails()
|
||||
);
|
||||
|
||||
oTrashOrSpamFolder.actionBlink(true);
|
||||
this.removeCheckedOrSelectedMessagesFromList(oTrashOrSpamFolder.fullNameRaw);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.dragAndDronHelper = function (oMessageListItem)
|
||||
{
|
||||
if (oMessageListItem)
|
||||
{
|
||||
oMessageListItem.checked(true);
|
||||
}
|
||||
|
||||
var oEl = Utils.draggeblePlace();
|
||||
oEl.data('rl-folder', RL.data().currentFolderFullNameRaw());
|
||||
oEl.data('rl-uids', RL.data().messageListCheckedOrSelectedUidsWithSubMails());
|
||||
oEl.find('.text').text(RL.data().messageListCheckedOrSelectedUidsWithSubMails().length);
|
||||
|
||||
return oEl;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sResult
|
||||
* @param {AjaxJsonDefaultResponse} oData
|
||||
* @param {boolean} bCached
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.onMessageResponse = function (sResult, oData, bCached)
|
||||
{
|
||||
var oRainLoopData = RL.data();
|
||||
|
||||
oRainLoopData.messageLoading(false);
|
||||
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
|
||||
{
|
||||
oRainLoopData.setMessage(oData, bCached);
|
||||
}
|
||||
else if (Enums.StorageResultType.Unload === sResult)
|
||||
{
|
||||
oRainLoopData.message(null);
|
||||
oRainLoopData.messageError('');
|
||||
}
|
||||
else if (Enums.StorageResultType.Abort !== sResult)
|
||||
{
|
||||
oRainLoopData.message(null);
|
||||
oRainLoopData.messageError((oData && oData.ErrorCode ?
|
||||
Utils.getNotification(oData.ErrorCode) :
|
||||
Utils.getNotification(Enums.Notification.UnknownError)));
|
||||
}
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.populateMessageBody = function (oMessage)
|
||||
{
|
||||
if (oMessage)
|
||||
{
|
||||
if (RL.remote().message(this.onMessageResponse, oMessage.folderFullNameRaw, oMessage.uid))
|
||||
{
|
||||
RL.data().messageLoading(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.log('Error: Unknown message request: ' + oMessage.folderFullNameRaw + ' ~ ' + oMessage.uid + ' [e-101]');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sFolderFullNameRaw
|
||||
* @param {number} iSetAction
|
||||
* @param {Array=} aMessages = null
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.setAction = function (sFolderFullNameRaw, iSetAction, aMessages)
|
||||
{
|
||||
var
|
||||
aUids = [],
|
||||
oFolder = null,
|
||||
oCache = RL.cache(),
|
||||
iAlreadyUnread = 0
|
||||
;
|
||||
|
||||
if (Utils.isUnd(aMessages))
|
||||
{
|
||||
aMessages = RL.data().messageListChecked();
|
||||
}
|
||||
|
||||
aUids = _.map(aMessages, function (oMessage) {
|
||||
return oMessage.uid;
|
||||
});
|
||||
|
||||
if ('' !== sFolderFullNameRaw && 0 < aUids.length)
|
||||
{
|
||||
switch (iSetAction) {
|
||||
case Enums.MessageSetAction.SetSeen:
|
||||
_.each(aMessages, function (oMessage) {
|
||||
if (oMessage.unseen())
|
||||
{
|
||||
iAlreadyUnread++;
|
||||
}
|
||||
|
||||
oMessage.unseen(false);
|
||||
oCache.storeMessageFlagsToCache(oMessage);
|
||||
});
|
||||
|
||||
oFolder = oCache.getFolderFromCacheList(sFolderFullNameRaw);
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.messageCountUnread(oFolder.messageCountUnread() - iAlreadyUnread);
|
||||
}
|
||||
|
||||
RL.remote().messageSetSeen(Utils.emptyFunction, sFolderFullNameRaw, aUids, true);
|
||||
break;
|
||||
case Enums.MessageSetAction.UnsetSeen:
|
||||
_.each(aMessages, function (oMessage) {
|
||||
if (oMessage.unseen())
|
||||
{
|
||||
iAlreadyUnread++;
|
||||
}
|
||||
|
||||
oMessage.unseen(true);
|
||||
oCache.storeMessageFlagsToCache(oMessage);
|
||||
});
|
||||
|
||||
oFolder = oCache.getFolderFromCacheList(sFolderFullNameRaw);
|
||||
if (oFolder)
|
||||
{
|
||||
oFolder.messageCountUnread(oFolder.messageCountUnread() - iAlreadyUnread + aUids.length);
|
||||
}
|
||||
RL.remote().messageSetSeen(Utils.emptyFunction, sFolderFullNameRaw, aUids, false);
|
||||
break;
|
||||
case Enums.MessageSetAction.SetFlag:
|
||||
_.each(aMessages, function (oMessage) {
|
||||
oMessage.flagged(true);
|
||||
oCache.storeMessageFlagsToCache(oMessage);
|
||||
});
|
||||
RL.remote().messageSetFlagged(Utils.emptyFunction, sFolderFullNameRaw, aUids, true);
|
||||
break;
|
||||
case Enums.MessageSetAction.UnsetFlag:
|
||||
_.each(aMessages, function (oMessage) {
|
||||
oMessage.flagged(false);
|
||||
oCache.storeMessageFlagsToCache(oMessage);
|
||||
});
|
||||
RL.remote().messageSetFlagged(Utils.emptyFunction, sFolderFullNameRaw, aUids, false);
|
||||
break;
|
||||
}
|
||||
|
||||
RL.reloadFlagsCurrentMessageListAndMessageFromCache();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sFolderFullNameRaw
|
||||
* @param {number} iSetAction
|
||||
*/
|
||||
MailBoxMessageListViewModel.prototype.setActionForAll = function (sFolderFullNameRaw, iSetAction)
|
||||
{
|
||||
var
|
||||
oFolder = null,
|
||||
aMessages = RL.data().messageList(),
|
||||
oCache = RL.cache()
|
||||
;
|
||||
|
||||
if ('' !== sFolderFullNameRaw)
|
||||
{
|
||||
oFolder = oCache.getFolderFromCacheList(sFolderFullNameRaw);
|
||||
|
||||
if (oFolder)
|
||||
{
|
||||
switch (iSetAction) {
|
||||
case Enums.MessageSetAction.SetSeen:
|
||||
oFolder = oCache.getFolderFromCacheList(sFolderFullNameRaw);
|
||||
if (oFolder)
|
||||
{
|
||||
_.each(aMessages, function (oMessage) {
|
||||
oMessage.unseen(false);
|
||||
});
|
||||
|
||||
oFolder.messageCountUnread(0);
|
||||
oCache.clearMessageFlagsFromCacheByFolder(sFolderFullNameRaw);
|
||||
}
|
||||
|
||||
RL.remote().messageSetSeenToAll(Utils.emptyFunction, sFolderFullNameRaw, true);
|
||||
break;
|
||||
case Enums.MessageSetAction.UnsetSeen:
|
||||
oFolder = oCache.getFolderFromCacheList(sFolderFullNameRaw);
|
||||
if (oFolder)
|
||||
{
|
||||
_.each(aMessages, function (oMessage) {
|
||||
oMessage.unseen(true);
|
||||
});
|
||||
|
||||
oFolder.messageCountUnread(oFolder.messageCountAll());
|
||||
oCache.clearMessageFlagsFromCacheByFolder(sFolderFullNameRaw);
|
||||
}
|
||||
RL.remote().messageSetSeenToAll(Utils.emptyFunction, sFolderFullNameRaw, false);
|
||||
break;
|
||||
}
|
||||
|
||||
RL.reloadFlagsCurrentMessageListAndMessageFromCache();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.listSetSeen = function ()
|
||||
{
|
||||
this.setAction(RL.data().currentFolderFullNameRaw(), Enums.MessageSetAction.SetSeen, RL.data().messageListCheckedOrSelected());
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.listSetAllSeen = function ()
|
||||
{
|
||||
this.setActionForAll(RL.data().currentFolderFullNameRaw(), Enums.MessageSetAction.SetSeen);
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.listUnsetSeen = function ()
|
||||
{
|
||||
this.setAction(RL.data().currentFolderFullNameRaw(), Enums.MessageSetAction.UnsetSeen, RL.data().messageListCheckedOrSelected());
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.listSetFlags = function ()
|
||||
{
|
||||
this.setAction(RL.data().currentFolderFullNameRaw(), Enums.MessageSetAction.SetFlag, RL.data().messageListCheckedOrSelected());
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.listUnsetFlags = function ()
|
||||
{
|
||||
this.setAction(RL.data().currentFolderFullNameRaw(), Enums.MessageSetAction.UnsetFlag, RL.data().messageListCheckedOrSelected());
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.onBuild = function (oDom)
|
||||
{
|
||||
var
|
||||
self = this,
|
||||
oData = RL.data()
|
||||
;
|
||||
|
||||
this.oContentVisible = $('.b-content', oDom);
|
||||
this.oContentScrollable = $('.content', this.oContentVisible);
|
||||
|
||||
this.oContentVisible.on('click', '.fullThreadHandle', function () {
|
||||
var
|
||||
aList = [],
|
||||
oMessage = ko.dataFor(this)
|
||||
;
|
||||
|
||||
if (oMessage && !oMessage.lastInCollapsedThreadLoading())
|
||||
{
|
||||
RL.data().messageListThreadFolder(oMessage.folderFullNameRaw);
|
||||
|
||||
aList = RL.data().messageListThreadUids();
|
||||
|
||||
if (oMessage.lastInCollapsedThread())
|
||||
{
|
||||
aList.push(0 < oMessage.parentUid() ? oMessage.parentUid() : oMessage.uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
aList = _.without(aList, 0 < oMessage.parentUid() ? oMessage.parentUid() : oMessage.uid);
|
||||
}
|
||||
|
||||
RL.data().messageListThreadUids(_.uniq(aList));
|
||||
|
||||
oMessage.lastInCollapsedThreadLoading(true);
|
||||
oMessage.lastInCollapsedThread(!oMessage.lastInCollapsedThread());
|
||||
RL.reloadMessageList();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
this.selector.init(this.oContentVisible, this.oContentScrollable);
|
||||
|
||||
$document.on('keydown', function (oEvent) {
|
||||
|
||||
var
|
||||
bResult = true,
|
||||
iKeyCode = oEvent ? oEvent.keyCode : 0
|
||||
;
|
||||
|
||||
if (oEvent && self.viewModelVisibility() && oData.useKeyboardShortcuts() && !RL.popupVisibility() && !oData.messageFullScreenMode() && !Utils.inFocus())
|
||||
{
|
||||
if (oData.usePreviewPane() || (!oData.message() && (Enums.EventKeyCode.Delete === iKeyCode || Enums.EventKeyCode.A === iKeyCode)))
|
||||
{
|
||||
if (oEvent.ctrlKey && Enums.EventKeyCode.A === iKeyCode)
|
||||
{
|
||||
self.checkAll(!(self.checkAll() && !self.isIncompleteChecked()));
|
||||
bResult = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bResult;
|
||||
});
|
||||
|
||||
oDom
|
||||
.on('click', '.pagenator .page', function () {
|
||||
var oPage = ko.dataFor(this);
|
||||
if (oPage)
|
||||
{
|
||||
kn.setHash(RL.link().mailBox(
|
||||
oData.currentFolderFullNameHash(),
|
||||
oPage.value,
|
||||
oData.messageListSearch()
|
||||
));
|
||||
}
|
||||
})
|
||||
.on('click', '.messageList .checkboxCkeckAll', function () {
|
||||
self.checkAll(!self.checkAll());
|
||||
})
|
||||
.on('click', '.messageList .messageListItem .flagParent', function () {
|
||||
|
||||
var
|
||||
oMessage = ko.dataFor(this),
|
||||
aChecked = oData.messageListCheckedOrSelected(),
|
||||
aCheckedUids = []
|
||||
;
|
||||
|
||||
if (oMessage)
|
||||
{
|
||||
if (0 < aChecked.length)
|
||||
{
|
||||
aCheckedUids = _.map(aChecked, function (oMessage) {
|
||||
return oMessage.uid;
|
||||
});
|
||||
}
|
||||
|
||||
if (0 < aCheckedUids.length && -1 < Utils.inArray(oMessage.uid, aCheckedUids))
|
||||
{
|
||||
self.setAction(oMessage.folderFullNameRaw, oMessage.flagged() ?
|
||||
Enums.MessageSetAction.UnsetFlag : Enums.MessageSetAction.SetFlag, aChecked);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.setAction(oMessage.folderFullNameRaw, oMessage.flagged() ?
|
||||
Enums.MessageSetAction.UnsetFlag : Enums.MessageSetAction.SetFlag, [oMessage]);
|
||||
}
|
||||
}
|
||||
})
|
||||
;
|
||||
|
||||
ko.computed(function () {
|
||||
|
||||
var
|
||||
oData = RL.data(),
|
||||
bViewModelVisibility = this.viewModelVisibility(),
|
||||
bPopupVisibility = RL.popupVisibility(),
|
||||
bUseKeyboardShortcuts = oData.useKeyboardShortcuts(),
|
||||
bMessageFullScreenMode = oData.messageFullScreenMode()
|
||||
;
|
||||
|
||||
this.selector.useKeyboard(bViewModelVisibility && bUseKeyboardShortcuts && !bMessageFullScreenMode && !bPopupVisibility);
|
||||
|
||||
}, this).extend({'notify': 'always'});
|
||||
|
||||
this.initUploaderForAppend();
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.composeClick = function ()
|
||||
{
|
||||
kn.showScreenPopup(PopupsComposeViewModel);
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.advancedSearchClick = function ()
|
||||
{
|
||||
kn.showScreenPopup(PopupsAdvancedSearchViewModel);
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.quotaTooltip = function ()
|
||||
{
|
||||
return Utils.i18n('MESSAGE_LIST/QUOTA_SIZE', {
|
||||
'SIZE': Utils.friendlySize(this.userUsageSize()),
|
||||
'PROC': this.userUsageProc(),
|
||||
'LIMIT': Utils.friendlySize(this.userQuota())
|
||||
});
|
||||
};
|
||||
|
||||
MailBoxMessageListViewModel.prototype.initUploaderForAppend = function ()
|
||||
{
|
||||
if (!RL.settingsGet('AllowAppendMessage') || !this.dragOverArea())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var oJua = new Jua({
|
||||
'action': RL.link().append(),
|
||||
'name': 'AppendFile',
|
||||
'queueSize': 1,
|
||||
'multipleSizeLimit': 1,
|
||||
'disableFolderDragAndDrop': true,
|
||||
'hidden': {
|
||||
'Folder': function () {
|
||||
return RL.data().currentFolderFullNameRaw();
|
||||
}
|
||||
},
|
||||
'dragAndDropElement': this.dragOverArea(),
|
||||
'dragAndDropBodyElement': this.dragOverBodyArea(),
|
||||
'onDragEnter': _.bind(function () {
|
||||
this.dragOverEnter(true);
|
||||
}, this),
|
||||
'onDragLeave': _.bind(function () {
|
||||
this.dragOverEnter(false);
|
||||
}, this),
|
||||
'onBodyDragEnter': _.bind(function () {
|
||||
this.dragOver(true);
|
||||
}, this),
|
||||
'onBodyDragLeave': _.bind(function () {
|
||||
this.dragOver(false);
|
||||
}, this),
|
||||
'onSelect': _.bind(function (sUid, oData) {
|
||||
if (sUid && oData && 'message/rfc822' === oData['Type'])
|
||||
{
|
||||
RL.data().messageListLoading(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}),
|
||||
'onComplete': _.bind(function () {
|
||||
RL.reloadMessageList(true, true);
|
||||
}, this)
|
||||
});
|
||||
|
||||
return !!oJua;
|
||||
};
|
||||
Reference in New Issue
Block a user