2016-09-13 04:50:21 +08:00
|
|
|
import ko from 'ko';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2021-11-01 18:24:11 +08:00
|
|
|
import { Settings, SettingsGet } from 'Common/Globals';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2021-01-27 19:02:37 +08:00
|
|
|
import { logoutLink } from 'Common/Links';
|
2021-01-27 17:59:15 +08:00
|
|
|
import { i18nToNodes, initOnStartOrLangChange } from 'Common/Translator';
|
2015-11-19 01:32:29 +08:00
|
|
|
|
2021-01-27 17:59:15 +08:00
|
|
|
import { LanguageStore } from 'Stores/Language';
|
2021-01-27 07:26:31 +08:00
|
|
|
import { ThemeStore } from 'Stores/Theme';
|
2016-09-13 04:50:21 +08:00
|
|
|
|
2021-01-27 17:59:15 +08:00
|
|
|
import { InputComponent } from 'Component/Input';
|
|
|
|
import { SelectComponent } from 'Component/Select';
|
|
|
|
import { TextAreaComponent } from 'Component/TextArea';
|
|
|
|
import { CheckboxMaterialDesignComponent } from 'Component/MaterialDesign/Checkbox';
|
|
|
|
import { CheckboxComponent } from 'Component/Checkbox';
|
2021-01-26 05:00:13 +08:00
|
|
|
|
2021-01-22 23:32:08 +08:00
|
|
|
export 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
|
|
|
*/
|
2021-01-26 05:00:13 +08:00
|
|
|
constructor(Remote) {
|
|
|
|
this.Remote = Remote;
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
2020-09-04 20:36:24 +08:00
|
|
|
logoutReload(close = false) {
|
2021-01-27 19:02:37 +08:00
|
|
|
const url = logoutLink();
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2020-09-04 20:36:24 +08:00
|
|
|
close && window.close && window.close();
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-01-27 19:02:37 +08:00
|
|
|
if (location.href !== url) {
|
|
|
|
setTimeout(() => (Settings.app('inIframe') ? parent : window).location.href = url, 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
|
|
|
|
2021-11-01 18:24:11 +08:00
|
|
|
refresh() {
|
|
|
|
// rl.adminArea() || !translatorReload(false, );
|
|
|
|
rl.adminArea() || LanguageStore.language(SettingsGet('Language'));
|
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
|
2015-11-19 01:32:29 +08:00
|
|
|
bootstart() {
|
2021-02-15 22:20:22 +08:00
|
|
|
const register = (key, ClassObject, templateID) => ko.components.register(key, {
|
2021-01-27 17:59:15 +08:00
|
|
|
template: { element: templateID || (key + 'Component') },
|
|
|
|
viewModel: {
|
|
|
|
createViewModel: (params, componentInfo) => {
|
|
|
|
params = params || {};
|
|
|
|
|
|
|
|
if (componentInfo && componentInfo.element) {
|
|
|
|
|
|
|
|
i18nToNodes(componentInfo.element);
|
|
|
|
|
2021-09-14 22:11:50 +08:00
|
|
|
if (params.inline) {
|
|
|
|
componentInfo.element.style.display = 'inline-block';
|
2021-01-27 17:59:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ClassObject(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-01-27 07:26:31 +08:00
|
|
|
|
|
|
|
register('Input', InputComponent);
|
|
|
|
register('Select', SelectComponent);
|
|
|
|
register('TextArea', TextAreaComponent);
|
2021-03-25 17:54:40 +08:00
|
|
|
register('Checkbox', CheckboxMaterialDesignComponent, 'CheckboxMaterialDesignComponent');
|
2021-01-27 17:59:15 +08:00
|
|
|
register('CheckboxSimple', CheckboxComponent, 'CheckboxComponent');
|
2014-08-20 23:03:12 +08:00
|
|
|
|
2021-01-04 19:08:41 +08:00
|
|
|
initOnStartOrLangChange();
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
LanguageStore.populate();
|
|
|
|
ThemeStore.populate();
|
2020-09-17 05:19:34 +08:00
|
|
|
|
2021-11-01 18:24:11 +08:00
|
|
|
this.start();
|
2020-09-17 05:19:34 +08:00
|
|
|
}
|
2015-11-19 01:32:29 +08:00
|
|
|
}
|