2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
|
|
|
|
2020-08-30 16:30:50 +08:00
|
|
|
import { Capa, Focused, Layout, KeyState } from 'Common/Enums';
|
2020-07-15 20:25:51 +08:00
|
|
|
import { $htmlCL, leftPanelDisabled, moveAction } from 'Common/Globals';
|
2019-07-05 03:19:24 +08:00
|
|
|
import { mailBox, settings } from 'Common/Links';
|
|
|
|
import { setFolderHash } from 'Common/Cache';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
import AppStore from 'Stores/User/App';
|
|
|
|
import SettingsStore from 'Stores/User/Settings';
|
|
|
|
import FolderStore from 'Stores/User/Folder';
|
|
|
|
import MessageStore from 'Stores/User/Message';
|
|
|
|
|
2020-09-17 02:35:29 +08:00
|
|
|
import { view, ViewType, showScreenPopup } from 'Knoin/Knoin';
|
2019-07-05 03:19:24 +08:00
|
|
|
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
const Settings = rl.settings;
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
@view({
|
|
|
|
name: 'View/User/MailBox/FolderList',
|
|
|
|
type: ViewType.Left,
|
|
|
|
templateID: 'MailFolderList'
|
|
|
|
})
|
2019-07-05 03:19:24 +08:00
|
|
|
class FolderListMailBoxUserView extends AbstractViewNext {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
|
|
|
super();
|
2015-02-17 20:04:03 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.oContentScrollable = null;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.composeInEdit = AppStore.composeInEdit;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.messageList = MessageStore.messageList;
|
|
|
|
this.folderList = FolderStore.folderList;
|
|
|
|
this.folderListSystem = FolderStore.folderListSystem;
|
|
|
|
this.foldersChanging = FolderStore.foldersChanging;
|
2014-06-03 07:22:36 +08:00
|
|
|
|
2017-02-09 01:48:53 +08:00
|
|
|
this.moveAction = moveAction;
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.foldersListWithSingleInboxRootFolder = FolderStore.foldersListWithSingleInboxRootFolder;
|
2015-04-02 02:18:15 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.leftPanelDisabled = leftPanelDisabled;
|
2016-04-29 04:32:54 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.iDropOverTimer = 0;
|
2014-04-13 08:32:07 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.allowComposer = !!Settings.capa(Capa.Composer);
|
|
|
|
this.allowContacts = !!AppStore.contactsIsAllowed();
|
|
|
|
this.allowFolders = !!Settings.capa(Capa.Folders);
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.folderListFocused = ko.computed(() => Focused.FolderList === AppStore.focusedState());
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.isInboxStarred = ko.computed(
|
2019-07-05 03:19:24 +08:00
|
|
|
() =>
|
|
|
|
FolderStore.currentFolder() &&
|
2016-08-17 06:01:20 +08:00
|
|
|
FolderStore.currentFolder().isInbox() &&
|
2020-08-07 00:24:46 +08:00
|
|
|
MessageStore.messageListSearch().trim().includes('is:flagged')
|
2016-08-17 06:01:20 +08:00
|
|
|
);
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onBuild(dom) {
|
2020-08-30 16:30:50 +08:00
|
|
|
const qs = s => dom.querySelector(s),
|
|
|
|
eqs = (ev, s) => ev.target.closestWithin(s, dom),
|
2020-09-04 18:05:17 +08:00
|
|
|
isMobile = Settings.app('mobile'),
|
2016-08-17 06:01:20 +08:00
|
|
|
fSelectFolder = (el, event, starred) => {
|
2017-02-09 01:48:53 +08:00
|
|
|
const isMove = moveAction();
|
2019-07-05 03:19:24 +08:00
|
|
|
if (isMobile) {
|
2016-08-17 06:01:20 +08:00
|
|
|
leftPanelDisabled(true);
|
|
|
|
}
|
2016-04-29 04:32:54 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
event.preventDefault();
|
2016-04-29 04:32:54 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (starred) {
|
2016-08-17 06:01:20 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
const folder = ko.dataFor(el);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (folder) {
|
|
|
|
if (isMove) {
|
2017-02-09 01:48:53 +08:00
|
|
|
moveAction(false);
|
2020-09-15 15:29:25 +08:00
|
|
|
rl.app.moveMessagesToFolder(
|
2017-02-09 01:48:53 +08:00
|
|
|
FolderStore.currentFolderFullNameRaw(),
|
|
|
|
MessageStore.messageListCheckedOrSelectedUidsWithSubMails(),
|
|
|
|
folder.fullNameRaw,
|
|
|
|
false
|
|
|
|
);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
|
|
|
if (Layout.NoPreview === SettingsStore.layout()) {
|
2017-02-09 01:48:53 +08:00
|
|
|
MessageStore.message(null);
|
|
|
|
}
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (folder.fullNameRaw === FolderStore.currentFolderFullNameRaw()) {
|
2017-02-09 01:48:53 +08:00
|
|
|
setFolderHash(folder.fullNameRaw, '');
|
|
|
|
}
|
|
|
|
|
2020-09-17 02:35:29 +08:00
|
|
|
rl.route.setHash(starred
|
|
|
|
? mailBox(folder.fullNameHash, 1, 'is:flagged')
|
|
|
|
: mailBox(folder.fullNameHash)
|
|
|
|
);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2017-02-09 01:48:53 +08:00
|
|
|
|
|
|
|
AppStore.focusedState(Focused.MessageList);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
};
|
2014-02-04 04:06:35 +08:00
|
|
|
|
2020-08-27 21:45:47 +08:00
|
|
|
this.oContentScrollable = qs('.b-content');
|
|
|
|
|
2020-08-30 16:30:50 +08:00
|
|
|
dom.addEventListener('click', event => {
|
|
|
|
let el = eqs(event, '.b-folders .e-item .e-link .e-collapsed-sign');
|
|
|
|
if (el) {
|
|
|
|
const folder = ko.dataFor(el);
|
|
|
|
if (folder) {
|
2016-08-17 06:01:20 +08:00
|
|
|
const collapsed = folder.collapsed();
|
2020-09-15 15:29:25 +08:00
|
|
|
rl.app.setExpandedFolder(folder.fullNameHash, collapsed);
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
folder.collapsed(!collapsed);
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2020-08-30 16:30:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
el = eqs(event, '.b-folders .e-item .e-link.selectable .inbox-star-icon');
|
|
|
|
el && fSelectFolder(el, event, !this.isInboxStarred());
|
|
|
|
|
|
|
|
el = eqs(event, '.b-folders .e-item .e-link.selectable');
|
|
|
|
el && fSelectFolder(el, event, false);
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
key('up, down', KeyState.FolderList, (event, handler) => {
|
2020-08-30 16:30:50 +08:00
|
|
|
let items = [], index = 0;
|
|
|
|
dom.querySelectorAll('.b-folders .e-item .e-link:not(.hidden)').forEach(node => {
|
|
|
|
if (node.offsetHeight || node.getClientRects().length) {
|
|
|
|
items.push(node);
|
|
|
|
if (node.matches('.focused')) {
|
|
|
|
node.classList.remove('focused');
|
|
|
|
index = items.length - 1;
|
2020-08-27 21:45:47 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2020-08-30 16:30:50 +08:00
|
|
|
});
|
|
|
|
if (items.length) {
|
|
|
|
if (handler && 'up' === handler.shortcut) {
|
|
|
|
index && --index;
|
|
|
|
} else if (index < items.length - 1) {
|
2020-08-27 21:45:47 +08:00
|
|
|
++index;
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2020-08-30 16:30:50 +08:00
|
|
|
items[index].classList.add('focused');
|
|
|
|
this.scrollToFocused();
|
2014-04-13 08:32:07 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
return false;
|
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
key('enter', KeyState.FolderList, () => {
|
2020-08-27 21:45:47 +08:00
|
|
|
const item = qs('.b-folders .e-item .e-link:not(.hidden).focused');
|
|
|
|
if (item) {
|
2016-08-17 06:01:20 +08:00
|
|
|
AppStore.focusedState(Focused.MessageList);
|
2020-08-27 21:45:47 +08:00
|
|
|
item.click();
|
2014-04-13 08:32:07 +08:00
|
|
|
}
|
2014-06-03 07:22:36 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
return false;
|
|
|
|
});
|
2014-04-13 08:32:07 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
key('space', KeyState.FolderList, () => {
|
2020-08-27 21:45:47 +08:00
|
|
|
const item = qs('.b-folders .e-item .e-link:not(.hidden).focused'),
|
|
|
|
folder = item && ko.dataFor(item);
|
|
|
|
if (folder) {
|
|
|
|
const collapsed = folder.collapsed();
|
2020-09-15 15:29:25 +08:00
|
|
|
rl.app.setExpandedFolder(folder.fullNameHash, collapsed);
|
2020-08-27 21:45:47 +08:00
|
|
|
folder.collapsed(!collapsed);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-04-13 08:32:07 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
key('esc, tab, shift+tab, right', KeyState.FolderList, () => {
|
|
|
|
AppStore.focusedState(Focused.MessageList);
|
2017-02-09 01:48:53 +08:00
|
|
|
moveAction(false);
|
2016-08-17 06:01:20 +08:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2020-08-27 21:45:47 +08:00
|
|
|
AppStore.focusedState.subscribe(value => {
|
|
|
|
let el = qs('.b-folders .e-item .e-link.focused');
|
|
|
|
el && qs('.b-folders .e-item .e-link.focused').classList.remove('focused');
|
2019-07-05 03:19:24 +08:00
|
|
|
if (Focused.FolderList === value) {
|
2020-08-27 21:45:47 +08:00
|
|
|
el = qs('.b-folders .e-item .e-link.selected');
|
|
|
|
el && qs('.b-folders .e-item .e-link.selected').classList.add('focused');
|
2014-05-08 00:04:32 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
2014-05-08 00:04:32 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
messagesDropOver(folder) {
|
2020-08-12 06:25:36 +08:00
|
|
|
clearTimeout(this.iDropOverTimer);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (folder && folder.collapsed()) {
|
2020-08-12 06:25:36 +08:00
|
|
|
this.iDropOverTimer = setTimeout(() => {
|
2016-08-17 06:01:20 +08:00
|
|
|
folder.collapsed(false);
|
2020-09-15 15:29:25 +08:00
|
|
|
rl.app.setExpandedFolder(folder.fullNameHash, true);
|
2020-08-14 04:58:41 +08:00
|
|
|
}, 500);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-05-08 00:04:32 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
messagesDropOut() {
|
2020-08-12 06:25:36 +08:00
|
|
|
clearTimeout(this.iDropOverTimer);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
scrollToFocused() {
|
2020-08-27 21:45:47 +08:00
|
|
|
const scrollable = this.oContentScrollable;
|
|
|
|
if (scrollable) {
|
|
|
|
let block, focused = scrollable.querySelector('.e-item .e-link.focused');
|
|
|
|
if (focused) {
|
|
|
|
const fRect = focused.getBoundingClientRect(),
|
|
|
|
sRect = scrollable.getBoundingClientRect();
|
|
|
|
if (fRect.top < sRect.top) {
|
|
|
|
block = 'start';
|
|
|
|
} else if (fRect.bottom > sRect.bottom) {
|
|
|
|
block = 'end';
|
|
|
|
}
|
|
|
|
block && focused.scrollIntoView(block === 'start');
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2015-05-20 06:05:54 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {FolderModel} toFolder
|
|
|
|
* @param {{helper:jQuery}} ui
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
messagesDrop(toFolder, ui) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (toFolder && ui && ui.helper) {
|
2020-08-27 21:45:47 +08:00
|
|
|
const fromFolderFullNameRaw = ui.helper.rlFolder,
|
2020-07-15 20:25:51 +08:00
|
|
|
copy = $htmlCL.contains('rl-ctrl-key-pressed'),
|
2020-08-27 21:45:47 +08:00
|
|
|
uids = ui.helper.rlUids;
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2020-08-18 03:57:56 +08:00
|
|
|
if (fromFolderFullNameRaw && Array.isArray(uids)) {
|
2020-09-15 15:29:25 +08:00
|
|
|
rl.app.moveMessagesToFolder(fromFolderFullNameRaw, uids, toFolder.fullNameRaw, copy);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-06-03 07:22:36 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
composeClick() {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (Settings.capa(Capa.Composer)) {
|
2016-08-17 06:01:20 +08:00
|
|
|
showScreenPopup(require('View/Popup/Compose'));
|
2014-06-03 07:22:36 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-06-03 07:22:36 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
createFolder() {
|
|
|
|
showScreenPopup(require('View/Popup/FolderCreate'));
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
configureFolders() {
|
2020-09-17 02:35:29 +08:00
|
|
|
rl.route.setHash(settings('folders'));
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
contactsClick() {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (this.allowContacts) {
|
2016-08-17 06:01:20 +08:00
|
|
|
showScreenPopup(require('View/Popup/Contacts'));
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-06-03 07:22:36 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { FolderListMailBoxUserView, FolderListMailBoxUserView as default };
|