Completed
Push — master ( 2f8415...e6e0b0 )
by Rain
02:22
created

dev/Knoin/AbstractViewNext.js   A

Size

Lines of Code 63

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
nc 1
dl 0
loc 63
rs 10
noi 0
1
2
import ko from 'ko';
3
4
import {delegateRun, inFocus} from 'Common/Utils';
5
import {KeyState, EventKeyCode} from 'Common/Enums';
6
import {$win, keyScope} from 'Common/Globals';
7
8
class AbstractViewNext
9
{
10
	bDisabeCloseOnEsc = false;
11
	sDefaultKeyScope = KeyState.None;
12
	sCurrentKeyScope = KeyState.None;
13
14
	viewModelVisibility = ko.observable(false);
15
	modalVisibility = ko.observable(false).extend({rateLimit: 0});
16
17
	viewModelName = '';
18
	viewModelNames = [];
19
	viewModelDom = null;
20
21
	/**
22
	 * @returns {void}
23
	 */
24
	storeAndSetKeyScope() {
25
		this.sCurrentKeyScope = keyScope();
26
		keyScope(this.sDefaultKeyScope);
27
	}
28
29
	/**
30
	 * @returns {void}
31
	 */
32
	restoreKeyScope() {
33
		keyScope(this.sCurrentKeyScope);
34
	}
35
36
	/**
37
	 * @returns {void}
38
	 */
39
	registerPopupKeyDown() {
40
		$win.on('keydown', (event) => {
41
			if (event && this.modalVisibility && this.modalVisibility())
42
			{
43
				if (!this.bDisabeCloseOnEsc && EventKeyCode.Esc === event.keyCode)
44
				{
45
					delegateRun(this, 'cancelCommand');
46
					return false;
47
				}
48
				else if (EventKeyCode.Backspace === event.keyCode && !inFocus())
49
				{
50
					return false;
51
				}
52
			}
53
54
			return true;
55
		});
56
	}
57
58
	cancelCommand() {} // eslint-disable-line no-empty-function
59
	closeCommand() {} // eslint-disable-line no-empty-function
60
}
61
62
export {AbstractViewNext, AbstractViewNext as default};
63