2016-07-02 06:49:59 +08:00
|
|
|
import window from 'window';
|
|
|
|
import _ from '_';
|
2016-09-13 04:50:21 +08:00
|
|
|
import ko from 'ko';
|
2016-07-02 06:49:59 +08:00
|
|
|
import key from 'key';
|
2016-09-13 04:50:21 +08:00
|
|
|
import ssm from 'ssm';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
import {
|
2019-07-05 03:19:24 +08:00
|
|
|
$win,
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL,
|
2019-07-05 03:19:24 +08:00
|
|
|
leftPanelDisabled,
|
|
|
|
leftPanelType,
|
2020-07-22 14:17:02 +08:00
|
|
|
bMobileDevice
|
2016-06-07 05:57:52 +08:00
|
|
|
} from 'Common/Globals';
|
|
|
|
|
2019-10-17 06:43:04 +08:00
|
|
|
import { isNormal, pString, detectDropdownVisibility, windowResizeCallback } from 'Common/Utils';
|
2016-07-08 07:22:58 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { KeyState, Magics } from 'Common/Enums';
|
|
|
|
import { root, rootAdmin, rootUser, populateAuthSuffix } from 'Common/Links';
|
|
|
|
import { initOnStartOrLangChange, initNotificationLanguage } from 'Common/Translator';
|
2016-08-24 06:17:50 +08:00
|
|
|
import * as Events from 'Common/Events';
|
|
|
|
import * as Settings from 'Storage/Settings';
|
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';
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { routeOff, setHash } from 'Knoin/Knoin';
|
|
|
|
import { AbstractBoot } from 'Knoin/AbstractBoot';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
class AbstractApp extends AbstractBoot {
|
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() {
|
2015-11-19 01:32:29 +08:00
|
|
|
super();
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2016-06-28 04:54:38 +08:00
|
|
|
this.isLocalAutocomplete = true;
|
|
|
|
this.lastErrorTime = 0;
|
|
|
|
|
2020-07-15 20:25:51 +08:00
|
|
|
window.addEventListener('resize', () => {
|
2015-02-12 05:39:27 +08:00
|
|
|
Events.pub('window.resize');
|
|
|
|
});
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
Events.sub(
|
|
|
|
'window.resize',
|
|
|
|
_.throttle(() => {
|
|
|
|
const iH = $win.height(),
|
|
|
|
iW = $win.height();
|
2015-02-12 05:39:27 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if ($win.__sizes[0] !== iH || $win.__sizes[1] !== iW) {
|
|
|
|
$win.__sizes[0] = iH;
|
|
|
|
$win.__sizes[1] = iW;
|
2015-02-12 05:39:27 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
Events.pub('window.resize.real');
|
|
|
|
}
|
|
|
|
}, Magics.Time50ms)
|
|
|
|
);
|
2015-02-12 05:39:27 +08:00
|
|
|
|
2017-06-25 03:26:27 +08:00
|
|
|
// DEBUG
|
|
|
|
// Events.sub({
|
|
|
|
// 'window.resize': function() {
|
|
|
|
// window.console.log('window.resize');
|
|
|
|
// },
|
|
|
|
// 'window.resize.real': function() {
|
|
|
|
// window.console.log('window.resize.real');
|
|
|
|
// }
|
|
|
|
// });
|
2015-02-12 05:39:27 +08:00
|
|
|
|
2020-07-17 01:49:56 +08:00
|
|
|
const $doc = window.document;
|
|
|
|
$doc.addEventListener('keydown', (event) => {
|
|
|
|
if (event && event.ctrlKey) {
|
|
|
|
$htmlCL.add('rl-ctrl-key-pressed');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$doc.addEventListener('keyup', (event) => {
|
|
|
|
if (event && !event.ctrlKey) {
|
|
|
|
$htmlCL.remove('rl-ctrl-key-pressed');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const fn = _.debounce(() => {
|
|
|
|
Events.pub('rl.auto-logout-refresh');
|
|
|
|
}, Magics.Time5s);
|
|
|
|
$doc.addEventListener('mousemove', fn);
|
|
|
|
$doc.addEventListener('keypress', fn);
|
|
|
|
$doc.addEventListener('click', fn);
|
2015-03-16 05:58:50 +08:00
|
|
|
|
2016-07-08 07:22:58 +08:00
|
|
|
key('esc, enter', KeyState.All, () => {
|
2016-06-07 05:57:52 +08:00
|
|
|
detectDropdownVisibility();
|
2016-07-08 07:22:58 +08:00
|
|
|
});
|
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
|
|
|
|
2016-04-30 07:42:18 +08:00
|
|
|
getApplicationConfiguration(name, default_) {
|
|
|
|
return this.applicationConfiguration[name] || default_;
|
|
|
|
}
|
|
|
|
|
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) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (bMobileDevice) {
|
2015-11-19 01:32:29 +08:00
|
|
|
window.open(link, '_self');
|
2014-08-20 23:03:12 +08:00
|
|
|
window.focus();
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2020-07-17 01:49:56 +08:00
|
|
|
const oLink = window.document.createElement('a');
|
|
|
|
oLink.href = link;
|
|
|
|
window.document.body.appendChild(oLink).click();
|
|
|
|
oLink.remove();
|
|
|
|
// window.open(link, '_self');
|
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
|
|
|
|
2014-09-02 08:15:31 +08:00
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {string} title
|
2014-09-02 08:15:31 +08:00
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
setWindowTitle(title) {
|
2019-07-05 03:19:24 +08:00
|
|
|
title = isNormal(title) && 0 < title.length ? '' + title : '';
|
|
|
|
if (Settings.settingsGet('Title')) {
|
2015-11-19 01:32:29 +08:00
|
|
|
title += (title ? ' - ' : '') + Settings.settingsGet('Title');
|
2015-10-15 02:28:58 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
window.document.title = title;
|
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
redirectToAdminPanel() {
|
2016-07-01 06:50:11 +08:00
|
|
|
_.delay(() => {
|
2016-08-24 06:17:50 +08:00
|
|
|
window.location.href = rootAdmin();
|
|
|
|
}, Magics.Time100ms);
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-10-03 04:22:06 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
clearClientSideToken() {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (window.__rlah_clear) {
|
2014-10-06 02:37:31 +08:00
|
|
|
window.__rlah_clear();
|
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-10-06 02:37:31 +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) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (window.__rlah_set) {
|
2016-04-21 01:12:51 +08:00
|
|
|
window.__rlah_set(token);
|
2015-05-06 00:41:15 +08:00
|
|
|
|
2016-08-24 06:17:50 +08:00
|
|
|
Settings.settingsSet('AuthAccountHash', token);
|
|
|
|
populateAuthSuffix();
|
2015-05-06 00:41:15 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2015-05-06 00:41:15 +08:00
|
|
|
|
2014-08-20 23:03:12 +08:00
|
|
|
/**
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {boolean=} admin = false
|
|
|
|
* @param {boolean=} logout = false
|
|
|
|
* @param {boolean=} close = false
|
2014-08-20 23:03:12 +08:00
|
|
|
*/
|
2015-11-19 01:32:29 +08:00
|
|
|
loginAndLogoutReload(admin = false, logout = false, close = false) {
|
2016-07-16 01:38:11 +08:00
|
|
|
const inIframe = !!Settings.appSettingsGet('inIframe');
|
2016-06-07 05:57:52 +08:00
|
|
|
let customLogoutLink = pString(Settings.appSettingsGet('customLogoutLink'));
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (logout) {
|
2014-10-06 02:37:31 +08:00
|
|
|
this.clearClientSideToken();
|
|
|
|
}
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (logout && close && window.close) {
|
2014-08-20 23:03:12 +08:00
|
|
|
window.close();
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-24 06:17:50 +08:00
|
|
|
customLogoutLink = customLogoutLink || (admin ? rootAdmin() : rootUser());
|
2015-03-28 06:06:56 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (logout && window.location.href !== customLogoutLink) {
|
2015-11-19 01:32:29 +08:00
|
|
|
_.delay(() => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (inIframe && window.parent) {
|
2015-11-19 01:32:29 +08:00
|
|
|
window.parent.location.href = customLogoutLink;
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2015-11-19 01:32:29 +08:00
|
|
|
window.location.href = customLogoutLink;
|
2014-08-20 23:03:12 +08:00
|
|
|
}
|
2016-09-29 05:40:17 +08:00
|
|
|
|
|
|
|
$win.trigger('rl.tooltips.diactivate');
|
2016-08-24 06:17:50 +08:00
|
|
|
}, Magics.Time100ms);
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2016-07-08 07:22:58 +08:00
|
|
|
routeOff();
|
2016-08-24 06:17:50 +08:00
|
|
|
setHash(root(), true);
|
2016-07-08 07:22:58 +08:00
|
|
|
routeOff();
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
_.delay(() => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (inIframe && window.parent) {
|
2014-08-20 23:03:12 +08:00
|
|
|
window.parent.location.reload();
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2014-08-20 23:03:12 +08:00
|
|
|
window.location.reload();
|
|
|
|
}
|
2016-09-29 05:40:17 +08:00
|
|
|
|
|
|
|
$win.trigger('rl.tooltips.diactivate');
|
2016-08-24 06:17:50 +08:00
|
|
|
}, Magics.Time100ms);
|
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
|
|
|
historyBack() {
|
2014-08-20 23:03:12 +08:00
|
|
|
window.history.back();
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
bootstart() {
|
2016-06-07 05:57:52 +08:00
|
|
|
// log('Ps' + 'ss, hac' + 'kers! The' + 're\'s not' + 'hing inte' + 'resting :' + ')');
|
2015-07-30 02:13:49 +08:00
|
|
|
|
2014-08-22 23:08:56 +08:00
|
|
|
Events.pub('rl.bootstart');
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
const mobile = Settings.appSettingsGet('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('Radio', require('Component/Radio').default);
|
|
|
|
ko.components.register('TextArea', require('Component/TextArea').default);
|
|
|
|
ko.components.register('Date', require('Component/Date').default);
|
2014-10-30 05:08:53 +08:00
|
|
|
|
2017-03-01 02:44:13 +08:00
|
|
|
ko.components.register('x-script', require('Component/Script').default);
|
2017-06-25 03:26:27 +08:00
|
|
|
// ko.components.register('svg-icon', require('Component/SvgIcon').default);
|
2015-04-02 02:18:15 +08:00
|
|
|
|
2020-07-22 14:17:02 +08:00
|
|
|
if (Settings.appSettingsGet('materialDesign') && !bMobileDevice) {
|
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-06-25 03:26:27 +08:00
|
|
|
// ko.components.register('Checkbox', require('Component/Classic/Checkbox').default);
|
|
|
|
// ko.components.register('CheckboxSimple', require('Component/Classic/Checkbox').default);
|
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
|
|
|
|
2016-08-24 06:17:50 +08:00
|
|
|
_.delay(windowResizeCallback, Magics.Time1s);
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
Events.sub('ssm.mobile-enter', () => {
|
2016-06-07 05:57:52 +08:00
|
|
|
leftPanelDisabled(true);
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
2013-12-30 05:13:35 +08:00
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
Events.sub('ssm.mobile-leave', () => {
|
2016-06-07 05:57:52 +08:00
|
|
|
leftPanelDisabled(false);
|
2014-08-20 23:03:12 +08:00
|
|
|
});
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (!mobile) {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.add('rl-desktop');
|
2017-09-21 02:36:56 +08:00
|
|
|
|
2016-05-01 09:07:10 +08:00
|
|
|
ssm.addState({
|
|
|
|
id: 'mobile',
|
2016-07-30 03:14:51 +08:00
|
|
|
query: '(max-width: 767px)',
|
2016-05-01 09:07:10 +08:00
|
|
|
onEnter: () => {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.add('ssm-state-mobile');
|
2016-05-01 09:07:10 +08:00
|
|
|
Events.pub('ssm.mobile-enter');
|
|
|
|
},
|
|
|
|
onLeave: () => {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.remove('ssm-state-mobile');
|
2016-05-01 09:07:10 +08:00
|
|
|
Events.pub('ssm.mobile-leave');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ssm.addState({
|
|
|
|
id: 'tablet',
|
2016-07-30 03:14:51 +08:00
|
|
|
query: '(min-width: 768px) and (max-width: 999px)',
|
2016-08-24 06:17:50 +08:00
|
|
|
onEnter: () => {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.add('ssm-state-tablet');
|
2016-05-01 09:07:10 +08:00
|
|
|
},
|
2016-08-24 06:17:50 +08:00
|
|
|
onLeave: () => {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.remove('ssm-state-tablet');
|
2016-05-01 09:07:10 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ssm.addState({
|
|
|
|
id: 'desktop',
|
2016-07-30 03:14:51 +08:00
|
|
|
query: '(min-width: 1000px) and (max-width: 1400px)',
|
2016-05-01 09:07:10 +08:00
|
|
|
onEnter: () => {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.add('ssm-state-desktop');
|
2016-05-01 09:07:10 +08:00
|
|
|
},
|
|
|
|
onLeave: () => {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.remove('ssm-state-desktop');
|
2016-05-01 09:07:10 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ssm.addState({
|
|
|
|
id: 'desktop-large',
|
2016-07-30 03:14:51 +08:00
|
|
|
query: '(min-width: 1401px)',
|
2016-05-01 09:07:10 +08:00
|
|
|
onEnter: () => {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.add('ssm-state-desktop-large');
|
2016-05-01 09:07:10 +08:00
|
|
|
},
|
|
|
|
onLeave: () => {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.remove('ssm-state-desktop-large');
|
2016-05-01 09:07:10 +08:00
|
|
|
}
|
|
|
|
});
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2020-07-15 20:25:51 +08:00
|
|
|
$htmlCL.add('ssm-state-mobile', 'rl-mobile');
|
2016-05-01 09:07:10 +08:00
|
|
|
Events.pub('ssm.mobile-enter');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
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 };
|