Browse Source

Add Require password dialog

master
Ilya Daynatovich 8 years ago
parent
commit
257bb49c52

+ 2
- 1
css/_variables.scss View File

@@ -126,4 +126,5 @@ $selectActiveItemBg: $defaultDarkColor;
126 126
 $inputControlEmColor: #f29424;
127 127
 //buttons
128 128
 $linkFontColor: #489afe;
129
-$linkHoverFontColor: #287ade;
129
+$linkHoverFontColor: #287ade;
130
+$errorColor: #c61600;

+ 11
- 0
css/input-control/_input-control.scss View File

@@ -20,6 +20,8 @@
20 20
     }
21 21
 
22 22
     &__input {
23
+        margin-bottom: 8px;
24
+        @include transition(all .2s ease-in);
23 25
 
24 26
         &:last-child {
25 27
             margin-bottom: inherit;
@@ -28,6 +30,11 @@
28 30
         &::selection {
29 31
             background-color: $defaultDarkSelectionColor;
30 32
         }
33
+
34
+        &.error {
35
+            color: $errorColor;
36
+            border-color: $errorColor;
37
+        }
31 38
     }
32 39
 
33 40
     &__em {
@@ -41,6 +48,10 @@
41 48
         span {
42 49
             vertical-align: middle;
43 50
         }
51
+
52
+        &_error {
53
+            color: $errorColor;
54
+        }
44 55
     }
45 56
 
46 57
     &__container {

+ 1
- 0
lang/main.json View File

@@ -199,6 +199,7 @@
199 199
         "passwordError2": "This conversation isn't currently protected by a password. Only the owner of the conference can set a password.",
200 200
         "connectError": "Oops! Something went wrong and we couldn't connect to the conference.",
201 201
         "connectErrorWithMsg": "Oops! Something went wrong and we couldn't connect to the conference: __msg__",
202
+        "incorrectPassword": "Password is incorrect",
202 203
         "connecting": "Connecting",
203 204
         "copy": "Copy",
204 205
         "error": "Error",

+ 5
- 0
modules/UI/invite/Invite.js View File

@@ -46,6 +46,11 @@ class Invite {
46 46
             }
47 47
         });
48 48
 
49
+        this.conference.on(ConferenceEvents.CONFERENCE_JOINED, () => {
50
+            let roomLocker = this.getRoomLocker();
51
+            roomLocker.hideRequirePasswordDialog();
52
+        });
53
+
49 54
         APP.UI.addListener( UIEvents.INVITE_CLICKED,
50 55
                             () => { this.openLinkDialog(); });
51 56
 

+ 110
- 0
modules/UI/invite/RequirePasswordDialog.js View File

@@ -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
+}

+ 7
- 3
modules/UI/invite/RoomLocker.js View File

@@ -1,5 +1,5 @@
1 1
 /* global APP, JitsiMeetJS */
2
-import askForPassword from './AskForPassword';
2
+import RequirePasswordDialog from './RequirePasswordDialog';
3 3
 
4 4
 /**
5 5
  * Show notification that user cannot set password for the conference
@@ -31,7 +31,7 @@ const ConferenceErrors = JitsiMeetJS.errors.conference;
31 31
  */
32 32
 export default function createRoomLocker (room) {
33 33
     let password;
34
-
34
+    let requirePasswordDialog = new RequirePasswordDialog();
35 35
     /**
36 36
      * If the room was locked from someone other than us, we indicate it with
37 37
      * this property in order to have correct roomLocker state of isLocked.
@@ -104,7 +104,7 @@ export default function createRoomLocker (room) {
104 104
          * Asks user for required conference password.
105 105
          */
106 106
         requirePassword () {
107
-            return askForPassword().then(
107
+            return requirePasswordDialog.askForPassword().then(
108 108
                 newPass => { password = newPass; }
109 109
             ).catch(
110 110
                 reason => {
@@ -116,6 +116,10 @@ export default function createRoomLocker (room) {
116 116
                         console.error(reason);
117 117
                 }
118 118
             );
119
+        },
120
+
121
+        hideRequirePasswordDialog() {
122
+            requirePasswordDialog.close();
119 123
         }
120 124
     };
121 125
 }

Loading…
Cancel
Save