1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * 'cr-settings-users-page' is the settings page for managing user accounts on
12 * <neon-animated-pages>
13 * <cr-settings-users-page prefs="{{prefs}}">
14 * </cr-settings-users-page>
16 * </neon-animated-pages>
18 * @group Chrome Settings Elements
19 * @element cr-settings-users-page
22 is
: 'cr-settings-users-page',
25 Polymer
.IronA11yKeysBehavior
41 return this.$.addUserInput
;
57 computed
: 'computeEditingDisabled_(isOwner, isWhitelistManaged)'
60 editingUsersDisabled
: {
62 computed
: 'computeEditingUsersDisabled_(isOwner, isWhitelistManaged, ' +
63 'prefs.cros.accounts.allowGuest.value)'
73 chrome
.usersPrivate
.isCurrentUserOwner(function(isOwner
) {
74 this.isOwner
= isOwner
;
77 chrome
.usersPrivate
.isWhitelistManaged(function(isWhitelistManaged
) {
78 this.isWhitelistManaged
= isWhitelistManaged
;
83 * Regular expression for adding a user where the string provided is just the
84 * part before the "@".
85 * Email alias only, assuming it's a gmail address.
90 nameOnlyString_
: '^\\s*([\\w\\.!#\\$%&\'\\*\\+-\\/=\\?\\^`\\{\\|\\}~]+)\\s*$',
93 * Regular expression for adding a user where the string provided is a full
95 * e.g. 'john@chromium.org'
100 '^\\s*([\\w\\.!#\\$%&\'\\*\\+-\\/=\\?\\^`\\{\\|\\}~]+)@' +
101 '([A-Za-z0-9\-]{2,63}\\..+)\\s*$',
104 addUser_: function() {
105 /** @const */ var nameOnlyRegex
= new RegExp(this.nameOnlyString_
);
106 /** @const */ var emailRegex
= new RegExp(this.emailString_
);
108 var userStr
= this.$.addUserInput
.value
;
110 var matches
= nameOnlyRegex
.exec(userStr
);
113 userEmail
= matches
[1] + '@gmail.com';
116 matches
= emailRegex
.exec(userStr
);
118 userEmail
= matches
[1] + '@' + matches
[2];
122 chrome
.usersPrivate
.addWhitelistedUser(
124 /* callback */ function(success
) {});
125 this.$.addUserInput
.value
= '';
130 * @param {boolean} isOwner
131 * @param {boolean} isWhitelistManaged
134 computeHideOwnerLabel_: function(isOwner
, isWhitelistManaged
) {
135 return isOwner
|| isWhitelistManaged
;
139 * @param {boolean} isOwner
140 * @param {boolean} isWhitelistManaged
143 computeHideManagedLabel_: function(isOwner
, isWhitelistManaged
) {
144 return !isWhitelistManaged
;
148 * @param {boolean} isOwner
149 * @param {boolean} isWhitelistManaged
152 computeEditingDisabled_: function(isOwner
, isWhitelistManaged
) {
153 return !isOwner
|| isWhitelistManaged
;
157 * @param {boolean} isOwner
158 * @param {boolean} isWhitelistManaged
159 * @param {boolean} allowGuest
162 computeEditingUsersDisabled_: function(
163 isOwner
, isWhitelistManaged
, allowGuest
) {
164 return !isOwner
|| isWhitelistManaged
|| allowGuest
;