snappymail/dev/View/User/MailBox/MessageList.js

1076 lines
28 KiB
JavaScript
Raw Normal View History

2016-06-30 08:02:45 +08:00
var
window = require('window'),
_ = require('_'),
$ = require('$'),
ko = require('ko'),
key = require('key'),
Jua = require('Jua'),
ifvisible = require('ifvisible'),
Enums = require('Common/Enums'),
Consts = require('Common/Consts'),
Globals = require('Common/Globals'),
Utils = require('Common/Utils'),
Links = require('Common/Links'),
Events = require('Common/Events'),
Selector = require('Common/Selector'),
Translator = require('Common/Translator'),
Cache = require('Common/Cache'),
AppStore = require('Stores/User/App'),
QuotaStore = require('Stores/User/Quota'),
SettingsStore = require('Stores/User/Settings'),
FolderStore = require('Stores/User/Folder'),
MessageStore = require('Stores/User/Message'),
Settings = require('Storage/Settings'),
Remote = require('Remote/User/Ajax'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
/**
* @constructor
* @extends AbstractView
*/
function MessageListMailBoxUserView()
{
AbstractView.call(this, 'Right', 'MailMessageList');
this.sLastUid = null;
this.bPrefetch = false;
this.emptySubjectValue = '';
this.mobile = !!Settings.appSettingsGet('mobile');
this.allowReload = !!Settings.capa(Enums.Capa.Reload);
this.allowSearch = !!Settings.capa(Enums.Capa.Search);
this.allowSearchAdv = !!Settings.capa(Enums.Capa.SearchAdv);
this.allowComposer = !!Settings.capa(Enums.Capa.Composer);
this.allowMessageListActions = !!Settings.capa(Enums.Capa.MessageListActions);
this.allowDangerousActions = !!Settings.capa(Enums.Capa.DangerousActions);
this.allowFolders = !!Settings.capa(Enums.Capa.Folders);
this.popupVisibility = Globals.popupVisibility;
this.message = MessageStore.message;
this.messageList = MessageStore.messageList;
this.messageListDisableAutoSelect = MessageStore.messageListDisableAutoSelect;
this.folderList = FolderStore.folderList;
this.composeInEdit = AppStore.composeInEdit;
this.leftPanelDisabled = Globals.leftPanelDisabled;
this.selectorMessageSelected = MessageStore.selectorMessageSelected;
this.selectorMessageFocused = MessageStore.selectorMessageFocused;
this.isMessageSelected = MessageStore.isMessageSelected;
this.messageListSearch = MessageStore.messageListSearch;
this.messageListThreadUid = MessageStore.messageListThreadUid;
this.messageListError = MessageStore.messageListError;
this.folderMenuForMove = FolderStore.folderMenuForMove;
this.useCheckboxesInList = SettingsStore.useCheckboxesInList;
this.mainMessageListSearch = MessageStore.mainMessageListSearch;
this.messageListEndFolder = MessageStore.messageListEndFolder;
this.messageListEndThreadUid = MessageStore.messageListEndThreadUid;
this.messageListChecked = MessageStore.messageListChecked;
this.messageListCheckedOrSelected = MessageStore.messageListCheckedOrSelected;
this.messageListCheckedOrSelectedUidsWithSubMails = MessageStore.messageListCheckedOrSelectedUidsWithSubMails;
this.messageListCompleteLoadingThrottle = MessageStore.messageListCompleteLoadingThrottle;
this.messageListCompleteLoadingThrottleForAnimation = MessageStore.messageListCompleteLoadingThrottleForAnimation;
Translator.initOnStartOrLangChange(function() {
this.emptySubjectValue = Translator.i18n('MESSAGE_LIST/EMPTY_SUBJECT_TEXT');
}, this);
this.userQuota = QuotaStore.quota;
this.userUsageSize = QuotaStore.usage;
this.userUsageProc = QuotaStore.percentage;
this.moveDropdownTrigger = ko.observable(false);
this.moreDropdownTrigger = ko.observable(false);
// 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 this.mobile || Enums.Layout.SidePreview === SettingsStore.layout() ?
'MailMessageListItem' : 'MailMessageListItemNoPreviewPane';
}, this);
this.messageListSearchDesc = ko.computed(function() {
var sValue = MessageStore.messageListEndSearch();
return '' === sValue ? '' : Translator.i18n('MESSAGE_LIST/SEARCH_RESULT_FOR', {'SEARCH': sValue});
});
this.messageListPagenator = ko.computed(Utils.computedPagenatorHelper(
MessageStore.messageListPage, MessageStore.messageListPageCount));
this.checkAll = ko.computed({
'read': function() {
return 0 < MessageStore.messageListChecked().length;
},
'write': function(bValue) {
bValue = !!bValue;
_.each(MessageStore.messageList(), function(oMessage) {
oMessage.checked(bValue);
});
}
});
2016-06-30 08:02:45 +08:00
this.inputMessageListSearchFocus = ko.observable(false);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.sLastSearchValue = '';
this.inputProxyMessageListSearch = ko.computed({
'read': this.mainMessageListSearch,
'write': function(sValue) {
this.sLastSearchValue = sValue;
},
'owner': this
});
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.isIncompleteChecked = ko.computed(function() {
var
iM = MessageStore.messageList().length,
iC = MessageStore.messageListChecked().length;
return 0 < iM && 0 < iC && iM > iC;
}, this);
this.hasMessages = ko.computed(function() {
return 0 < this.messageList().length;
}, this);
this.hasCheckedOrSelectedLines = ko.computed(function() {
return 0 < this.messageListCheckedOrSelected().length;
}, this);
this.isSpamFolder = ko.computed(function() {
return FolderStore.spamFolder() === this.messageListEndFolder() &&
'' !== FolderStore.spamFolder();
}, this);
this.isSpamDisabled = ko.computed(function() {
return Consts.UNUSED_OPTION_VALUE === FolderStore.spamFolder();
}, this);
this.isTrashFolder = ko.computed(function() {
return FolderStore.trashFolder() === this.messageListEndFolder() &&
'' !== FolderStore.trashFolder();
}, this);
this.isDraftFolder = ko.computed(function() {
return FolderStore.draftFolder() === this.messageListEndFolder() &&
'' !== FolderStore.draftFolder();
}, this);
this.isSentFolder = ko.computed(function() {
return FolderStore.sentFolder() === this.messageListEndFolder() &&
'' !== FolderStore.sentFolder();
}, this);
this.isArchiveFolder = ko.computed(function() {
return FolderStore.archiveFolder() === this.messageListEndFolder() &&
'' !== FolderStore.archiveFolder();
}, this);
this.isArchiveDisabled = ko.computed(function() {
return Consts.UNUSED_OPTION_VALUE === FolderStore.archiveFolder();
}, this);
this.isArchiveVisible = ko.computed(function() {
return !this.isArchiveFolder() && !this.isArchiveDisabled() && !this.isDraftFolder();
}, this);
this.isSpamVisible = ko.computed(function() {
return !this.isSpamFolder() && !this.isSpamDisabled() && !this.isDraftFolder() && !this.isSentFolder();
}, this);
this.isUnSpamVisible = ko.computed(function() {
return this.isSpamFolder() && !this.isSpamDisabled() && !this.isDraftFolder() && !this.isSentFolder();
}, this);
this.mobileCheckedStateShow = ko.computed(function() {
var checked = 0 < this.messageListChecked().length;
return this.mobile ? checked : true;
}, this);
this.mobileCheckedStateHide = ko.computed(function() {
var checked = 0 < this.messageListChecked().length;
return this.mobile ? !checked : true;
}, this);
this.messageListFocused = ko.computed(function() {
return Enums.Focused.MessageList === AppStore.focusedState();
});
this.canBeMoved = this.hasCheckedOrSelectedLines;
this.clearCommand = Utils.createCommand(this, function() {
if (Settings.capa(Enums.Capa.DangerousActions))
{
kn.showScreenPopup(require('View/Popup/FolderClear'), [FolderStore.currentFolder()]);
}
});
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.multyForwardCommand = Utils.createCommand(this, function() {
if (Settings.capa(Enums.Capa.Composer))
{
kn.showScreenPopup(require('View/Popup/Compose'), [
Enums.ComposeType.ForwardAsAttachment, MessageStore.messageListCheckedOrSelected()]);
}
}, this.canBeMoved);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.deleteWithoutMoveCommand = Utils.createCommand(this, function() {
if (Settings.capa(Enums.Capa.DangerousActions))
{
2015-11-19 01:32:29 +08:00
require('App/User').default.deleteMessagesFromFolder(Enums.FolderType.Trash,
2015-02-22 06:00:51 +08:00
FolderStore.currentFolderFullNameRaw(),
2016-06-30 08:02:45 +08:00
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), false);
}
}, this.canBeMoved);
this.deleteCommand = Utils.createCommand(this, function() {
require('App/User').default.deleteMessagesFromFolder(Enums.FolderType.Trash,
FolderStore.currentFolderFullNameRaw(),
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), true);
}, this.canBeMoved);
this.archiveCommand = Utils.createCommand(this, function() {
require('App/User').default.deleteMessagesFromFolder(Enums.FolderType.Archive,
FolderStore.currentFolderFullNameRaw(),
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), true);
}, this.canBeMoved);
this.spamCommand = Utils.createCommand(this, function() {
require('App/User').default.deleteMessagesFromFolder(Enums.FolderType.Spam,
FolderStore.currentFolderFullNameRaw(),
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), true);
}, this.canBeMoved);
this.notSpamCommand = Utils.createCommand(this, function() {
require('App/User').default.deleteMessagesFromFolder(Enums.FolderType.NotSpam,
FolderStore.currentFolderFullNameRaw(),
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), true);
}, this.canBeMoved);
this.moveCommand = Utils.createCommand(this, Utils.noop, this.canBeMoved);
this.reloadCommand = Utils.createCommand(this, function() {
if (!MessageStore.messageListCompleteLoadingThrottleForAnimation() && this.allowReload)
{
require('App/User').default.reloadMessageList(false, true);
}
});
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.quotaTooltip = _.bind(this.quotaTooltip, this);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.selector = new Selector.Selector(this.messageList, this.selectorMessageSelected, this.selectorMessageFocused,
'.messageListItem .actionHandle', '.messageListItem.selected', '.messageListItem .checkboxMessage',
'.messageListItem.focused');
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.selector.on('onItemSelect', _.bind(function(oMessage) {
MessageStore.selectMessage(oMessage);
}, this));
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.selector.on('onItemGetUid', function(oMessage) {
return oMessage ? oMessage.generateUid() : '';
});
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.selector.on('onAutoSelect', _.bind(function() {
return this.useAutoSelect();
}, this));
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.selector.on('onUpUpOrDownDown', _.bind(function(bV) {
this.goToUpUpOrDownDown(bV);
}, this));
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
Events.sub('mailbox.message-list.selector.go-down', function(bSelect) {
this.selector.goDown(bSelect);
}, this);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
Events.sub('mailbox.message-list.selector.go-up', function(bSelect) {
this.selector.goUp(bSelect);
}, this);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
Events.sub('mailbox.message.show', function(sFolder, sUid) {
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
var oMessage = _.find(this.messageList(), function(oItem) {
return oItem && sFolder === oItem.folderFullNameRaw && sUid === oItem.uid;
});
2016-06-16 07:36:44 +08:00
2016-06-30 08:02:45 +08:00
if ('INBOX' === sFolder)
{
kn.setHash(Links.mailBox(sFolder, 1));
}
2015-07-07 02:46:44 +08:00
2016-06-30 08:02:45 +08:00
if (oMessage)
{
this.selector.selectMessageItem(oMessage);
}
else
{
if ('INBOX' !== sFolder)
2016-06-16 07:36:44 +08:00
{
kn.setHash(Links.mailBox(sFolder, 1));
}
2016-06-30 08:02:45 +08:00
MessageStore.selectMessageByFolderAndUid(sFolder, sUid);
}
2015-07-07 02:46:44 +08:00
2016-06-30 08:02:45 +08:00
}, this);
2015-07-07 02:46:44 +08:00
2016-06-30 08:02:45 +08:00
MessageStore.messageListEndHash.subscribe(function() {
this.selector.scrollToTop();
}, this);
2016-06-30 08:02:45 +08:00
kn.constructorEnd(this);
}
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
kn.extendAsViewModel(['View/User/MailBox/MessageList', 'View/App/MailBox/MessageList', 'MailBoxMessageListViewModel'], MessageListMailBoxUserView);
_.extend(MessageListMailBoxUserView.prototype, AbstractView.prototype);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
/**
* @type {string}
*/
MessageListMailBoxUserView.prototype.emptySubjectValue = '';
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.iGoToUpUpOrDownDownTimeout = 0;
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.hideLeft = function(oItem, oEvent)
{
oEvent.preventDefault();
oEvent.stopPropagation();
2016-05-01 09:07:10 +08:00
2016-06-30 08:02:45 +08:00
Globals.leftPanelDisabled(true);
};
2016-05-01 09:07:10 +08:00
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.showLeft = function(oItem, oEvent)
{
oEvent.preventDefault();
oEvent.stopPropagation();
2016-05-01 09:07:10 +08:00
2016-06-30 08:02:45 +08:00
Globals.leftPanelDisabled(false);
};
2016-05-01 09:07:10 +08:00
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.composeClick = function()
{
if (Settings.capa(Enums.Capa.Composer))
2016-05-01 09:07:10 +08:00
{
2016-06-30 08:02:45 +08:00
kn.showScreenPopup(require('View/Popup/Compose'));
}
};
2016-05-01 09:07:10 +08:00
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.goToUpUpOrDownDown = function(bUp)
{
var self = this;
2016-06-30 08:02:45 +08:00
if (0 < this.messageListChecked().length)
{
return false;
}
2015-05-03 04:22:32 +08:00
2016-06-30 08:02:45 +08:00
window.clearTimeout(this.iGoToUpUpOrDownDownTimeout);
this.iGoToUpUpOrDownDownTimeout = window.setTimeout(function() {
2016-06-30 08:02:45 +08:00
var
oPrev = null,
oNext = null,
oTemp = null,
oCurrent = null,
aPages = self.messageListPagenator();
2016-06-30 08:02:45 +08:00
_.find(aPages, function(oItem) {
2016-06-30 08:02:45 +08:00
if (oItem)
{
if (oCurrent)
{
2016-06-30 08:02:45 +08:00
oNext = oItem;
}
2016-06-30 08:02:45 +08:00
if (oItem.current)
{
oCurrent = oItem;
oPrev = oTemp;
}
2016-06-30 08:02:45 +08:00
if (oNext)
{
return true;
}
2016-06-30 08:02:45 +08:00
oTemp = oItem;
}
2016-06-30 08:02:45 +08:00
return false;
});
2016-06-30 08:02:45 +08:00
if (Enums.Layout.NoPreview === SettingsStore.layout() && !self.message())
2015-03-06 08:42:40 +08:00
{
2016-06-30 08:02:45 +08:00
self.selector.iFocusedNextHelper = bUp ? -1 : 1;
2015-03-06 08:42:40 +08:00
}
2016-06-30 08:02:45 +08:00
else
{
2016-06-30 08:02:45 +08:00
self.selector.iSelectNextHelper = bUp ? -1 : 1;
}
2016-06-30 08:02:45 +08:00
if (bUp ? oPrev : oNext)
{
self.selector.unselect();
self.gotoPage(bUp ? oPrev : oNext);
}
2016-07-06 03:52:52 +08:00
}, Enums.Magics.Time350ms);
2016-07-01 06:50:11 +08:00
return true;
2016-06-30 08:02:45 +08:00
};
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.useAutoSelect = function()
{
if (this.messageListDisableAutoSelect())
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
return false;
}
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
if (/is:unseen/.test(this.mainMessageListSearch()))
{
2014-08-21 23:08:34 +08:00
return false;
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
return Enums.Layout.NoPreview !== SettingsStore.layout();
};
MessageListMailBoxUserView.prototype.searchEnterAction = function()
{
this.mainMessageListSearch(this.sLastSearchValue);
this.inputMessageListSearchFocus(false);
};
/**
* @returns {string}
*/
MessageListMailBoxUserView.prototype.printableMessageCountForDeletion = function()
{
var iCnt = this.messageListCheckedOrSelectedUidsWithSubMails().length;
2016-07-06 03:52:52 +08:00
return 1 < iCnt ? ' (' + (100 > iCnt ? iCnt : '99+') + ')' : ''; // eslint-disable-line no-magic-numbers
2016-06-30 08:02:45 +08:00
};
MessageListMailBoxUserView.prototype.cancelSearch = function()
{
this.mainMessageListSearch('');
this.inputMessageListSearchFocus(false);
};
MessageListMailBoxUserView.prototype.cancelThreadUid = function()
{
kn.setHash(Links.mailBox(
FolderStore.currentFolderFullNameHash(),
MessageStore.messageListPageBeforeThread(),
MessageStore.messageListSearch()
));
};
/**
* @param {string} sToFolderFullNameRaw
* @param {boolean} bCopy
* @returns {boolean}
*/
MessageListMailBoxUserView.prototype.moveSelectedMessagesToFolder = function(sToFolderFullNameRaw, bCopy)
{
if (this.canBeMoved())
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
require('App/User').default.moveMessagesToFolder(
FolderStore.currentFolderFullNameRaw(),
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(), sToFolderFullNameRaw, bCopy);
}
2016-06-30 08:02:45 +08:00
return false;
};
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.dragAndDronHelper = function(oMessageListItem)
{
if (oMessageListItem)
{
oMessageListItem.checked(true);
}
2016-06-30 08:02:45 +08:00
var
oEl = Utils.draggablePlace(),
updateUidsInfo = function() {
var aUids = MessageStore.messageListCheckedOrSelectedUidsWithSubMails();
oEl.data('rl-uids', aUids);
oEl.find('.text').text('' + aUids.length);
};
oEl.data('rl-folder', FolderStore.currentFolderFullNameRaw());
updateUidsInfo();
_.defer(updateUidsInfo);
return oEl;
};
/**
* @param {string} sFolderFullNameRaw
* @param {string|bool} mUid
* @param {number} iSetAction
* @param {Array=} aMessages = null
* @returns {void}
*/
MessageListMailBoxUserView.prototype.setAction = function(sFolderFullNameRaw, mUid, iSetAction, aMessages)
{
require('App/User').default.messageListAction(sFolderFullNameRaw, mUid, iSetAction, aMessages);
};
/**
* @param {string} sFolderFullNameRaw
* @param {number} iSetAction
* @returns {void}
*/
MessageListMailBoxUserView.prototype.setActionForAll = function(sFolderFullNameRaw, iSetAction)
{
var
oFolder = null,
aMessages = MessageStore.messageList();
2016-06-30 08:02:45 +08:00
if ('' !== sFolderFullNameRaw)
2014-04-09 04:59:22 +08:00
{
2016-06-30 08:02:45 +08:00
oFolder = Cache.getFolderFromCacheList(sFolderFullNameRaw);
2014-04-09 04:59:22 +08:00
2016-06-30 08:02:45 +08:00
if (oFolder)
2014-04-09 04:59:22 +08:00
{
2016-06-30 08:02:45 +08:00
switch (iSetAction)
2014-08-21 23:08:34 +08:00
{
case Enums.MessageSetAction.SetSeen:
oFolder = Cache.getFolderFromCacheList(sFolderFullNameRaw);
if (oFolder)
{
2016-06-30 08:02:45 +08:00
_.each(aMessages, function(oMessage) {
2014-08-21 23:08:34 +08:00
oMessage.unseen(false);
});
2014-04-09 04:59:22 +08:00
2014-08-21 23:08:34 +08:00
oFolder.messageCountUnread(0);
Cache.clearMessageFlagsFromCacheByFolder(sFolderFullNameRaw);
}
2014-04-09 04:59:22 +08:00
2016-06-17 07:23:49 +08:00
Remote.messageSetSeenToAll(Utils.noop, sFolderFullNameRaw, true);
2014-08-21 23:08:34 +08:00
break;
case Enums.MessageSetAction.UnsetSeen:
oFolder = Cache.getFolderFromCacheList(sFolderFullNameRaw);
if (oFolder)
{
2016-06-30 08:02:45 +08:00
_.each(aMessages, function(oMessage) {
2014-08-21 23:08:34 +08:00
oMessage.unseen(true);
});
oFolder.messageCountUnread(oFolder.messageCountAll());
Cache.clearMessageFlagsFromCacheByFolder(sFolderFullNameRaw);
}
2016-06-17 07:23:49 +08:00
Remote.messageSetSeenToAll(Utils.noop, sFolderFullNameRaw, false);
2014-08-21 23:08:34 +08:00
break;
2016-06-30 08:02:45 +08:00
// no default
2014-08-21 23:08:34 +08:00
}
2014-04-09 04:59:22 +08:00
2016-06-30 08:02:45 +08:00
require('App/User').default.reloadFlagsCurrentMessageListAndMessageFromCache();
2014-08-21 23:08:34 +08:00
}
2016-06-30 08:02:45 +08:00
}
};
MessageListMailBoxUserView.prototype.listSetSeen = function()
{
this.setAction(FolderStore.currentFolderFullNameRaw(), true,
Enums.MessageSetAction.SetSeen, MessageStore.messageListCheckedOrSelected());
};
MessageListMailBoxUserView.prototype.listSetAllSeen = function()
{
this.setActionForAll(FolderStore.currentFolderFullNameRaw(), Enums.MessageSetAction.SetSeen);
};
MessageListMailBoxUserView.prototype.listUnsetSeen = function()
{
this.setAction(FolderStore.currentFolderFullNameRaw(), true,
Enums.MessageSetAction.UnsetSeen, MessageStore.messageListCheckedOrSelected());
};
MessageListMailBoxUserView.prototype.listSetFlags = function()
{
this.setAction(FolderStore.currentFolderFullNameRaw(), true,
Enums.MessageSetAction.SetFlag, MessageStore.messageListCheckedOrSelected());
};
MessageListMailBoxUserView.prototype.listUnsetFlags = function()
{
this.setAction(FolderStore.currentFolderFullNameRaw(), true,
Enums.MessageSetAction.UnsetFlag, MessageStore.messageListCheckedOrSelected());
};
MessageListMailBoxUserView.prototype.flagMessages = function(oCurrentMessage)
{
var
aChecked = this.messageListCheckedOrSelected(),
aCheckedUids = [];
2016-06-30 08:02:45 +08:00
if (oCurrentMessage)
2014-08-21 23:08:34 +08:00
{
if (0 < aChecked.length)
{
2016-06-30 08:02:45 +08:00
aCheckedUids = _.map(aChecked, function(oMessage) {
return oMessage.uid;
2014-08-21 23:08:34 +08:00
});
2016-06-30 08:02:45 +08:00
}
2016-06-30 08:02:45 +08:00
if (0 < aCheckedUids.length && -1 < Utils.inArray(oCurrentMessage.uid, aCheckedUids))
{
this.setAction(oCurrentMessage.folderFullNameRaw, true, oCurrentMessage.flagged() ?
Enums.MessageSetAction.UnsetFlag : Enums.MessageSetAction.SetFlag, aChecked);
}
else
{
this.setAction(oCurrentMessage.folderFullNameRaw, true, oCurrentMessage.flagged() ?
Enums.MessageSetAction.UnsetFlag : Enums.MessageSetAction.SetFlag, [oCurrentMessage]);
}
2016-06-30 08:02:45 +08:00
}
};
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.flagMessagesFast = function(bFlag)
{
var
aChecked = this.messageListCheckedOrSelected(),
aFlagged = [];
if (0 < aChecked.length)
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
aFlagged = _.filter(aChecked, function(oMessage) {
return oMessage.flagged();
});
2016-06-30 08:02:45 +08:00
if (Utils.isUnd(bFlag))
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
this.setAction(aChecked[0].folderFullNameRaw, true,
aChecked.length === aFlagged.length ? Enums.MessageSetAction.UnsetFlag : Enums.MessageSetAction.SetFlag, aChecked);
2014-08-21 23:08:34 +08:00
}
2016-06-30 08:02:45 +08:00
else
{
2016-06-30 08:02:45 +08:00
this.setAction(aChecked[0].folderFullNameRaw, true,
!bFlag ? Enums.MessageSetAction.UnsetFlag : Enums.MessageSetAction.SetFlag, aChecked);
}
2016-06-30 08:02:45 +08:00
}
};
MessageListMailBoxUserView.prototype.seenMessagesFast = function(bSeen)
{
var
aChecked = this.messageListCheckedOrSelected(),
aUnseen = [];
2016-06-30 08:02:45 +08:00
if (0 < aChecked.length)
2015-04-21 06:39:14 +08:00
{
2016-06-30 08:02:45 +08:00
aUnseen = _.filter(aChecked, function(oMessage) {
return oMessage.unseen();
});
if (Utils.isUnd(bSeen))
{
this.setAction(aChecked[0].folderFullNameRaw, true,
0 < aUnseen.length ? Enums.MessageSetAction.SetSeen : Enums.MessageSetAction.UnsetSeen, aChecked);
}
else
2015-04-21 06:39:14 +08:00
{
2016-06-30 08:02:45 +08:00
this.setAction(aChecked[0].folderFullNameRaw, true,
bSeen ? Enums.MessageSetAction.SetSeen : Enums.MessageSetAction.UnsetSeen, aChecked);
2015-04-21 06:39:14 +08:00
}
2016-06-30 08:02:45 +08:00
}
};
2015-04-21 06:39:14 +08:00
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.gotoPage = function(oPage)
{
if (oPage)
2015-04-23 05:33:02 +08:00
{
2016-06-30 08:02:45 +08:00
kn.setHash(Links.mailBox(
FolderStore.currentFolderFullNameHash(),
oPage.value,
MessageStore.messageListSearch(),
MessageStore.messageListThreadUid()
));
}
};
2015-04-23 05:33:02 +08:00
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.gotoThread = function(oMessage)
{
if (oMessage && 0 < oMessage.threadsLen())
{
2016-06-30 08:02:45 +08:00
MessageStore.messageListPageBeforeThread(MessageStore.messageListPage());
2016-06-30 08:02:45 +08:00
kn.setHash(Links.mailBox(
FolderStore.currentFolderFullNameHash(),
1,
MessageStore.messageListSearch(),
oMessage.uid
));
}
};
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.clearListIsVisible = function()
{
return '' === this.messageListSearchDesc() && '' === this.messageListError() &&
'' === MessageStore.messageListEndThreadUid() &&
0 < this.messageList().length && (this.isSpamFolder() || this.isTrashFolder());
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.onBuild = function(oDom)
{
var self = this;
2016-05-01 09:07:10 +08:00
2016-06-30 08:02:45 +08:00
this.oContentVisible = $('.b-content', oDom);
this.oContentScrollable = $('.content', this.oContentVisible);
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
this.selector.init(this.oContentVisible, this.oContentScrollable, Enums.KeyState.MessageList);
2016-06-30 08:02:45 +08:00
if (this.mobile)
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
oDom
.on('click', function() {
Globals.leftPanelDisabled(true);
});
}
2014-05-27 20:54:41 +08:00
2016-06-30 08:02:45 +08:00
oDom
.on('click', '.messageList .b-message-list-wrapper', function() {
if (Enums.Focused.MessageView === AppStore.focusedState())
{
2016-06-30 08:02:45 +08:00
AppStore.focusedState(Enums.Focused.MessageList);
}
2016-06-30 08:02:45 +08:00
})
.on('click', '.e-pagenator .e-page', function() {
self.gotoPage(ko.dataFor(this));
})
.on('click', '.messageList .checkboxCkeckAll', function() {
self.checkAll(!self.checkAll());
})
.on('click', '.messageList .messageListItem .flagParent', function() {
self.flagMessages(ko.dataFor(this));
})
.on('click', '.messageList .messageListItem .threads-len', function() {
self.gotoThread(ko.dataFor(this));
})
.on('dblclick', '.messageList .messageListItem .actionHandle', function() {
self.gotoThread(ko.dataFor(this));
});
2016-06-30 08:02:45 +08:00
this.initUploaderForAppend();
this.initShortcuts();
2016-06-30 08:02:45 +08:00
if (!Globals.bMobileDevice && ifvisible && Settings.capa(Enums.Capa.Prefetch))
{
2016-07-06 03:52:52 +08:00
ifvisible.setIdleDuration(Enums.Magics.ifvisibleIdle10s);
2016-06-30 08:02:45 +08:00
ifvisible.idle(function() {
self.prefetchNextTick();
});
}
};
2014-04-09 04:59:22 +08:00
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.initShortcuts = function()
{
var self = this;
key('enter', Enums.KeyState.MessageList, function() {
if (self.message() && self.useAutoSelect())
{
2016-06-30 08:02:45 +08:00
Events.pub('mailbox.message-view.toggle-full-screen');
return false;
}
2016-07-01 06:50:11 +08:00
return true;
2016-06-30 08:02:45 +08:00
});
2016-06-30 08:02:45 +08:00
if (Settings.capa(Enums.Capa.MessageListActions))
{
// archive (zip)
key('z', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function() {
self.archiveCommand();
2014-08-21 23:08:34 +08:00
return false;
});
2014-04-09 04:59:22 +08:00
2016-06-30 08:02:45 +08:00
// delete
key('delete, shift+delete, shift+3', Enums.KeyState.MessageList, function(event, handler) {
if (event)
{
if (0 < MessageStore.messageListCheckedOrSelected().length)
{
if (handler && 'shift+delete' === handler.shortcut)
{
self.deleteWithoutMoveCommand();
}
else
{
self.deleteCommand();
}
}
2014-04-09 04:59:22 +08:00
return false;
2016-06-30 08:02:45 +08:00
}
2016-07-01 06:50:11 +08:00
return true;
2016-06-30 08:02:45 +08:00
});
}
2016-06-30 08:02:45 +08:00
if (Settings.capa(Enums.Capa.Reload))
{
// check mail
key('ctrl+r, command+r', [Enums.KeyState.FolderList, Enums.KeyState.MessageList, Enums.KeyState.MessageView], function() {
self.reloadCommand();
return false;
});
}
2015-04-21 06:39:14 +08:00
2016-06-30 08:02:45 +08:00
// check all
key('ctrl+a, command+a', Enums.KeyState.MessageList, function() {
self.checkAll(!(self.checkAll() && !self.isIncompleteChecked()));
return false;
});
2015-04-21 06:39:14 +08:00
2016-06-30 08:02:45 +08:00
if (Settings.capa(Enums.Capa.Composer))
{
// write/compose (open compose popup)
key('w,c', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function() {
kn.showScreenPopup(require('View/Popup/Compose'));
return false;
});
}
2015-04-21 06:39:14 +08:00
2016-06-30 08:02:45 +08:00
if (Settings.capa(Enums.Capa.MessageListActions))
{
// important - star/flag messages
key('i', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function() {
self.flagMessagesFast();
2015-04-21 06:39:14 +08:00
return false;
});
2016-06-30 08:02:45 +08:00
}
2015-04-21 06:39:14 +08:00
2016-06-30 08:02:45 +08:00
key('t', [Enums.KeyState.MessageList], function() {
2016-06-30 08:02:45 +08:00
var oMessage = self.selectorMessageSelected();
if (!oMessage)
{
2016-06-30 08:02:45 +08:00
oMessage = self.selectorMessageFocused();
}
2016-06-30 08:02:45 +08:00
if (oMessage && 0 < oMessage.threadsLen())
{
2016-06-30 08:02:45 +08:00
self.gotoThread(oMessage);
}
2016-06-30 08:02:45 +08:00
return false;
});
2016-06-30 08:02:45 +08:00
if (Settings.capa(Enums.Capa.MessageListActions))
{
// move
key('m', Enums.KeyState.MessageList, function() {
self.moveDropdownTrigger(true);
return false;
2014-08-21 23:08:34 +08:00
});
2016-06-30 08:02:45 +08:00
}
2016-06-30 08:02:45 +08:00
if (Settings.capa(Enums.Capa.MessageListActions))
{
// read
key('q', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function() {
self.seenMessagesFast(true);
2014-08-21 23:08:34 +08:00
return false;
});
2016-06-30 08:02:45 +08:00
// unread
key('u', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function() {
self.seenMessagesFast(false);
2015-02-17 23:52:33 +08:00
return false;
2014-08-21 23:08:34 +08:00
});
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
if (Settings.capa(Enums.Capa.Composer))
{
key('shift+f', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function() {
self.multyForwardCommand();
2015-02-17 23:52:33 +08:00
return false;
2014-08-21 23:08:34 +08:00
});
2016-06-30 08:02:45 +08:00
}
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
if (Settings.capa(Enums.Capa.Search))
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
// search input focus
key('/', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function() {
self.inputMessageListSearchFocus(true);
return false;
});
}
2016-06-30 08:02:45 +08:00
// cancel search
key('esc', Enums.KeyState.MessageList, function() {
if ('' !== self.messageListSearchDesc())
{
self.cancelSearch();
return false;
}
else if ('' !== self.messageListEndThreadUid())
{
self.cancelThreadUid();
return false;
}
2016-07-01 06:50:11 +08:00
return true;
2016-06-30 08:02:45 +08:00
});
2016-06-30 08:02:45 +08:00
// change focused state
key('tab, shift+tab, left, right', Enums.KeyState.MessageList, function(event, handler) {
if (event && handler && ('shift+tab' === handler.shortcut || 'left' === handler.shortcut))
{
AppStore.focusedState(Enums.Focused.FolderList);
}
else if (self.message())
{
AppStore.focusedState(Enums.Focused.MessageView);
}
2016-06-30 08:02:45 +08:00
return false;
});
2016-06-30 08:02:45 +08:00
key('ctrl+left, command+left', Enums.KeyState.MessageView, function() {
return false;
});
2016-06-30 08:02:45 +08:00
key('ctrl+right, command+right', Enums.KeyState.MessageView, function() {
return false;
});
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.prefetchNextTick = function()
{
if (ifvisible && !this.bPrefetch && !ifvisible.now() && this.viewModelVisibility())
{
2016-06-30 08:02:45 +08:00
var
self = this,
oMessage = _.find(this.messageList(), function(oItem) {
return oItem && !Cache.hasRequestedMessage(oItem.folderFullNameRaw, oItem.uid);
});
if (oMessage)
{
2016-06-30 08:02:45 +08:00
this.bPrefetch = true;
Cache.addRequestedMessage(oMessage.folderFullNameRaw, oMessage.uid);
Remote.message(function(sResult, oData) {
var bNext = !!(Enums.StorageResultType.Success === sResult && oData && oData.Result);
_.delay(function() {
self.bPrefetch = false;
if (bNext)
{
self.prefetchNextTick();
}
2016-07-06 03:52:52 +08:00
}, Enums.Magics.Time1s);
2016-06-30 08:02:45 +08:00
}, oMessage.folderFullNameRaw, oMessage.uid);
}
2016-06-30 08:02:45 +08:00
}
};
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.composeClick = function()
{
if (Settings.capa(Enums.Capa.Composer))
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
kn.showScreenPopup(require('View/Popup/Compose'));
}
};
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
MessageListMailBoxUserView.prototype.advancedSearchClick = function()
{
if (Settings.capa(Enums.Capa.SearchAdv))
{
kn.showScreenPopup(require('View/Popup/AdvancedSearch'), [this.mainMessageListSearch()]);
}
};
MessageListMailBoxUserView.prototype.quotaTooltip = function()
{
return Translator.i18n('MESSAGE_LIST/QUOTA_SIZE', {
'SIZE': Utils.friendlySize(this.userUsageSize()),
'PROC': this.userUsageProc(),
'LIMIT': Utils.friendlySize(this.userQuota())
});
};
MessageListMailBoxUserView.prototype.initUploaderForAppend = function()
{
if (!Settings.appSettingsGet('allowAppendMessage') || !this.dragOverArea())
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
return false;
}
var
oJua = new Jua({
action: Links.append(),
name: 'AppendFile',
queueSize: 1,
multipleSizeLimit: 1,
hidden: {
Folder: function() {
return FolderStore.currentFolderFullNameRaw();
}
},
dragAndDropElement: this.dragOverArea(),
dragAndDropBodyElement: this.dragOverBodyArea()
2014-08-21 23:08:34 +08:00
});
2013-12-09 06:14:55 +08:00
2016-06-30 08:02:45 +08:00
this.dragOver.subscribe(function(bValue) {
if (bValue)
2014-08-21 23:08:34 +08:00
{
2016-06-30 08:02:45 +08:00
this.selector.scrollToTop();
2014-08-21 23:08:34 +08:00
}
2016-06-30 08:02:45 +08:00
}, this);
oJua
.on('onDragEnter', _.bind(function() {
this.dragOverEnter(true);
}, this))
.on('onDragLeave', _.bind(function() {
this.dragOverEnter(false);
}, this))
.on('onBodyDragEnter', _.bind(function() {
this.dragOver(true);
}, this))
.on('onBodyDragLeave', _.bind(function() {
this.dragOver(false);
}, this))
.on('onSelect', _.bind(function(sUid, oData) {
if (sUid && oData && 'message/rfc822' === oData.Type)
{
2016-06-30 08:02:45 +08:00
MessageStore.messageListLoading(true);
return true;
}
2015-02-22 06:00:51 +08:00
2016-06-30 08:02:45 +08:00
return false;
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
}, this))
.on('onComplete', _.bind(function() {
require('App/User').default.reloadMessageList(true, true);
}, this));
2014-08-21 23:08:34 +08:00
2016-06-30 08:02:45 +08:00
return !!oJua;
};
2016-06-30 08:02:45 +08:00
module.exports = MessageListMailBoxUserView;