2016-09-13 04:50:21 +08:00
|
|
|
import ko from 'ko';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
import {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL,
|
2019-07-05 03:19:24 +08:00
|
|
|
leftPanelDisabled,
|
2020-09-30 18:31:34 +08:00
|
|
|
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';
|
2020-09-04 20:36:24 +08:00
|
|
|
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
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
import LanguageStore from 'Stores/Language';
|
|
|
|
import ThemeStore from 'Stores/Theme';
|
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
const Settings = rl.settings;
|
|
|
|
|
2020-09-17 02:01:47 +08:00
|
|
|
class AbstractApp {
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2014-09-02 08:15:31 +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;
|
|
|
|
|
2020-08-12 06:25:36 +08:00
|
|
|
const $doc = document;
|
2020-10-09 21:00:26 +08:00
|
|
|
$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')
|
|
|
|
);
|
2020-07-30 03:49:41 +08:00
|
|
|
|
2020-08-19 02:24:17 +08:00
|
|
|
const fn = (()=>dispatchEvent(new CustomEvent('rl.auto-logout-refresh'))).debounce(5000);
|
2020-07-30 03:49:41 +08:00
|
|
|
|
2020-07-17 01:49:56 +08:00
|
|
|
$doc.addEventListener('mousemove', fn);
|
|
|
|
$doc.addEventListener('keypress', fn);
|
|
|
|
$doc.addEventListener('click', fn);
|
2015-03-16 05:58:50 +08:00
|
|
|
|
2020-09-26 16:20:24 +08:00
|
|
|
shortcuts.add('escape,enter', '', KeyState.All, () => rl.Dropdowns.detectVisibility());
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
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) {
|
2020-09-30 18:31:34 +08:00
|
|
|
if (rl.settings.app('mobile')) {
|
2020-08-12 06:25:36 +08:00
|
|
|
open(link, '_self');
|
|
|
|
focus();
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2020-08-12 06:25:36 +08:00
|
|
|
const oLink = document.createElement('a');
|
2020-07-17 01:49:56 +08:00
|
|
|
oLink.href = link;
|
2020-09-04 22:11:57 +08:00
|
|
|
document.body.appendChild(oLink).click();
|
2020-07-17 01:49:56 +08:00
|
|
|
oLink.remove();
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
|
|
|
return true;
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-10-31 04:09:53 +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) {
|
2020-09-04 18:05:17 +08:00
|
|
|
rl.hash.set();
|
|
|
|
Settings.set('AuthAccountHash', token);
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2015-05-06 00:41:15 +08:00
|
|
|
|
2020-09-04 20:36:24 +08:00
|
|
|
logoutReload(close = false) {
|
|
|
|
const logoutLink = rl.adminArea() ? rootAdmin() : rootUser();
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-09-04 20:36:24 +08:00
|
|
|
rl.hash.clear();
|
|
|
|
close && window.close && window.close();
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-09-04 20:36:24 +08:00
|
|
|
if (location.href !== logoutLink) {
|
|
|
|
setTimeout(() => (Settings.app('inIframe') ? parent : window).location.href = logoutLink, 100);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2020-09-17 02:35:29 +08:00
|
|
|
rl.route.reload();
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
bootstart() {
|
2020-09-04 18:05:17 +08:00
|
|
|
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);
|
2015-04-02 02:18:15 +08:00
|
|
|
|
2020-09-30 18:31:34 +08:00
|
|
|
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-10-30 05:08:53 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2016-06-17 07:23:49 +08:00
|
|
|
initOnStartOrLangChange(initNotificationLanguage);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (!mobile) {
|
2020-09-20 18:33:33 +08:00
|
|
|
// mobile
|
|
|
|
window.addEventListener('resize', () => leftPanelDisabled(767 >= window.innerWidth));
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2020-09-20 18:33:33 +08:00
|
|
|
$htmlCL.add('rl-mobile');
|
2020-08-15 02:35:39 +08:00
|
|
|
leftPanelDisabled(true);
|
2016-05-01 09:07:10 +08:00
|
|
|
}
|
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
leftPanelDisabled.subscribe((bValue) => {
|
2020-07-15 20:25:51 +08:00
|
|
|
$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) => {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.toggle('rl-left-panel-none', 'none' === sValue);
|
|
|
|
$htmlCL.toggle('rl-left-panel-short', 'short' === sValue);
|
2015-05-20 06:05:54 +08:00
|
|
|
});
|
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
leftPanelDisabled.valueHasMutated();
|
2016-04-29 04:32:54 +08:00
|
|
|
|
2016-09-13 04:50:21 +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 };
|