snappymail/dev/Knoin/AbstractViewNext.js

55 lines
1.2 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2019-07-05 03:19:24 +08:00
import { delegateRun, inFocus } from 'Common/Utils';
import { KeyState, EventKeyCode } from 'Common/Enums';
import { keyScope } from 'Common/Globals';
2019-07-05 03:19:24 +08:00
export class AbstractViewNext {
2016-09-10 06:38:16 +08:00
bDisabeCloseOnEsc = false;
sDefaultKeyScope = KeyState.None;
sCurrentKeyScope = KeyState.None;
2016-09-10 06:38:16 +08:00
viewModelVisibility = ko.observable(false);
2019-07-05 03:19:24 +08:00
modalVisibility = ko.observable(false).extend({ rateLimit: 0 });
2016-09-10 06:38:16 +08:00
viewModelName = '';
viewModelNames = [];
viewModelDom = null;
/**
* @returns {void}
*/
storeAndSetKeyScope() {
this.sCurrentKeyScope = keyScope();
keyScope(this.sDefaultKeyScope);
}
/**
* @returns {void}
*/
restoreKeyScope() {
keyScope(this.sCurrentKeyScope);
}
/**
* @returns {void}
*/
registerPopupKeyDown() {
addEventListener('keydown', (event) => {
2019-07-05 03:19:24 +08:00
if (event && this.modalVisibility && this.modalVisibility()) {
if (!this.bDisabeCloseOnEsc && EventKeyCode.Esc === event.keyCode) {
delegateRun(this, 'cancelCommand');
return false;
2019-07-05 03:19:24 +08:00
} else if (EventKeyCode.Backspace === event.keyCode && !inFocus()) {
return false;
}
}
return true;
});
}
cancelCommand() {} // eslint-disable-line no-empty-function
closeCommand() {} // eslint-disable-line no-empty-function
}