snappymail/dev/View/User/SystemDropDown.js

143 lines
3.9 KiB
JavaScript
Raw Normal View History

import { AppUserStore } from 'Stores/User/App';
import { AccountUserStore } from 'Stores/User/Account';
import { MessageUserStore } from 'Stores/User/Message';
//import { FolderUserStore } from 'Stores/User/Folder';
2014-08-21 23:08:34 +08:00
2022-03-06 05:25:32 +08:00
import { Scope } from 'Common/Enums';
2022-03-03 23:28:05 +08:00
import { settings } from 'Common/Links';
2014-08-25 15:10:51 +08:00
import { showScreenPopup } from 'Knoin/Knoin';
import { AbstractViewRight } from 'Knoin/AbstractViews';
import { KeyboardShortcutsHelpPopupView } from 'View/Popup/KeyboardShortcutsHelp';
import { AccountPopupView } from 'View/Popup/Account';
import { ContactsPopupView } from 'View/Popup/Contacts';
import { doc, leftPanelDisabled, fireEvent, SettingsCapa, registerShortcut } from 'Common/Globals';
import { ThemeStore } from 'Stores/Theme';
import Remote from 'Remote/User/Fetch';
import { getNotification } from 'Common/Translator';
//import { clearCache } from 'Common/Cache';
//import { koComputable } from 'External/ko';
export class SystemDropDownUserView extends AbstractViewRight {
constructor() {
super('SystemDropDown');
2015-04-10 16:17:49 +08:00
2022-03-06 05:25:32 +08:00
this.allowAccounts = SettingsCapa('AdditionalAccounts');
this.accountEmail = AccountUserStore.email;
2015-04-10 16:17:49 +08:00
this.accounts = AccountUserStore.accounts;
this.accountsLoading = AccountUserStore.loading;
/*
this.accountsUnreadCount = : koComputable(() => 0);
this.accountsUnreadCount = : koComputable(() => AccountUserStore.accounts().reduce((result, item) => result + item.count(), 0));
*/
2015-04-10 16:17:49 +08:00
2020-10-27 18:09:24 +08:00
this.addObservables({
currentAudio: '',
2021-03-23 21:48:34 +08:00
accountMenuDropdownTrigger: false
2020-10-27 18:09:24 +08:00
});
this.allowContacts = AppUserStore.allowContacts();
addEventListener('audio.stop', () => this.currentAudio(''));
addEventListener('audio.start', e => this.currentAudio(e.detail));
2016-06-30 08:02:45 +08:00
}
stopPlay() {
fireEvent('audio.api.stop');
}
accountClick(account, event) {
if (account && 0 === event.button) {
AccountUserStore.loading(true);
event.preventDefault();
event.stopPropagation();
Remote.request('AccountSwitch',
(iError/*, oData*/) => {
if (iError) {
AccountUserStore.loading(false);
alert(getNotification(iError).replace('%EMAIL%', account.email));
2021-11-15 17:56:52 +08:00
if (account.isAdditional()) {
showScreenPopup(AccountPopupView, [account]);
}
} else {
/* // Not working yet
forEachObjectEntry(oData.Result, (key, value) => rl.settings.set(key, value));
clearCache();
// MessageUserStore.setMessage();
// MessageUserStore.purgeMessageBodyCache();
// MessageUserStore.hideMessageBodies();
MessagelistUserStore([]);
// FolderUserStore.folderList([]);
loadFolders(value => {
if (value) {
// 4. Change to INBOX = reload MessageList
// MessagelistUserStore.setMessageList();
}
});
AccountUserStore.loading(false);
*/
2022-03-03 23:28:05 +08:00
rl.route.reload();
}
}, {Email:account.email}
);
}
return true;
2016-06-30 08:02:45 +08:00
}
emailTitle() {
return AccountUserStore.email();
2016-06-30 08:02:45 +08:00
}
2014-04-29 23:31:49 +08:00
settingsClick() {
2022-03-03 23:28:05 +08:00
hasher.setHash(settings());
2016-06-30 08:02:45 +08:00
}
2019-07-05 03:19:24 +08:00
settingsHelp() {
2021-09-17 20:37:18 +08:00
showScreenPopup(KeyboardShortcutsHelpPopupView);
}
addAccountClick() {
2021-03-23 21:48:34 +08:00
this.allowAccounts && showScreenPopup(AccountPopupView);
}
contactsClick() {
2021-03-23 21:48:34 +08:00
this.allowContacts && showScreenPopup(ContactsPopupView);
}
2021-09-14 16:06:38 +08:00
toggleLayout()
{
2021-09-14 16:06:38 +08:00
const mobile = !ThemeStore.isMobile();
doc.cookie = 'rllayout=' + (mobile ? 'mobile' : 'desktop') + '; samesite=strict';
2021-09-14 16:06:38 +08:00
ThemeStore.isMobile(mobile);
leftPanelDisabled(mobile);
}
logoutClick() {
2020-09-15 15:29:25 +08:00
rl.app.logout();
}
onBuild() {
registerShortcut('m', '', [Scope.MessageList, Scope.MessageView, Scope.Settings], () => {
if (!this.viewModelDom.hidden) {
MessageUserStore.fullScreen(false);
this.accountMenuDropdownTrigger(true);
return false;
}
});
// shortcuts help
registerShortcut('?,f1,help', '', [Scope.MessageList, Scope.MessageView, Scope.Settings], () => {
if (!this.viewModelDom.hidden) {
showScreenPopup(KeyboardShortcutsHelpPopupView);
return false;
}
});
}
}