2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
|
|
|
|
2022-02-17 16:36:29 +08:00
|
|
|
import { addObservablesTo, addComputablesTo, addSubscribablesTo } from 'External/ko';
|
2022-11-22 16:53:46 +08:00
|
|
|
import { keyScope, addShortcut, SettingsGet, leftPanelDisabled, toggleLeftPanel, elementById } from 'Common/Globals';
|
2022-03-08 19:28:16 +08:00
|
|
|
import { ViewTypePopup, showScreenPopup } from 'Knoin/Knoin';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2022-09-26 20:02:30 +08:00
|
|
|
import { SaveSettingStatus } from 'Common/Enums';
|
2022-02-28 17:38:47 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
class AbstractView {
|
2021-09-23 15:41:02 +08:00
|
|
|
constructor(templateID, type)
|
2021-01-24 17:25:23 +08:00
|
|
|
{
|
2021-10-11 20:31:54 +08:00
|
|
|
// Object.defineProperty(this, 'viewModelTemplateID', { value: templateID });
|
2022-03-08 19:28:16 +08:00
|
|
|
this.viewModelTemplateID = templateID || this.constructor.name.replace('UserView', '');
|
2021-09-23 02:17:44 +08:00
|
|
|
this.viewType = type;
|
|
|
|
this.viewModelDom = null;
|
2021-03-16 23:06:16 +08:00
|
|
|
|
2021-09-23 02:17:44 +08:00
|
|
|
this.keyScope = {
|
2022-03-07 20:47:03 +08:00
|
|
|
scope: 'none',
|
|
|
|
previous: 'none',
|
2021-09-23 02:17:44 +08:00
|
|
|
set: function() {
|
|
|
|
this.previous = keyScope();
|
|
|
|
keyScope(this.scope);
|
|
|
|
},
|
|
|
|
unset: function() {
|
|
|
|
keyScope(this.previous);
|
|
|
|
}
|
|
|
|
};
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 02:17:44 +08:00
|
|
|
/*
|
|
|
|
onBuild() {}
|
2022-03-11 17:26:25 +08:00
|
|
|
beforeShow() {} // Happens before: hidden = false
|
2022-02-25 19:11:32 +08:00
|
|
|
onShow() {} // Happens after: hidden = false
|
2021-09-23 02:17:44 +08:00
|
|
|
onHide() {}
|
|
|
|
*/
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
querySelector(selectors) {
|
|
|
|
return this.viewModelDom.querySelector(selectors);
|
|
|
|
}
|
|
|
|
|
|
|
|
addObservables(observables) {
|
2021-03-16 17:59:47 +08:00
|
|
|
addObservablesTo(this, observables);
|
2021-01-24 17:25:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
addComputables(computables) {
|
2021-03-16 17:59:47 +08:00
|
|
|
addComputablesTo(this, computables);
|
2021-01-24 17:25:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
addSubscribables(subscribables) {
|
2021-03-16 17:59:47 +08:00
|
|
|
addSubscribablesTo(this, subscribables);
|
2021-01-24 17:25:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export class AbstractViewPopup extends AbstractView
|
|
|
|
{
|
|
|
|
constructor(name)
|
|
|
|
{
|
2022-03-08 19:28:16 +08:00
|
|
|
super('Popups' + name, ViewTypePopup);
|
2022-02-25 05:40:17 +08:00
|
|
|
this.keyScope.scope = name;
|
2022-02-26 08:06:18 +08:00
|
|
|
this.modalVisible = ko.observable(false).extend({ rateLimit: 0 });
|
2023-02-15 02:04:14 +08:00
|
|
|
this.close = () => this.modalVisible(false);
|
2022-11-05 19:07:26 +08:00
|
|
|
addShortcut('escape,close', '', name, () => {
|
2022-02-26 17:33:11 +08:00
|
|
|
if (this.modalVisible() && false !== this.onClose()) {
|
2022-03-04 16:21:24 +08:00
|
|
|
this.close();
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2022-09-07 01:22:53 +08:00
|
|
|
return false;
|
|
|
|
// return true; Issue with supported modal close
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2022-02-25 05:40:17 +08:00
|
|
|
}
|
|
|
|
|
2022-02-25 20:13:09 +08:00
|
|
|
// Happens when user hits Escape or Close key
|
2022-02-26 17:33:11 +08:00
|
|
|
// return false to prevent closing
|
|
|
|
onClose() {}
|
2022-02-25 05:40:17 +08:00
|
|
|
|
|
|
|
/*
|
2022-03-11 17:26:25 +08:00
|
|
|
beforeShow() {} // Happens before showModal()
|
2022-04-05 17:06:22 +08:00
|
|
|
onShow() {} // Happens after showModal()
|
|
|
|
afterShow() {} // Happens after showModal() animation transitionend
|
|
|
|
onHide() {} // Happens before animation transitionend
|
|
|
|
afterHide() {} // Happens after animation transitionend
|
2022-02-25 05:40:17 +08:00
|
|
|
*/
|
2021-01-24 17:25:23 +08:00
|
|
|
}
|
2022-02-07 22:20:39 +08:00
|
|
|
|
|
|
|
AbstractViewPopup.showModal = function(params = []) {
|
2022-02-04 16:49:55 +08:00
|
|
|
showScreenPopup(this, params);
|
|
|
|
}
|
2022-02-07 22:20:39 +08:00
|
|
|
|
2022-02-04 16:49:55 +08:00
|
|
|
AbstractViewPopup.hidden = function() {
|
2022-02-26 08:06:18 +08:00
|
|
|
return !this.__vm || !this.__vm.modalVisible();
|
2022-02-04 16:49:55 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
export class AbstractViewLeft extends AbstractView
|
|
|
|
{
|
2021-09-23 15:41:02 +08:00
|
|
|
constructor(templateID)
|
2021-01-24 17:25:23 +08:00
|
|
|
{
|
2022-10-10 19:52:56 +08:00
|
|
|
super(templateID, 'left');
|
2021-11-08 04:19:48 +08:00
|
|
|
this.leftPanelDisabled = leftPanelDisabled;
|
2022-11-22 16:53:46 +08:00
|
|
|
this.toggleLeftPanel = toggleLeftPanel;
|
2020-10-26 19:54:03 +08:00
|
|
|
}
|
2021-01-24 17:25:23 +08:00
|
|
|
}
|
2020-10-26 19:54:03 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
export class AbstractViewRight extends AbstractView
|
|
|
|
{
|
2021-09-23 15:41:02 +08:00
|
|
|
constructor(templateID)
|
2021-01-24 17:25:23 +08:00
|
|
|
{
|
2022-10-10 19:52:56 +08:00
|
|
|
super(templateID, 'right');
|
2020-10-26 19:54:03 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2021-09-23 02:17:44 +08:00
|
|
|
|
|
|
|
export class AbstractViewSettings
|
|
|
|
{
|
2022-02-28 17:38:47 +08:00
|
|
|
/*
|
2021-09-23 02:17:44 +08:00
|
|
|
onBuild(viewModelDom) {}
|
2022-03-11 17:26:25 +08:00
|
|
|
beforeShow() {}
|
2021-09-23 02:17:44 +08:00
|
|
|
onShow() {}
|
|
|
|
onHide() {}
|
|
|
|
viewModelDom
|
|
|
|
*/
|
2022-02-28 17:38:47 +08:00
|
|
|
addSetting(name, valueCb)
|
|
|
|
{
|
2022-02-28 23:10:23 +08:00
|
|
|
let prop = name[0].toLowerCase() + name.slice(1),
|
2022-02-28 17:38:47 +08:00
|
|
|
trigger = prop + 'Trigger';
|
|
|
|
addObservablesTo(this, {
|
|
|
|
[prop]: SettingsGet(name),
|
2022-09-26 20:02:30 +08:00
|
|
|
[trigger]: SaveSettingStatus.Idle,
|
2022-02-28 17:38:47 +08:00
|
|
|
});
|
|
|
|
addSubscribablesTo(this, {
|
|
|
|
[prop]: (value => {
|
2022-09-26 20:02:30 +08:00
|
|
|
this[trigger](SaveSettingStatus.Saving);
|
2022-09-02 17:52:07 +08:00
|
|
|
valueCb?.(value);
|
2022-02-28 17:38:47 +08:00
|
|
|
rl.app.Remote.saveSetting(name, value,
|
|
|
|
iError => {
|
2022-09-26 20:02:30 +08:00
|
|
|
this[trigger](iError ? SaveSettingStatus.Failed : SaveSettingStatus.Success);
|
|
|
|
setTimeout(() => this[trigger](SaveSettingStatus.Idle), 1000);
|
2022-02-28 17:38:47 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}).debounce(999),
|
|
|
|
});
|
|
|
|
}
|
2022-03-01 17:18:12 +08:00
|
|
|
|
|
|
|
addSettings(names)
|
|
|
|
{
|
|
|
|
names.forEach(name => {
|
|
|
|
let prop = name[0].toLowerCase() + name.slice(1);
|
|
|
|
this[prop] || (this[prop] = ko.observable(SettingsGet(name)));
|
|
|
|
this[prop].subscribe(value => rl.app.Remote.saveSetting(name, value));
|
|
|
|
});
|
|
|
|
}
|
2022-02-28 17:38:47 +08:00
|
|
|
}
|
2021-11-08 00:06:08 +08:00
|
|
|
|
2022-03-08 19:28:16 +08:00
|
|
|
export class AbstractViewLogin extends AbstractView {
|
2021-11-08 00:06:08 +08:00
|
|
|
constructor(templateID) {
|
2022-10-10 19:52:56 +08:00
|
|
|
super(templateID, 'content');
|
2021-11-08 00:06:08 +08:00
|
|
|
this.formError = ko.observable(false).extend({ falseTimeout: 500 });
|
|
|
|
}
|
|
|
|
|
|
|
|
onBuild(dom) {
|
|
|
|
dom.classList.add('LoginView');
|
|
|
|
}
|
|
|
|
|
|
|
|
onShow() {
|
2022-05-20 03:16:00 +08:00
|
|
|
elementById('rl-left').hidden = true;
|
|
|
|
elementById('rl-right').hidden = true;
|
2021-11-08 00:06:08 +08:00
|
|
|
rl.route.off();
|
|
|
|
}
|
|
|
|
|
2022-05-20 03:16:00 +08:00
|
|
|
onHide() {
|
|
|
|
elementById('rl-left').hidden = false;
|
|
|
|
elementById('rl-right').hidden = false;
|
|
|
|
}
|
|
|
|
|
2021-11-08 00:06:08 +08:00
|
|
|
submitForm() {
|
|
|
|
// return false;
|
|
|
|
}
|
|
|
|
}
|