snappymail/dev/App/Abstract.js

147 lines
3.8 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2016-06-07 05:57:52 +08:00
import {
$htmlCL,
2019-07-05 03:19:24 +08:00
leftPanelDisabled,
leftPanelType
2016-06-07 05:57:52 +08:00
} from 'Common/Globals';
2020-08-14 04:58:41 +08:00
import { KeyState } from 'Common/Enums';
import { rootAdmin, rootUser } from 'Common/Links';
2019-07-05 03:19:24 +08:00
import { initOnStartOrLangChange, initNotificationLanguage } from 'Common/Translator';
2015-11-19 01:32:29 +08:00
import LanguageStore from 'Stores/Language';
import ThemeStore from 'Stores/Theme';
const Settings = rl.settings;
2020-09-17 02:01:47 +08:00
class AbstractApp {
2014-08-20 23:03:12 +08:00
/**
* @param {RemoteStorage|AdminRemoteStorage} Remote
2014-08-20 23:03:12 +08:00
*/
2019-10-17 06:43:04 +08:00
constructor() {
2016-06-28 04:54:38 +08:00
this.isLocalAutocomplete = true;
this.lastErrorTime = 0;
const $doc = document;
$doc.addEventListener('keydown', event =>
event.ctrlKey && $htmlCL.add('rl-ctrl-key-pressed')
// $htmlCL.toggle('rl-ctrl-key-pressed', event.ctrlKey)
// 'Control' === event.key && $htmlCL.add('rl-ctrl-key-pressed')
);
$doc.addEventListener('keyup', event =>
// !event.ctrlKey && $htmlCL.remove('rl-ctrl-key-pressed')
$htmlCL.toggle('rl-ctrl-key-pressed', event.ctrlKey)
// 'Control' === event.key && $htmlCL.remove('rl-ctrl-key-pressed')
);
const fn = (()=>dispatchEvent(new CustomEvent('rl.auto-logout-refresh'))).debounce(5000);
$doc.addEventListener('mousemove', fn);
$doc.addEventListener('keypress', fn);
$doc.addEventListener('click', fn);
2015-03-16 05:58:50 +08:00
shortcuts.add('escape,enter', '', KeyState.All, () => rl.Dropdowns.detectVisibility());
}
2015-11-19 01:32:29 +08:00
remote() {
2014-08-22 23:08:56 +08:00
return null;
2015-11-19 01:32:29 +08:00
}
2014-08-22 23:08:56 +08:00
2015-11-19 01:32:29 +08:00
data() {
2014-08-22 23:08:56 +08:00
return null;
2015-11-19 01:32:29 +08:00
}
2014-08-22 23:08:56 +08:00
2014-08-20 23:03:12 +08:00
/**
2015-11-19 01:32:29 +08:00
* @param {string} link
2016-06-30 08:02:45 +08:00
* @returns {boolean}
2014-08-20 23:03:12 +08:00
*/
2015-11-19 01:32:29 +08:00
download(link) {
if (rl.settings.app('mobile')) {
open(link, '_self');
focus();
2019-07-05 03:19:24 +08:00
} else {
const oLink = document.createElement('a');
oLink.href = link;
document.body.appendChild(oLink).click();
oLink.remove();
2014-08-20 23:03:12 +08:00
}
return true;
2015-11-19 01:32:29 +08:00
}
2015-05-06 00:41:15 +08:00
/**
2016-04-21 01:12:51 +08:00
* @param {string} token
2015-05-06 00:41:15 +08:00
*/
2016-04-21 01:12:51 +08:00
setClientSideToken(token) {
rl.hash.set();
Settings.set('AuthAccountHash', token);
2015-11-19 01:32:29 +08:00
}
2015-05-06 00:41:15 +08:00
logoutReload(close = false) {
const logoutLink = rl.adminArea() ? rootAdmin() : rootUser();
rl.hash.clear();
close && window.close && window.close();
if (location.href !== logoutLink) {
setTimeout(() => (Settings.app('inIframe') ? parent : window).location.href = logoutLink, 100);
2019-07-05 03:19:24 +08:00
} else {
rl.route.reload();
2014-08-20 23:03:12 +08:00
}
2015-11-19 01:32:29 +08:00
}
2015-11-19 01:32:29 +08:00
bootstart() {
const mobile = Settings.app('mobile');
2014-10-29 06:05:50 +08:00
2017-03-01 02:44:13 +08:00
ko.components.register('SaveTrigger', require('Component/SaveTrigger').default);
ko.components.register('Input', require('Component/Input').default);
ko.components.register('Select', require('Component/Select').default);
ko.components.register('TextArea', require('Component/TextArea').default);
if (Settings.app('materialDesign') && !rl.settings.app('mobile')) {
2017-03-01 02:44:13 +08:00
ko.components.register('Checkbox', require('Component/MaterialDesign/Checkbox').default);
ko.components.register('CheckboxSimple', require('Component/Checkbox').default);
2019-07-05 03:19:24 +08:00
} else {
2017-03-01 02:44:13 +08:00
ko.components.register('Checkbox', require('Component/Checkbox').default);
ko.components.register('CheckboxSimple', require('Component/Checkbox').default);
}
2014-08-20 23:03:12 +08:00
2016-06-17 07:23:49 +08:00
initOnStartOrLangChange(initNotificationLanguage);
2019-07-05 03:19:24 +08:00
if (!mobile) {
// mobile
window.addEventListener('resize', () => leftPanelDisabled(767 >= window.innerWidth));
2019-07-05 03:19:24 +08:00
} else {
$htmlCL.add('rl-mobile');
leftPanelDisabled(true);
2016-05-01 09:07:10 +08:00
}
2016-06-07 05:57:52 +08:00
leftPanelDisabled.subscribe((bValue) => {
$htmlCL.toggle('rl-left-panel-disabled', bValue);
$htmlCL.toggle('rl-left-panel-enabled', !bValue);
2014-08-20 23:03:12 +08:00
});
2014-04-27 08:54:22 +08:00
2016-06-07 05:57:52 +08:00
leftPanelType.subscribe((sValue) => {
$htmlCL.toggle('rl-left-panel-none', 'none' === sValue);
$htmlCL.toggle('rl-left-panel-short', 'short' === sValue);
});
2016-06-07 05:57:52 +08:00
leftPanelDisabled.valueHasMutated();
2016-04-29 04:32:54 +08:00
LanguageStore.populate();
ThemeStore.populate();
2016-04-21 01:12:51 +08:00
}
2020-09-17 05:19:34 +08:00
/**
* @returns {void}
*/
hideLoading() {
const id = id => document.getElementById(id);
id('rl-content').hidden = false;
id('rl-loading').remove();
}
2015-11-19 01:32:29 +08:00
}
2014-04-27 08:54:22 +08:00
2019-07-05 03:19:24 +08:00
export { AbstractApp, AbstractApp as default };