mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 14:37:02 +03:00
Replace viewDecorator and popupDecorator with proper AbstractView classes
This commit is contained in:
parent
51958babba
commit
864da66b5f
38 changed files with 202 additions and 359 deletions
110
dev/Knoin/AbstractViews.js
Normal file
110
dev/Knoin/AbstractViews.js
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { inFocus } from 'Common/Utils';
|
||||
import { KeyState } from 'Common/Enums';
|
||||
import { keyScope } from 'Common/Globals';
|
||||
import { ViewType } from 'Knoin/Knoin';
|
||||
|
||||
class AbstractView {
|
||||
bDisabeCloseOnEsc = false;
|
||||
sDefaultKeyScope = KeyState.None;
|
||||
sCurrentKeyScope = KeyState.None;
|
||||
|
||||
viewModelVisible = false;
|
||||
modalVisibility = ko.observable(false).extend({ rateLimit: 0 });
|
||||
|
||||
viewModelName = '';
|
||||
viewModelDom = null;
|
||||
|
||||
constructor(name, templateID, type)
|
||||
{
|
||||
this.viewModelName = 'View/' + name;
|
||||
this.viewModelTemplateID = templateID;
|
||||
this.viewModelPosition = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
storeAndSetKeyScope() {
|
||||
this.sCurrentKeyScope = keyScope();
|
||||
keyScope(this.sDefaultKeyScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
restoreKeyScope() {
|
||||
keyScope(this.sCurrentKeyScope);
|
||||
}
|
||||
|
||||
cancelCommand() {} // eslint-disable-line no-empty-function
|
||||
closeCommand() {} // eslint-disable-line no-empty-function
|
||||
|
||||
querySelector(selectors) {
|
||||
return this.viewModelDom.querySelector(selectors);
|
||||
}
|
||||
|
||||
addObservables(observables) {
|
||||
ko.addObservablesTo(this, observables);
|
||||
}
|
||||
|
||||
addComputables(computables) {
|
||||
ko.addComputablesTo(this, computables);
|
||||
}
|
||||
|
||||
addSubscribables(subscribables) {
|
||||
ko.addSubscribablesTo(this, subscribables);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class AbstractViewPopup extends AbstractView
|
||||
{
|
||||
constructor(name)
|
||||
{
|
||||
super('Popup/' + name, 'Popups' + name, ViewType.Popup);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
registerPopupKeyDown() {
|
||||
addEventListener('keydown', event => {
|
||||
if (event && this.modalVisibility && this.modalVisibility()) {
|
||||
if (!this.bDisabeCloseOnEsc && 'Escape' == event.key) {
|
||||
this.cancelCommand && this.cancelCommand();
|
||||
return false;
|
||||
} else if ('Backspace' == event.key && !inFocus()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class AbstractViewCenter extends AbstractView
|
||||
{
|
||||
constructor(name, templateID)
|
||||
{
|
||||
super(name, templateID, ViewType.Center);
|
||||
}
|
||||
}
|
||||
|
||||
export class AbstractViewLeft extends AbstractView
|
||||
{
|
||||
constructor(name, templateID)
|
||||
{
|
||||
super(name, templateID, ViewType.Left);
|
||||
}
|
||||
}
|
||||
|
||||
export class AbstractViewRight extends AbstractView
|
||||
{
|
||||
constructor(name, templateID)
|
||||
{
|
||||
super(name, templateID, ViewType.Right);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue