|
@@ -0,0 +1,110 @@
|
|
1
|
+/* global APP */
|
|
2
|
+
|
|
3
|
+import UIUtil from '../util/UIUtil';
|
|
4
|
+
|
|
5
|
+/**
|
|
6
|
+ * Show dialog which asks for required conference password.
|
|
7
|
+ * @returns {Promise<string>} password or nothing if user canceled
|
|
8
|
+ */
|
|
9
|
+export default class RequirePasswordDialog {
|
|
10
|
+ constructor() {
|
|
11
|
+ this.titleKey = 'dialog.passwordRequired';
|
|
12
|
+ this.labelKey = 'dialog.passwordLabel';
|
|
13
|
+ this.errorKey = 'dialog.incorrectPassword';
|
|
14
|
+ this.errorId = 'passwordRequiredError';
|
|
15
|
+ this.inputId = 'passwordRequiredInput';
|
|
16
|
+ this.inputErrorClass = 'error';
|
|
17
|
+ this.isOpened = false;
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ _registerListeners() {
|
|
21
|
+ let el = document.getElementById(this.inputId);
|
|
22
|
+ el.addEventListener('keypress', this._hideError.bind(this));
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ _getBodyMessage() {
|
|
26
|
+ let passMsg = APP.translation.translateString("dialog.password");
|
|
27
|
+ let label = APP.translation.translateString(this.labelKey);
|
|
28
|
+ let error = APP.translation.translateString(this.errorKey);
|
|
29
|
+ return (
|
|
30
|
+ `<div class="input-control">
|
|
31
|
+ <label class="input-control__label"
|
|
32
|
+ data-i18n="${this.labelKey}">${label}</label>
|
|
33
|
+ <input class="input-control__input" name="lockKey" type="text"
|
|
34
|
+ data-i18n="[placeholder]dialog.password"
|
|
35
|
+ placeholder="${passMsg}" autofocus id="${this.inputId}">
|
|
36
|
+ <p class="input-control__hint input-control__hint_error hide"
|
|
37
|
+ id="${this.errorId}"
|
|
38
|
+ data-i18n="${this.errorKey}">${error}</p>
|
|
39
|
+ </div>`
|
|
40
|
+ );
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ askForPassword() {
|
|
44
|
+ if (!this.isOpened) {
|
|
45
|
+ return this.open();
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ return new Promise((resolve, reject) => {
|
|
49
|
+ this.resolve = resolve;
|
|
50
|
+ this.reject = reject;
|
|
51
|
+ this._showError();
|
|
52
|
+ });
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ open() {
|
|
56
|
+ let { titleKey } = this;
|
|
57
|
+ let msgString = this._getBodyMessage();
|
|
58
|
+
|
|
59
|
+ return new Promise((resolve, reject) => {
|
|
60
|
+ this.resolve = resolve;
|
|
61
|
+ this.reject = reject;
|
|
62
|
+ let submitFunction = this._submitFunction.bind(this);
|
|
63
|
+ let closeFunction = this._closeFunction.bind(this);
|
|
64
|
+
|
|
65
|
+ APP.UI.messageHandler.openTwoButtonDialog({
|
|
66
|
+ titleKey,
|
|
67
|
+ msgString,
|
|
68
|
+ leftButtonKey: "dialog.Ok",
|
|
69
|
+ submitFunction,
|
|
70
|
+ closeFunction,
|
|
71
|
+ focus: ':input:first'
|
|
72
|
+ });
|
|
73
|
+
|
|
74
|
+ this._registerListeners();
|
|
75
|
+ this.isOpened = true;
|
|
76
|
+ });
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ _submitFunction(e, v, m, f) {
|
|
80
|
+ e.preventDefault();
|
|
81
|
+
|
|
82
|
+ if (v && f.lockKey) {
|
|
83
|
+ this.resolve(UIUtil.escapeHtml(f.lockKey));
|
|
84
|
+ } else {
|
|
85
|
+ this.reject(APP.UI.messageHandler.CANCEL);
|
|
86
|
+ }
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+ _closeFunction() {
|
|
90
|
+ this._hideError();
|
|
91
|
+ this.close();
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ _showError() {
|
|
95
|
+ let className = this.inputErrorClass;
|
|
96
|
+ document.getElementById(this.errorId).classList.remove('hide');
|
|
97
|
+ document.getElementById(this.inputId).classList.add(className);
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ _hideError() {
|
|
101
|
+ let className = this.inputErrorClass;
|
|
102
|
+ document.getElementById(this.errorId).classList.add('hide');
|
|
103
|
+ document.getElementById(this.inputId).classList.remove(className);
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ close() {
|
|
107
|
+ APP.UI.messageHandler.closeDialog();
|
|
108
|
+ this.isOpened = false;
|
|
109
|
+ }
|
|
110
|
+}
|