2013-11-16 06:21:12 +08:00
|
|
|
/* 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;
|
2014-01-26 22:23:37 +08:00
|
|
|
this.bPrefetch = false;
|
2013-11-16 06:21:12 +08:00
|
|
|
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 () {
|
2014-02-03 23:54:05 +08:00
|
|
|
return Enums.Layout.NoPreview !== oData.layout() ?
|
2013-11-16 06:21:12 +08:00
|
|
|
'MailMessageListItem' : 'MailMessageListItemNoPreviewPane';
|
|
|
|
});
|
|
|
|
|
|
|
|
this.messageListSearchDesc = ko.computed(function () {
|
|
|
|
var sValue = oData.messageListEndSearch();
|
|
|
|
return '' === sValue ? '' : Utils.i18n('MESSAGE_LIST/SEARCH_RESULT_FOR', {'SEARCH': sValue});
|
|
|
|
});
|
|
|
|
|
2013-12-08 07:58:33 +08:00
|
|
|
this.messageListPagenator = ko.computed(Utils.computedPagenatorHelper(oData.messageListPage, oData.messageListPageCount));
|
2013-11-16 06:21:12 +08:00
|
|
|
|
|
|
|
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 () {
|
2014-04-02 07:58:24 +08:00
|
|
|
return oData.spamFolder() === this.messageListEndFolder() &&
|
|
|
|
'' !== oData.spamFolder();
|
2013-11-16 06:21:12 +08:00
|
|
|
}, this);
|
|
|
|
|
2013-12-17 07:31:33 +08:00
|
|
|
this.isSpamDisabled = ko.computed(function () {
|
2014-04-02 07:58:24 +08:00
|
|
|
return Consts.Values.UnuseOptionValue === oData.spamFolder();
|
2013-12-17 07:31:33 +08:00
|
|
|
}, this);
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
this.isTrashFolder = ko.computed(function () {
|
2014-04-02 07:58:24 +08:00
|
|
|
return oData.trashFolder() === this.messageListEndFolder() &&
|
|
|
|
'' !== oData.trashFolder();
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.isArchiveFolder = ko.computed(function () {
|
|
|
|
return oData.archiveFolder() === this.messageListEndFolder() &&
|
|
|
|
'' !== oData.archiveFolder();
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.isArchiveDisabled = ko.computed(function () {
|
|
|
|
return Consts.Values.UnuseOptionValue === RL.data().archiveFolder();
|
2013-11-16 06:21:12 +08:00
|
|
|
}, 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 () {
|
2014-03-20 00:18:28 +08:00
|
|
|
RL.deleteMessagesFromFolder(Enums.FolderType.Trash,
|
|
|
|
RL.data().currentFolderFullNameRaw(),
|
|
|
|
RL.data().messageListCheckedOrSelectedUidsWithSubMails(), false);
|
2013-11-16 06:21:12 +08:00
|
|
|
}, this.canBeMoved);
|
|
|
|
|
|
|
|
this.deleteCommand = Utils.createCommand(this, function () {
|
2014-03-20 00:18:28 +08:00
|
|
|
RL.deleteMessagesFromFolder(Enums.FolderType.Trash,
|
|
|
|
RL.data().currentFolderFullNameRaw(),
|
|
|
|
RL.data().messageListCheckedOrSelectedUidsWithSubMails(), true);
|
2013-11-16 06:21:12 +08:00
|
|
|
}, this.canBeMoved);
|
2014-04-02 07:58:24 +08:00
|
|
|
|
|
|
|
this.archiveCommand = Utils.createCommand(this, function () {
|
|
|
|
RL.deleteMessagesFromFolder(Enums.FolderType.Archive,
|
|
|
|
RL.data().currentFolderFullNameRaw(),
|
|
|
|
RL.data().messageListCheckedOrSelectedUidsWithSubMails(), true);
|
|
|
|
}, this.canBeMoved);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
|
|
|
this.spamCommand = Utils.createCommand(this, function () {
|
2014-03-20 00:18:28 +08:00
|
|
|
RL.deleteMessagesFromFolder(Enums.FolderType.Spam,
|
|
|
|
RL.data().currentFolderFullNameRaw(),
|
|
|
|
RL.data().messageListCheckedOrSelectedUidsWithSubMails(), true);
|
2013-11-16 06:21:12 +08:00
|
|
|
}, 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)
|
|
|
|
{
|
2014-02-03 23:54:05 +08:00
|
|
|
if (Enums.Layout.NoPreview === oData.layout())
|
|
|
|
{
|
|
|
|
kn.setHash(RL.link().messagePreview(), true);
|
|
|
|
}
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
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));
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2013-12-13 07:23:47 +08:00
|
|
|
RL
|
|
|
|
.sub('mailbox.message-list.selector.go-down', function () {
|
|
|
|
this.selector.goDown();
|
|
|
|
}, this)
|
|
|
|
.sub('mailbox.message-list.selector.go-up', function () {
|
|
|
|
this.selector.goUp();
|
|
|
|
}, this)
|
|
|
|
;
|
|
|
|
|
2013-12-09 23:16:58 +08:00
|
|
|
Knoin.constructorEnd(this);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Utils.extendAsViewModel('MailBoxMessageListViewModel', MailBoxMessageListViewModel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
MailBoxMessageListViewModel.prototype.emptySubjectValue = '';
|
|
|
|
|
|
|
|
MailBoxMessageListViewModel.prototype.searchEnterAction = function ()
|
|
|
|
{
|
|
|
|
this.mainMessageListSearch(this.sLastSearchValue);
|
|
|
|
this.inputMessageListSearchFocus(false);
|
|
|
|
};
|
|
|
|
|
2014-04-02 07:58:24 +08:00
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
MailBoxMessageListViewModel.prototype.printableMessageCountForDeletion = function ()
|
|
|
|
{
|
|
|
|
var iCnt = this.messageListCheckedOrSelectedUidsWithSubMails().length;
|
|
|
|
return 1 < iCnt ? ' (' + (100 > iCnt ? iCnt : '99+') + ')' : '';
|
|
|
|
};
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
MailBoxMessageListViewModel.prototype.cancelSearch = function ()
|
|
|
|
{
|
|
|
|
this.mainMessageListSearch('');
|
|
|
|
this.inputMessageListSearchFocus(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} sToFolderFullNameRaw
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
MailBoxMessageListViewModel.prototype.moveSelectedMessagesToFolder = function (sToFolderFullNameRaw)
|
|
|
|
{
|
|
|
|
if (this.canBeMoved())
|
|
|
|
{
|
2014-03-20 00:18:28 +08:00
|
|
|
RL.moveMessagesToFolder(
|
|
|
|
RL.data().currentFolderFullNameRaw(),
|
2013-11-16 06:21:12 +08:00
|
|
|
RL.data().messageListCheckedOrSelectedUidsWithSubMails(), sToFolderFullNameRaw);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2013-12-09 05:32:19 +08:00
|
|
|
MailBoxMessageListViewModel.prototype.dragAndDronHelper = function (oMessageListItem, bCopy)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
|
|
|
if (oMessageListItem)
|
|
|
|
{
|
|
|
|
oMessageListItem.checked(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
var oEl = Utils.draggeblePlace();
|
|
|
|
oEl.data('rl-folder', RL.data().currentFolderFullNameRaw());
|
|
|
|
oEl.data('rl-uids', RL.data().messageListCheckedOrSelectedUidsWithSubMails());
|
2013-12-09 05:32:19 +08:00
|
|
|
oEl.data('rl-copy', bCopy ? '1' : '0');
|
|
|
|
oEl.find('.text').text((bCopy ? '+' : '') + '' + RL.data().messageListCheckedOrSelectedUidsWithSubMails().length);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
|
|
|
return oEl;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} sResult
|
|
|
|
* @param {AjaxJsonDefaultResponse} oData
|
|
|
|
* @param {boolean} bCached
|
|
|
|
*/
|
|
|
|
MailBoxMessageListViewModel.prototype.onMessageResponse = function (sResult, oData, bCached)
|
|
|
|
{
|
|
|
|
var oRainLoopData = RL.data();
|
2013-12-16 06:02:03 +08:00
|
|
|
|
2014-02-27 23:34:05 +08:00
|
|
|
oRainLoopData.hideMessageBodies();
|
2013-11-16 06:21:12 +08:00
|
|
|
oRainLoopData.messageLoading(false);
|
2014-02-27 23:34:05 +08:00
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
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())
|
|
|
|
{
|
2014-02-03 23:54:05 +08:00
|
|
|
if (Enums.Layout.NoPreview !== oData.layout() || (!oData.message() && (Enums.EventKeyCode.Delete === iKeyCode || Enums.EventKeyCode.A === iKeyCode)))
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
|
|
|
if (oEvent.ctrlKey && Enums.EventKeyCode.A === iKeyCode)
|
|
|
|
{
|
|
|
|
self.checkAll(!(self.checkAll() && !self.isIncompleteChecked()));
|
|
|
|
bResult = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bResult;
|
|
|
|
});
|
|
|
|
|
|
|
|
oDom
|
2013-12-08 07:58:33 +08:00
|
|
|
.on('click', '.e-pagenator .e-page', function () {
|
2013-11-16 06:21:12 +08:00
|
|
|
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();
|
2014-01-26 22:23:37 +08:00
|
|
|
|
|
|
|
if (!Globals.bMobileDevice && !!RL.settingsGet('AllowPrefetch') && ifvisible)
|
|
|
|
{
|
|
|
|
ifvisible.setIdleDuration(10);
|
|
|
|
|
|
|
|
ifvisible.idle(function () {
|
|
|
|
self.prefetchNextTick();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MailBoxMessageListViewModel.prototype.prefetchNextTick = function ()
|
|
|
|
{
|
|
|
|
if (!this.bPrefetch && !ifvisible.now() && this.viewModelVisibility())
|
|
|
|
{
|
|
|
|
var
|
|
|
|
self = this,
|
|
|
|
oCache = RL.cache(),
|
|
|
|
oMessage = _.find(this.messageList(), function (oMessage) {
|
|
|
|
return oMessage &&
|
|
|
|
!oCache.hasRequestedMessage(oMessage.folderFullNameRaw, oMessage.uid);
|
|
|
|
})
|
|
|
|
;
|
|
|
|
|
|
|
|
if (oMessage)
|
|
|
|
{
|
|
|
|
this.bPrefetch = true;
|
|
|
|
|
|
|
|
RL.cache().addRequestedMessage(oMessage.folderFullNameRaw, oMessage.uid);
|
|
|
|
|
|
|
|
RL.remote().message(function (sResult, oData) {
|
|
|
|
|
|
|
|
var bNext = !!(Enums.StorageResultType.Success === sResult && oData && oData.Result);
|
|
|
|
|
|
|
|
_.delay(function () {
|
|
|
|
self.bPrefetch = false;
|
|
|
|
if (bNext)
|
|
|
|
{
|
|
|
|
self.prefetchNextTick();
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
}, oMessage.folderFullNameRaw, oMessage.uid);
|
|
|
|
}
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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(),
|
2013-12-09 06:14:55 +08:00
|
|
|
'dragAndDropBodyElement': this.dragOverBodyArea()
|
|
|
|
});
|
|
|
|
|
|
|
|
oJua
|
|
|
|
.on('onDragEnter', _.bind(function () {
|
2013-11-16 06:21:12 +08:00
|
|
|
this.dragOverEnter(true);
|
2013-12-09 06:14:55 +08:00
|
|
|
}, this))
|
|
|
|
.on('onDragLeave', _.bind(function () {
|
2013-11-16 06:21:12 +08:00
|
|
|
this.dragOverEnter(false);
|
2013-12-09 06:14:55 +08:00
|
|
|
}, this))
|
|
|
|
.on('onBodyDragEnter', _.bind(function () {
|
2013-11-16 06:21:12 +08:00
|
|
|
this.dragOver(true);
|
2013-12-09 06:14:55 +08:00
|
|
|
}, this))
|
|
|
|
.on('onBodyDragLeave', _.bind(function () {
|
2013-11-16 06:21:12 +08:00
|
|
|
this.dragOver(false);
|
2013-12-09 06:14:55 +08:00
|
|
|
}, this))
|
|
|
|
.on('onSelect', _.bind(function (sUid, oData) {
|
2013-11-16 06:21:12 +08:00
|
|
|
if (sUid && oData && 'message/rfc822' === oData['Type'])
|
|
|
|
{
|
|
|
|
RL.data().messageListLoading(true);
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-09 06:14:55 +08:00
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
return false;
|
2013-12-09 06:14:55 +08:00
|
|
|
}, this))
|
|
|
|
.on('onComplete', _.bind(function () {
|
2013-11-16 06:21:12 +08:00
|
|
|
RL.reloadMessageList(true, true);
|
2013-12-09 06:14:55 +08:00
|
|
|
}, this))
|
|
|
|
;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
|
|
|
return !!oJua;
|
|
|
|
};
|