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

217 lines
5.5 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2023-04-03 16:29:26 +08:00
import { ScopeFolderList, ScopeMessageList } from 'Common/Enums';
2023-02-21 21:26:37 +08:00
import { addShortcut, stopEvent } from 'Common/Globals';
2019-07-05 03:19:24 +08:00
import { mailBox, settings } from 'Common/Links';
//import { setFolderETag } from 'Common/Cache';
2022-02-17 16:36:29 +08:00
import { addComputablesTo } from 'External/ko';
import { AppUserStore } from 'Stores/User/App';
import { SettingsUserStore } from 'Stores/User/Settings';
import { FolderUserStore } from 'Stores/User/Folder';
import { MessageUserStore } from 'Stores/User/Message';
import { MessagelistUserStore } from 'Stores/User/Messagelist';
import { showScreenPopup } from 'Knoin/Knoin';
import { AbstractViewLeft } from 'Knoin/AbstractViews';
import { showMessageComposer, moveAction } from 'Common/UtilsUser';
import { FolderCreatePopupView } from 'View/Popup/FolderCreate';
import { ContactsPopupView } from 'View/Popup/Contacts';
import { ComposePopupView } from 'View/Popup/Compose';
import { moveMessagesToFolder } from 'Common/Folders';
2022-10-07 18:06:03 +08:00
import { setExpandedFolder, foldersFilter } from 'Model/FolderCollection';
2022-02-08 00:27:25 +08:00
export class MailFolderList extends AbstractViewLeft {
constructor() {
2022-03-08 19:28:16 +08:00
super();
2022-09-09 18:07:05 +08:00
// this.oContentScrollable = null;
this.composeInEdit = ComposePopupView.inEdit;
2022-08-03 17:06:09 +08:00
this.systemFolders = FolderUserStore.systemFolders;
2017-02-09 01:48:53 +08:00
this.moveAction = moveAction;
2021-10-26 21:43:27 +08:00
this.foldersListWithSingleInboxRootFolder = ko.observable(false);
this.allowContacts = AppUserStore.allowContacts();
2022-10-07 18:06:03 +08:00
this.foldersFilter = foldersFilter;
addComputablesTo(this, {
2022-10-07 18:06:03 +08:00
foldersFilterVisible: () => 20 < FolderUserStore.folderList().CountRec,
2021-10-26 21:43:27 +08:00
folderListVisible: () => {
let multiple = false,
inbox, visible,
2021-10-26 21:43:27 +08:00
result = FolderUserStore.folderList().filter(folder => {
if (folder.isInbox()) {
inbox = folder;
}
visible = folder.visible();
multiple |= visible && !folder.isInbox();
return visible;
2021-10-26 21:43:27 +08:00
});
if (inbox && !multiple) {
2021-11-04 22:15:40 +08:00
inbox.collapsed(false);
2021-10-26 21:43:27 +08:00
}
this.foldersListWithSingleInboxRootFolder(!multiple);
return result;
}
});
}
2014-08-21 23:08:34 +08:00
onBuild(dom) {
const qs = s => dom.querySelector(s),
eqs = (ev, s) => ev.target.closestWithin(s, dom);
2016-04-29 04:32:54 +08:00
this.oContentScrollable = qs('.b-content');
2016-04-29 04:32:54 +08:00
dom.addEventListener('click', event => {
let el = eqs(event, '.e-collapsed-sign');
if (el) {
const folder = ko.dataFor(el);
if (folder) {
const collapsed = folder.collapsed();
2022-02-08 00:27:25 +08:00
setExpandedFolder(folder.fullName, collapsed);
folder.collapsed(!collapsed);
2023-02-21 21:26:37 +08:00
stopEvent(event);
return;
}
}
el = eqs(event, 'a');
2022-09-02 17:52:07 +08:00
if (el?.matches('.selectable')) {
event.preventDefault();
const folder = ko.dataFor(el);
2019-07-05 03:19:24 +08:00
if (folder) {
if (moveAction()) {
2017-02-09 01:48:53 +08:00
moveAction(false);
moveMessagesToFolder(
2021-11-30 17:19:43 +08:00
FolderUserStore.currentFolderFullName(),
MessagelistUserStore.listCheckedOrSelectedUidsWithSubMails(),
2021-11-23 04:01:30 +08:00
folder.fullName,
event.ctrlKey
2017-02-09 01:48:53 +08:00
);
2019-07-05 03:19:24 +08:00
} else {
if (!SettingsUserStore.usePreviewPane()) {
MessageUserStore.message(null);
2017-02-09 01:48:53 +08:00
}
/*
2021-11-30 17:19:43 +08:00
if (folder.fullName === FolderUserStore.currentFolderFullName()) {
setFolderETag(folder.fullName, '');
2017-02-09 01:48:53 +08:00
}
*/
2022-10-07 18:23:07 +08:00
let search = '';
if (event.target.matches('.flag-icon') && !folder.isFlagged()) {
search = 'flagged';
} else if (folder.unreadCount() && event.clientX > el.getBoundingClientRect().right - 25) {
2022-10-07 18:23:07 +08:00
search = 'unseen';
}
hasher.setHash(mailBox(folder.fullNameHash, 1, search));
}
2017-02-09 01:48:53 +08:00
2023-04-03 16:29:26 +08:00
AppUserStore.focusedState(ScopeMessageList);
}
}
});
2023-04-03 16:29:26 +08:00
addShortcut('arrowup,arrowdown', '', ScopeFolderList, event => {
let items = [], index = 0;
dom.querySelectorAll('li a').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
}
});
if (items.length) {
if ('ArrowUp' === event.key) {
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
}
items[index].classList.add('focused');
this.scrollToFocused();
}
2014-08-21 23:08:34 +08:00
return false;
});
2014-08-21 23:08:34 +08:00
2023-04-03 16:29:26 +08:00
addShortcut('enter,open', '', ScopeFolderList, () => {
const item = qs('li a.focused');
2020-08-27 21:45:47 +08:00
if (item) {
2023-04-03 16:29:26 +08:00
AppUserStore.focusedState(ScopeMessageList);
2020-08-27 21:45:47 +08:00
item.click();
}
return false;
});
2023-04-03 16:29:26 +08:00
addShortcut('space', '', ScopeFolderList, () => {
const item = qs('li a.focused'),
2020-08-27 21:45:47 +08:00
folder = item && ko.dataFor(item);
if (folder) {
const collapsed = folder.collapsed();
2022-02-08 00:27:25 +08:00
setExpandedFolder(folder.fullName, collapsed);
2020-08-27 21:45:47 +08:00
folder.collapsed(!collapsed);
2016-06-30 08:02:45 +08:00
}
return false;
});
2023-04-03 16:29:26 +08:00
// addShortcut('tab', 'shift', ScopeFolderList, () => {
addShortcut('escape,tab,arrowright', '', ScopeFolderList, () => {
AppUserStore.focusedState(ScopeMessageList);
2017-02-09 01:48:53 +08:00
moveAction(false);
return false;
});
}
scrollToFocused() {
2020-08-27 21:45:47 +08:00
const scrollable = this.oContentScrollable;
if (scrollable) {
let block, focused = scrollable.querySelector('li a.focused');
2020-08-27 21:45:47 +08:00
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
}
}
2016-06-30 08:02:45 +08:00
}
composeClick() {
showMessageComposer();
2016-06-30 08:02:45 +08:00
}
2023-01-12 23:54:40 +08:00
clearFolderSearch() {
foldersFilter('');
}
createFolder() {
showScreenPopup(FolderCreatePopupView);
2016-06-30 08:02:45 +08:00
}
configureFolders() {
2022-03-03 23:28:05 +08:00
hasher.setHash(settings('folders'));
}
2016-06-30 08:02:45 +08:00
contactsClick() {
2019-07-05 03:19:24 +08:00
if (this.allowContacts) {
showScreenPopup(ContactsPopupView);
}
2016-06-30 08:02:45 +08:00
}
}