Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-users-add-user-dialog' is the dialog shown for adding new allowed | 7 * 'settings-users-add-user-dialog' is the dialog shown for adding new allowed |
| 8 * users to a ChromeOS device. | 8 * users to a ChromeOS device. |
| 9 */ | 9 */ |
| 10 (function() { | 10 (function() { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 * e.g. 'john@chromium.org' | 25 * e.g. 'john@chromium.org' |
| 26 * @const {!RegExp} | 26 * @const {!RegExp} |
| 27 */ | 27 */ |
| 28 var EMAIL_REGEX = new RegExp( | 28 var EMAIL_REGEX = new RegExp( |
| 29 '^\\s*([\\w\\.!#\\$%&\'\\*\\+-\\/=\\?\\^`\\{\\|\\}~]+)@' + | 29 '^\\s*([\\w\\.!#\\$%&\'\\*\\+-\\/=\\?\\^`\\{\\|\\}~]+)@' + |
| 30 '([A-Za-z0-9\-]{2,63}\\..+)\\s*$'); | 30 '([A-Za-z0-9\-]{2,63}\\..+)\\s*$'); |
| 31 | 31 |
| 32 Polymer({ | 32 Polymer({ |
| 33 is: 'settings-users-add-user-dialog', | 33 is: 'settings-users-add-user-dialog', |
| 34 | 34 |
| 35 properties: { | |
| 36 /** @private */ | |
| 37 isValid_: { | |
| 38 type: Boolean, | |
| 39 value: false, | |
| 40 }, | |
| 41 }, | |
| 42 | |
| 35 open: function() { | 43 open: function() { |
| 44 this.isValid_ = false; | |
| 36 this.$.dialog.showModal(); | 45 this.$.dialog.showModal(); |
| 37 }, | 46 }, |
| 38 | 47 |
| 39 /** @private */ | 48 /** @private */ |
| 40 onCancelTap_: function() { | 49 onCancelTap_: function() { |
| 41 this.$.dialog.cancel(); | 50 this.$.dialog.cancel(); |
| 42 }, | 51 }, |
| 43 | 52 |
| 44 /** | 53 /** |
| 45 * Validates that the new user entered is valid. | 54 * Validates that the new user entered is valid. |
| 46 * @private | 55 * @private |
| 47 * @return {boolean} | 56 * @return {boolean} |
| 48 */ | 57 */ |
| 49 validate_: function() { | 58 validate_: function() { |
| 50 var input = this.$.addUserInput.value; | 59 var input = this.$.addUserInput.value; |
| 51 var valid = NAME_ONLY_REGEX.test(input) || EMAIL_REGEX.test(input); | 60 this.isValid_ = NAME_ONLY_REGEX.test(input) || EMAIL_REGEX.test(input); |
| 52 | 61 return this.isValid_; |
| 53 this.$.add.disabled = !valid; | |
| 54 this.$.addUserInput.invalid = !valid; | |
| 55 return valid; | |
| 56 }, | 62 }, |
| 57 | 63 |
| 58 /** @private */ | 64 /** @private */ |
| 59 addUser_: function() { | 65 addUser_: function() { |
| 60 // May be submitted by the Enter key even if the input value is invalid. | 66 // May be submitted by the Enter key even if the input value is invalid. |
|
dpapad
2017/04/11 00:03:55
@Tommy: Is this possible anymore, now that cr-dial
stevenjb
2017/04/11 00:44:22
Do let me know about this, I'll take that into con
| |
| 61 if (!this.validate_()) | 67 if (!this.validate_()) |
| 62 return; | 68 return; |
| 63 | 69 |
| 64 var input = this.$.addUserInput.value; | 70 var input = this.$.addUserInput.value; |
| 65 | 71 |
| 66 var nameOnlyMatches = NAME_ONLY_REGEX.exec(input); | 72 var nameOnlyMatches = NAME_ONLY_REGEX.exec(input); |
| 67 var userEmail; | 73 var userEmail; |
| 68 if (nameOnlyMatches) { | 74 if (nameOnlyMatches) { |
| 69 userEmail = nameOnlyMatches[1] + '@gmail.com'; | 75 userEmail = nameOnlyMatches[1] + '@gmail.com'; |
| 70 } else { | 76 } else { |
| 71 var emailMatches = EMAIL_REGEX.exec(input); | 77 var emailMatches = EMAIL_REGEX.exec(input); |
| 72 // Assuming the input validated, one of these two must match. | 78 // Assuming the input validated, one of these two must match. |
| 73 assert(emailMatches); | 79 assert(emailMatches); |
| 74 userEmail = emailMatches[1] + '@' + emailMatches[2]; | 80 userEmail = emailMatches[1] + '@' + emailMatches[2]; |
| 75 } | 81 } |
| 76 | 82 |
| 77 chrome.usersPrivate.addWhitelistedUser( | 83 chrome.usersPrivate.addWhitelistedUser( |
| 78 userEmail, | 84 userEmail, |
| 79 /* callback */ function(success) {}); | 85 /* callback */ function(success) {}); |
| 80 this.$.addUserInput.value = ''; | 86 this.$.addUserInput.value = ''; |
| 81 this.$.dialog.close(); | 87 this.$.dialog.close(); |
| 82 }, | 88 }, |
| 83 }); | 89 }); |
| 84 | 90 |
| 85 })(); | 91 })(); |
| OLD | NEW |