Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: chrome/browser/resources/md_user_manager/create_profile.js

Issue 1826903002: updated UI, default profile name, check for existing supervised user before create (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated browser tests Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 'create-profile' is a page that contains controls for creating 6 * @fileoverview 'create-profile' is a page that contains controls for creating
7 * a (optionally supervised) profile, including choosing a name, and an avatar. 7 * a (optionally supervised) profile, including choosing a name, and an avatar.
8 */ 8 */
9 (function() {
10 /**
11 * It means the sentinel menu item is selected.
12 * @const {number}
13 */
14 var NO_USER_SELECTED = -1;
15
9 Polymer({ 16 Polymer({
10 is: 'create-profile', 17 is: 'create-profile',
11 18
12 behaviors: [ 19 behaviors: [
13 I18nBehavior, 20 I18nBehavior,
14 WebUIListenerBehavior 21 WebUIListenerBehavior
15 ], 22 ],
16 23
17 properties: { 24 properties: {
18 /** 25 /**
19 * True if supervised user checkbox is disabled.
20 * @private {boolean}
21 */
22 supervisedUserCheckboxDisabled_: {
23 type: Boolean,
24 computed:
25 'isSupervisedUserCheckboxDisabled_(createInProgress_, signedIn_)'
26 },
27
28 /**
29 * The current profile name. 26 * The current profile name.
30 * @private {string} 27 * @private {string}
31 */ 28 */
32 profileName_: { 29 profileName_: {
33 type: String, 30 type: String,
34 value: '', 31 value: ''
35 }, 32 },
36 33
37 /** 34 /**
38 * The list of available profile icon URLs. 35 * The list of available profile icon URLs.
39 * @private {!Array<string>} 36 * @private {!Array<string>}
40 */ 37 */
41 availableIconUrls_: { 38 availableIconUrls_: {
42 type: Array, 39 type: Array,
43 value: function() { return []; } 40 value: function() { return []; }
44 }, 41 },
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 */ 82 */
86 signedInUsers_: { 83 signedInUsers_: {
87 type: Array, 84 type: Array,
88 value: function() { return []; } 85 value: function() { return []; }
89 }, 86 },
90 87
91 /** 88 /**
92 * Index of the selected signed-in user. 89 * Index of the selected signed-in user.
93 * @private {number} 90 * @private {number}
94 */ 91 */
95 selectedEmail_: { 92 signedInUserIndex_: {
96 type: Number, 93 type: Number,
97 value: 0 94 value: NO_USER_SELECTED
98 }, 95 },
99 96
100 /** @private {!signin.ProfileBrowserProxy} */ 97 /** @private {!signin.ProfileBrowserProxy} */
101 browserProxy_: Object 98 browserProxy_: Object
102 }, 99 },
103 100
104 /** @override */ 101 /** @override */
105 created: function() { 102 created: function() {
106 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance(); 103 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance();
107 }, 104 },
108 105
109 /** @override */ 106 /** @override */
110 attached: function() { 107 ready: function() {
111 this.resetForm_();
112
113 this.addWebUIListener( 108 this.addWebUIListener(
114 'create-profile-success', this.handleSuccess_.bind(this)); 109 'create-profile-success', this.handleSuccess_.bind(this));
115 this.addWebUIListener( 110 this.addWebUIListener(
116 'create-profile-warning', this.handleMessage_.bind(this)); 111 'create-profile-warning', this.handleMessage_.bind(this));
117 this.addWebUIListener( 112 this.addWebUIListener(
118 'create-profile-error', this.handleMessage_.bind(this)); 113 'create-profile-error', this.handleMessage_.bind(this));
119 this.addWebUIListener( 114 this.addWebUIListener(
120 'profile-icons-received', this.handleProfileIcons_.bind(this)); 115 'profile-icons-received', this.handleProfileIcons_.bind(this));
121 this.addWebUIListener( 116 this.addWebUIListener(
117 'profile-defaults-received', this.handleProfileDefaults_.bind(this));
118 this.addWebUIListener(
122 'signedin-users-received', this.handleSignedInUsers_.bind(this)); 119 'signedin-users-received', this.handleSignedInUsers_.bind(this));
123 120
124 this.browserProxy_.getAvailableIcons(); 121 this.browserProxy_.getAvailableIcons();
125 this.browserProxy_.getSignedInUsers(); 122 this.browserProxy_.getSignedInUsers();
123
124 // Alias on 'this' to use in html.
125 this.NO_USER_SELECTED = NO_USER_SELECTED;
126 }, 126 },
127 127
128 /** 128 /**
129 * Resets the state of the page.
130 * @private
131 */
132 resetForm_: function() {
133 this.profileName_ = '';
134 this.availableIconUrls_ = [];
135 this.profileIconUrl_ = '';
136 this.createInProgress_ = false;
137 this.message_ = '';
138 this.isSupervised_ = false;
139 this.signedInUsers_ = [];
140 this.selectedEmail_ = 0;
141 },
142
143 /**
144 * Handler for when the profile icons are pushed from the browser. 129 * Handler for when the profile icons are pushed from the browser.
145 * @param {!Array<string>} iconUrls 130 * @param {!Array<string>} iconUrls
146 * @private 131 * @private
147 */ 132 */
148 handleProfileIcons_: function(iconUrls) { 133 handleProfileIcons_: function(iconUrls) {
149 this.availableIconUrls_ = iconUrls; 134 this.availableIconUrls_ = iconUrls;
150 this.profileIconUrl_ = iconUrls[0]; 135 this.profileIconUrl_ = iconUrls[0];
151 }, 136 },
152 137
153 /** 138 /**
154 * Updates the signed-in users. 139 * Handler for when the profile defaults are pushed from the browser.
140 * @param {ProfileInfo} profileInfo Default Info for the new profile.
141 * @private
142 */
143 handleProfileDefaults_: function(profileInfo) {
144 this.profileName_ = profileInfo.name;
145 },
146
147 /**
148 * Handler for when signed-in users are pushed from the browser.
155 * @param {!Array<SignedInUser>} signedInUsers 149 * @param {!Array<SignedInUser>} signedInUsers
156 * @private 150 * @private
157 */ 151 */
158 handleSignedInUsers_: function(signedInUsers) { 152 handleSignedInUsers_: function(signedInUsers) {
159 this.signedInUsers_ = signedInUsers; 153 this.signedInUsers_ = signedInUsers;
160 this.signedIn_ = signedInUsers.length > 0;
161 }, 154 },
162 155
163 /** 156 /**
164 * Handler for the 'Learn More' button click event. 157 * Returns the currently selected signed-in user.
158 * @return {SignedInUser}
159 * @private
160 */
161 signedInUser_: function(signedInUserIndex) {
162 return this.signedInUsers_[signedInUserIndex];
Dan Beam 2016/04/06 06:45:19 nit: can't this technically return undefined as we
Moe 2016/04/07 14:36:40 Done.
163 },
164
165 /**
166 * Handler for the 'Learn More' link tap event.
165 * @param {!Event} event 167 * @param {!Event} event
166 * @private 168 * @private
167 */ 169 */
168 onLearnMoreTap_: function(event) { 170 onLearnMoreTap_: function(event) {
169 this.fire('change-page', {page: 'supervised-learn-more-page'}); 171 this.fire('change-page', {page: 'supervised-learn-more-page'});
170 }, 172 },
171 173
172 /** 174 /**
173 * Handler for the 'Ok' button click event. 175 * Handler for the 'Save' button tap event.
174 * @param {!Event} event 176 * @param {!Event} event
175 * @private 177 * @private
176 */ 178 */
177 onSaveTap_: function(event) { 179 onSaveTap_: function(event) {
178 this.createInProgress_ = true; 180 this.createInProgress_ = true;
179 this.browserProxy_.createProfile( 181
180 this.profileName_, this.profileIconUrl_, this.isSupervised_, 182 if (!this.isSupervised_) {
181 this.signedInUsers_[this.selectedEmail_].profilePath); 183 // The new profile is not supervised. Go ahead and create it.
184 this.createProfile_();
185 } else if (this.signedInUserIndex_ == NO_USER_SELECTED) {
186 // If the new profile is supervised, a custodian must be selected.
187 this.handleMessage_(this.i18n('custodianAccountNotSelectedError'));
188 this.createInProgress_ = false;
189 } else {
190 var signedInUser = this.signedInUser_(this.signedInUserIndex_);
191 this.browserProxy_.getExistingSupervisedUsers(
192 signedInUser.profilePath).then(
193 this.createProfileIfValidSupervisedUser_.bind(this),
194 /** @param {*} error */
195 function(error) { this.handleMessage_(error); }.bind(this));
196 }
182 }, 197 },
183 198
184 /** 199 /**
185 * Handler for the 'Cancel' button click event. 200 * Checks if the entered name matches name of an existing supervised user.
201 * If yes, the user is prompted to import the existing supervised user.
202 * If no, the new supervised profile gets created.
203 * @param {Array<SupervisedUser>} supervisedUsers The list of existing
204 * supervised users.
205 * @private
206 */
207 createProfileIfValidSupervisedUser_: function(supervisedUsers) {
208 for (var i = 0; i < supervisedUsers.length; ++i) {
209 if (supervisedUsers[i].name != this.profileName_)
210 continue;
211 // Check if another supervised user also exists with that name.
212 var nameIsUnique = true;
213 // Handling the case when multiple supervised users with the same
214 // name exist, but not all of them are on the device.
215 // If at least one is not imported, we want to offer that
216 // option to the user. This could happen due to a bug that allowed
217 // creating SUs with the same name (https://crbug.com/557445).
218 var allOnCurrentDevice = supervisedUsers[i].onCurrentDevice;
219 for (var j = i + 1; j < supervisedUsers.length; ++j) {
220 if (supervisedUsers[j].name == this.profileName_) {
221 nameIsUnique = false;
222 allOnCurrentDevice = allOnCurrentDevice &&
223 supervisedUsers[j].onCurrentDevice;
224 }
225 }
226
227 this.handleMessage_(allOnCurrentDevice ?
228 this.i18n('managedProfilesExistingLocalSupervisedUser') :
229 this.i18n('manageProfilesExistingSupervisedUser',
230 HTMLEscape(elide(this.profileName_, /* maxLength */ 50))));
231
232 this.createInProgress_ = false;
233 return;
234 }
235 // No existing supervised user's name matches the entered profile name.
236 // Continue with creating the new supervised profile.
237 this.createProfile_();
238 },
239
240 /**
241 * Creates the new profile.
242 * @private
243 */
244 createProfile_: function() {
245 var custodianProfilePath = '';
246 if (this.signedInUserIndex_ != NO_USER_SELECTED) {
247 custodianProfilePath =
248 this.signedInUser_(this.signedInUserIndex_).profilePath;
249 }
250
251 this.browserProxy_.createProfile(
252 this.profileName_, this.profileIconUrl_, this.isSupervised_,
253 custodianProfilePath);
254 },
255
256 /**
257 * Handler for the 'Cancel' button tap event.
186 * @param {!Event} event 258 * @param {!Event} event
187 * @private 259 * @private
188 */ 260 */
189 onCancelTap_: function(event) { 261 onCancelTap_: function(event) {
190 if (this.createInProgress_) { 262 if (this.createInProgress_) {
191 this.createInProgress_ = false; 263 this.createInProgress_ = false;
192 this.browserProxy_.cancelCreateProfile(); 264 this.browserProxy_.cancelCreateProfile();
193 } else { 265 } else {
194 this.fire('change-page', {page: 'user-pods-page'}); 266 this.fire('change-page', {page: 'user-pods-page'});
195 } 267 }
(...skipping 28 matching lines...) Expand all
224 }, 296 },
225 297
226 /** 298 /**
227 * Handles profile create/import warning/error message pushed by the browser. 299 * Handles profile create/import warning/error message pushed by the browser.
228 * @param {string} message An HTML warning/error message. 300 * @param {string} message An HTML warning/error message.
229 * @private 301 * @private
230 */ 302 */
231 handleMessage_: function(message) { 303 handleMessage_: function(message) {
232 this.createInProgress_ = false; 304 this.createInProgress_ = false;
233 this.message_ = message; 305 this.message_ = message;
306
307 // TODO(mahmadi): attach handler to '#supervised-user-import-existing'
308 // in order to import supervised user with the given name.
309
310 // TODO(mahmadi): attach handler to '#reauth' in order to re-authenticate
311 // custodian.
234 }, 312 },
235 313
236 /** 314 /**
237 * Computed binding determining which profile icon button is toggled on. 315 * Computed binding determining which profile icon button is toggled on.
238 * @param {string} iconUrl icon URL of a given icon button. 316 * @param {string} iconUrl icon URL of a given icon button.
239 * @param {string} profileIconUrl Currently selected icon URL. 317 * @param {string} profileIconUrl Currently selected icon URL.
240 * @return {boolean} 318 * @return {boolean}
241 * @private 319 * @private
242 */ 320 */
243 isActiveIcon_: function(iconUrl, profileIconUrl) { 321 isActiveIcon_: function(iconUrl, profileIconUrl) {
244 return iconUrl == profileIconUrl; 322 return iconUrl == profileIconUrl;
245 }, 323 },
246 324
247 /** 325 /**
248 * Computed binding determining whether 'Ok' button is disabled. 326 * Computed binding determining whether 'Save' button is disabled.
249 * @param {boolean} createInProgress Is create in progress? 327 * @param {boolean} createInProgress Is create in progress?
250 * @param {string} profileName Profile Name. 328 * @param {string} profileName Profile Name.
251 * @param {string} message Existing warning/error message.
252 * @return {boolean} 329 * @return {boolean}
253 * @private 330 * @private
254 */ 331 */
255 isOkDisabled_: function(createInProgress, profileName, message) { 332 isSaveDisabled_: function(createInProgress, profileName) {
256 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a 333 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a
257 // dependency and cast to PaperInputElement instead. 334 // dependency and cast to PaperInputElement instead.
258 /** @type {{validate: function():boolean}} */ 335 /** @type {{validate: function():boolean}} */
259 var nameInput = this.$.nameInput; 336 var nameInput = this.$.nameInput;
260 return createInProgress || !profileName || message != '' || 337 return createInProgress || !profileName || !nameInput.validate();
261 !nameInput.validate();
262 }, 338 },
263 339
264 /** 340 /**
265 * Computed binding determining whether supervised user checkbox is disabled. 341 * Computed binding that returns True if there are any signed-in users.
266 * @param {boolean} createInProgress Is create in progress? 342 * @param {!Array<SignedInUser>} signedInUsers signed-in users.
Dan Beam 2016/04/06 06:45:19 Nit: !Array<!SignedInUser>
Moe 2016/04/07 14:36:40 Done.
267 * @param {boolean} signedIn Are there any signed-in users?
268 * @return {boolean} 343 * @return {boolean}
269 * @private 344 * @private
270 */ 345 */
271 isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) { 346 isSignedIn_: function(signedInUsers) {
272 return createInProgress || !signedIn; 347 return signedInUsers.length > 0;
273 } 348 }
274 }); 349 });
350 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698