2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { delegateRun, inFocus } from 'Common/Utils';
|
|
|
|
import { KeyState, EventKeyCode } from 'Common/Enums';
|
2020-07-15 20:25:51 +08:00
|
|
|
import { keyScope } from 'Common/Globals';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
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-08-17 06:01:20 +08:00
|
|
|
|
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-08-17 06:01:20 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
viewModelName = '';
|
|
|
|
viewModelNames = [];
|
|
|
|
viewModelDom = null;
|
2016-08-17 06:01:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
storeAndSetKeyScope() {
|
|
|
|
this.sCurrentKeyScope = keyScope();
|
|
|
|
keyScope(this.sDefaultKeyScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
restoreKeyScope() {
|
|
|
|
keyScope(this.sCurrentKeyScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
registerPopupKeyDown() {
|
2020-08-12 06:25:36 +08:00
|
|
|
addEventListener('keydown', (event) => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (event && this.modalVisibility && this.modalVisibility()) {
|
|
|
|
if (!this.bDisabeCloseOnEsc && EventKeyCode.Esc === event.keyCode) {
|
2016-08-17 06:01:20 +08:00
|
|
|
delegateRun(this, 'cancelCommand');
|
|
|
|
return false;
|
2019-07-05 03:19:24 +08:00
|
|
|
} else if (EventKeyCode.Backspace === event.keyCode && !inFocus()) {
|
2016-08-17 06:01:20 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelCommand() {} // eslint-disable-line no-empty-function
|
|
|
|
closeCommand() {} // eslint-disable-line no-empty-function
|
|
|
|
}
|