snappymail/dev/View/User/AbstractSystemDropDown.js

103 lines
2.6 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
import AppStore from 'Stores/User/App';
import AccountStore from 'Stores/User/Account';
import MessageStore from 'Stores/User/Message';
2014-08-21 23:08:34 +08:00
2020-08-14 04:58:41 +08:00
import { Capa, KeyState } from 'Common/Enums';
2019-07-05 03:19:24 +08:00
import { settings } from 'Common/Links';
2014-08-25 15:10:51 +08:00
import { showScreenPopup } from 'Knoin/Knoin';
2019-07-05 03:19:24 +08:00
import { AbstractViewNext } from 'Knoin/AbstractViewNext';
const Settings = rl.settings;
2019-07-05 03:19:24 +08:00
class AbstractSystemDropDownUserView extends AbstractViewNext {
constructor() {
super();
2015-04-10 16:17:49 +08:00
this.logoImg = (Settings.get('UserLogo')||'').trim();
this.logoTitle = (Settings.get('UserLogoTitle')||'').trim();
this.mobile = !!Settings.app('mobile');
this.mobileDevice = !!Settings.app('mobileDevice');
this.allowSettings = !!Settings.capa(Capa.Settings);
this.allowHelp = !!Settings.capa(Capa.Help);
this.currentAudio = AppStore.currentAudio;
2015-04-10 16:17:49 +08:00
this.accountEmail = AccountStore.email;
2015-04-10 16:17:49 +08:00
this.accounts = AccountStore.accounts;
this.accountsUnreadCount = AccountStore.accountsUnreadCount;
2015-04-10 16:17:49 +08:00
this.accountMenuDropdownTrigger = ko.observable(false);
this.capaAdditionalAccounts = ko.observable(Settings.capa(Capa.AdditionalAccounts));
this.addAccountClick = this.addAccountClick.bind(this);
addEventListener('audio.stop', () => AppStore.currentAudio(''));
addEventListener('audio.start', e => AppStore.currentAudio(e.detail));
2016-06-30 08:02:45 +08:00
}
stopPlay() {
dispatchEvent(new CustomEvent('audio.api.stop'));
}
accountClick(account, event) {
if (account && event && undefined !== event.which && 1 === event.which) {
AccountStore.accounts.loading(true);
2020-08-14 04:58:41 +08:00
setTimeout(() => AccountStore.accounts.loading(false), 1000);
}
return true;
2016-06-30 08:02:45 +08:00
}
emailTitle() {
return AccountStore.email();
2016-06-30 08:02:45 +08:00
}
2014-04-29 23:31:49 +08:00
settingsClick() {
2019-07-05 03:19:24 +08:00
if (Settings.capa(Capa.Settings)) {
rl.route.setHash(settings());
}
2016-06-30 08:02:45 +08:00
}
2019-07-05 03:19:24 +08:00
settingsHelp() {
if (Settings.capa(Capa.Help)) {
showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
}
}
addAccountClick() {
2019-07-05 03:19:24 +08:00
if (this.capaAdditionalAccounts()) {
showScreenPopup(require('View/Popup/Account'));
}
}
logoutClick() {
2020-09-15 15:29:25 +08:00
rl.app.logout();
}
onBuild() {
shortcuts.add('`', '', [KeyState.MessageList, KeyState.MessageView, KeyState.Settings], () => {
2020-10-02 18:40:33 +08:00
if (this.viewModelVisible) {
MessageStore.messageFullScreenMode(false);
this.accountMenuDropdownTrigger(true);
}
});
// shortcuts help
shortcuts.add('?,f1,help', '', [KeyState.MessageList, KeyState.MessageView, KeyState.Settings], () => {
2020-10-02 18:40:33 +08:00
if (this.viewModelVisible) {
showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
return false;
}
return true;
});
}
}
2014-04-29 23:31:49 +08:00
2019-07-05 03:19:24 +08:00
export { AbstractSystemDropDownUserView, AbstractSystemDropDownUserView as default };