snappymail/dev/Knoin/AbstractViewNext.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
import {delegateRun, inFocus} from 'Common/Utils';
import {KeyState, EventKeyCode} from 'Common/Enums';
import {$win, keyScope} from 'Common/Globals';
2016-10-19 01:52:43 +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);
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() {
$win.on('keydown', (event) => {
if (event && this.modalVisibility && this.modalVisibility())
{
if (!this.bDisabeCloseOnEsc && EventKeyCode.Esc === event.keyCode)
{
delegateRun(this, 'cancelCommand');
return false;
}
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
}