2016-08-17 06:01:20 +08:00
|
|
|
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';
|
2023-02-16 17:55:23 +08:00
|
|
|
//import { setFolderETag } from 'Common/Cache';
|
2022-02-17 16:36:29 +08:00
|
|
|
import { addComputablesTo } from 'External/ko';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { AppUserStore } from 'Stores/User/App';
|
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
|
|
|
import { FolderUserStore } from 'Stores/User/Folder';
|
|
|
|
import { MessageUserStore } from 'Stores/User/Message';
|
2022-02-24 02:26:52 +08:00
|
|
|
import { MessagelistUserStore } from 'Stores/User/Messagelist';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
import { showScreenPopup } from 'Knoin/Knoin';
|
|
|
|
import { AbstractViewLeft } from 'Knoin/AbstractViews';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2022-11-22 18:14:56 +08:00
|
|
|
import { showMessageComposer, moveAction } from 'Common/UtilsUser';
|
2021-01-26 05:00:13 +08:00
|
|
|
import { FolderCreatePopupView } from 'View/Popup/FolderCreate';
|
|
|
|
import { ContactsPopupView } from 'View/Popup/Contacts';
|
2022-09-08 19:28:24 +08:00
|
|
|
import { ComposePopupView } from 'View/Popup/Compose';
|
2021-01-26 05:00:13 +08:00
|
|
|
|
2022-02-24 02:26:52 +08:00
|
|
|
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
|
|
|
|
2021-09-23 15:41:02 +08:00
|
|
|
export class MailFolderList extends AbstractViewLeft {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2022-03-08 19:28:16 +08:00
|
|
|
super();
|
2015-02-17 20:04:03 +08:00
|
|
|
|
2022-09-09 18:07:05 +08:00
|
|
|
// this.oContentScrollable = null;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2022-09-08 19:28:24 +08:00
|
|
|
this.composeInEdit = ComposePopupView.inEdit;
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2022-08-03 17:06:09 +08:00
|
|
|
this.systemFolders = FolderUserStore.systemFolders;
|
2014-06-03 07:22:36 +08:00
|
|
|
|
2017-02-09 01:48:53 +08:00
|
|
|
this.moveAction = moveAction;
|
|
|
|
|
2021-10-26 21:43:27 +08:00
|
|
|
this.foldersListWithSingleInboxRootFolder = ko.observable(false);
|
2015-04-02 02:18:15 +08:00
|
|
|
|
2021-03-17 17:05:22 +08:00
|
|
|
this.allowContacts = AppUserStore.allowContacts();
|
2014-04-08 05:03:58 +08:00
|
|
|
|
2022-10-07 18:06:03 +08:00
|
|
|
this.foldersFilter = foldersFilter;
|
|
|
|
|
2021-10-13 21:41:22 +08:00
|
|
|
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,
|
2021-11-04 02:25:52 +08:00
|
|
|
inbox, visible,
|
2021-10-26 21:43:27 +08:00
|
|
|
result = FolderUserStore.folderList().filter(folder => {
|
|
|
|
if (folder.isInbox()) {
|
|
|
|
inbox = folder;
|
|
|
|
}
|
2021-11-04 02:25:52 +08:00
|
|
|
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;
|
|
|
|
}
|
2021-10-13 21:41:22 +08:00
|
|
|
});
|
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),
|
2021-08-09 20:22:57 +08:00
|
|
|
eqs = (ev, s) => ev.target.closestWithin(s, dom);
|
2016-04-29 04:32:54 +08:00
|
|
|
|
2021-08-09 20:22:57 +08:00
|
|
|
this.oContentScrollable = qs('.b-content');
|
2016-04-29 04:32:54 +08:00
|
|
|
|
2021-08-09 20:22:57 +08:00
|
|
|
dom.addEventListener('click', event => {
|
2021-08-25 18:24:27 +08:00
|
|
|
let el = eqs(event, '.e-collapsed-sign');
|
2021-08-09 20:22:57 +08:00
|
|
|
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);
|
2021-08-09 20:22:57 +08:00
|
|
|
|
|
|
|
folder.collapsed(!collapsed);
|
2023-02-21 21:26:37 +08:00
|
|
|
stopEvent(event);
|
2021-08-09 20:22:57 +08:00
|
|
|
return;
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2021-08-09 20:22:57 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-08-25 18:24:27 +08:00
|
|
|
el = eqs(event, 'a');
|
2022-09-02 17:52:07 +08:00
|
|
|
if (el?.matches('.selectable')) {
|
2021-08-09 20:22:57 +08:00
|
|
|
event.preventDefault();
|
2016-08-17 06:01:20 +08:00
|
|
|
const folder = ko.dataFor(el);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (folder) {
|
2021-08-09 20:22:57 +08:00
|
|
|
if (moveAction()) {
|
2017-02-09 01:48:53 +08:00
|
|
|
moveAction(false);
|
2022-02-24 02:26:52 +08:00
|
|
|
moveMessagesToFolder(
|
2021-11-30 17:19:43 +08:00
|
|
|
FolderUserStore.currentFolderFullName(),
|
2022-02-24 02:26:52 +08:00
|
|
|
MessagelistUserStore.listCheckedOrSelectedUidsWithSubMails(),
|
2021-11-23 04:01:30 +08:00
|
|
|
folder.fullName,
|
2020-10-01 17:11:14 +08:00
|
|
|
event.ctrlKey
|
2017-02-09 01:48:53 +08:00
|
|
|
);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2021-03-11 05:41:35 +08:00
|
|
|
if (!SettingsUserStore.usePreviewPane()) {
|
|
|
|
MessageUserStore.message(null);
|
2017-02-09 01:48:53 +08:00
|
|
|
}
|
2022-06-07 17:54:19 +08:00
|
|
|
/*
|
2021-11-30 17:19:43 +08:00
|
|
|
if (folder.fullName === FolderUserStore.currentFolderFullName()) {
|
2023-02-16 17:55:23 +08:00
|
|
|
setFolderETag(folder.fullName, '');
|
2017-02-09 01:48:53 +08:00
|
|
|
}
|
2022-06-07 17:54:19 +08:00
|
|
|
*/
|
2022-10-07 18:23:07 +08:00
|
|
|
let search = '';
|
|
|
|
if (event.target.matches('.flag-icon') && !folder.isFlagged()) {
|
|
|
|
search = 'flagged';
|
2022-12-22 18:40:56 +08:00
|
|
|
} 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));
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2017-02-09 01:48:53 +08:00
|
|
|
|
2023-04-03 16:29:26 +08:00
|
|
|
AppUserStore.focusedState(ScopeMessageList);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2020-08-30 16:30:50 +08:00
|
|
|
}
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2023-04-03 16:29:26 +08:00
|
|
|
addShortcut('arrowup,arrowdown', '', ScopeFolderList, event => {
|
2020-08-30 16:30:50 +08:00
|
|
|
let items = [], index = 0;
|
2022-10-07 19:04:51 +08:00
|
|
|
dom.querySelectorAll('li a').forEach(node => {
|
2020-08-30 16:30:50 +08:00
|
|
|
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) {
|
2020-09-26 06:02:29 +08:00
|
|
|
if ('ArrowUp' === event.key) {
|
2020-08-30 16:30:50 +08:00
|
|
|
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
|
|
|
|
2023-04-03 16:29:26 +08:00
|
|
|
addShortcut('enter,open', '', ScopeFolderList, () => {
|
2022-10-07 19:04:51 +08:00
|
|
|
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();
|
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
|
|
|
|
2023-04-03 16:29:26 +08:00
|
|
|
addShortcut('space', '', ScopeFolderList, () => {
|
2022-10-07 19:04:51 +08:00
|
|
|
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
|
|
|
}
|
2014-04-13 08:32:07 +08:00
|
|
|
|
2016-08-17 06:01:20 +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);
|
2016-08-17 06:01:20 +08:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2014-05-08 00:04:32 +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) {
|
2021-08-25 00:23:17 +08:00
|
|
|
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
|
|
|
}
|
2015-05-20 06:05:54 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
composeClick() {
|
2021-03-10 18:43:23 +08:00
|
|
|
showMessageComposer();
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-06-03 07:22:36 +08:00
|
|
|
|
2023-01-12 23:54:40 +08:00
|
|
|
clearFolderSearch() {
|
|
|
|
foldersFilter('');
|
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
createFolder() {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(FolderCreatePopupView);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
configureFolders() {
|
2022-03-03 23:28:05 +08:00
|
|
|
hasher.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) {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(ContactsPopupView);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|