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
43 * Whether the page is a subpage.
61 * Title for the page header and navigation menu.
66 return loadTimeData.getString('usersPageTitle');
71 * Name of the 'iron-icon' to show.
83 return this.$.addUserInput;
99 computed: 'computeEditingDisabled_(isOwner, isWhitelistManaged)'
102 editingUsersDisabled: {
104 computed: 'computeEditingUsersDisabled_(isOwner, isWhitelistManaged, ' +
105 'prefs.cros.accounts.allowGuest.value)'
114 created: function() {
115 chrome.usersPrivate.isCurrentUserOwner(function(isOwner) {
116 this.isOwner = isOwner;
119 chrome.usersPrivate.isWhitelistManaged(function(isWhitelistManaged) {
120 this.isWhitelistManaged = isWhitelistManaged;
125 * Regular expression for adding a user where the string provided is just the
126 * part before the "@".
127 * Email alias only, assuming it's a gmail address.
132 nameOnlyString_: '^\\s*([\\w\\.!#\\$%&\'\\*\\+-\\/=\\?\\^`\\{\\|\\}~]+)\\s*$',
135 * Regular expression for adding a user where the string provided is a full
137 * e.g. 'john@chromium.org'
142 '^\\s*([\\w\\.!#\\$%&\'\\*\\+-\\/=\\?\\^`\\{\\|\\}~]+)@' +
143 '([A-Za-z0-9\-]{2,63}\\..+)\\s*$',
146 addUser_: function() {
147 /** @const */ var nameOnlyRegex = new RegExp(this.nameOnlyString_);
148 /** @const */ var emailRegex = new RegExp(this.emailString_);
150 var userStr = this.$.addUserInput.value;
152 var matches = nameOnlyRegex.exec(userStr);
155 userEmail = matches[1] + '@gmail.com';
158 matches = emailRegex.exec(userStr);
160 userEmail = matches[1] + '@' + matches[2];
164 chrome.usersPrivate.addWhitelistedUser(
166 /* callback */ function(success) {});
167 this.$.addUserInput.value = '';
172 * @param {boolean} isOwner
173 * @param {boolean} isWhitelistManaged
176 computeHideOwnerLabel_: function(isOwner, isWhitelistManaged) {
177 return isOwner || isWhitelistManaged;
181 * @param {boolean} isOwner
182 * @param {boolean} isWhitelistManaged
185 computeHideManagedLabel_: function(isOwner, isWhitelistManaged) {
186 return !isWhitelistManaged;
190 * @param {boolean} isOwner
191 * @param {boolean} isWhitelistManaged
194 computeEditingDisabled_: function(isOwner, isWhitelistManaged) {
195 return !isOwner || isWhitelistManaged;
199 * @param {boolean} isOwner
200 * @param {boolean} isWhitelistManaged
201 * @param {boolean} allowGuest
204 computeEditingUsersDisabled_: function(
205 isOwner, isWhitelistManaged, allowGuest) {
206 return !isOwner || isWhitelistManaged || allowGuest;