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 '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 | 9 |
10 /** @typedef {{url: string, label:string}} */ | 10 /** @typedef {{url: string, label:string}} */ |
(...skipping 23 matching lines...) Expand all Loading... |
34 * @private {!Array<!AvatarIcon>} | 34 * @private {!Array<!AvatarIcon>} |
35 */ | 35 */ |
36 availableIcons_: { | 36 availableIcons_: { |
37 type: Array, | 37 type: Array, |
38 value: function() { | 38 value: function() { |
39 return []; | 39 return []; |
40 } | 40 } |
41 }, | 41 }, |
42 | 42 |
43 /** | 43 /** |
44 * The currently selected profile icon URL. May be a data URL. | 44 * The currently selected profile avatar, if any. |
45 * @private {string} | 45 * @private {?AvatarIcon} |
46 */ | 46 */ |
47 profileIconUrl_: {type: String, value: ''}, | 47 selectedAvatar_: Object, |
48 | 48 |
49 /** | 49 /** |
50 * True if the existing supervised users are being loaded. | 50 * True if the existing supervised users are being loaded. |
51 * @private {boolean} | 51 * @private {boolean} |
52 */ | 52 */ |
53 loadingSupervisedUsers_: {type: Boolean, value: false}, | 53 loadingSupervisedUsers_: {type: Boolean, value: false}, |
54 | 54 |
55 /** | 55 /** |
56 * True if a profile is being created or imported. | 56 * True if a profile is being created or imported. |
57 * @private {boolean} | 57 * @private {boolean} |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 }, | 135 }, |
136 | 136 |
137 /** @override */ | 137 /** @override */ |
138 ready: function() { | 138 ready: function() { |
139 this.addWebUIListener( | 139 this.addWebUIListener( |
140 'create-profile-success', this.handleSuccess_.bind(this)); | 140 'create-profile-success', this.handleSuccess_.bind(this)); |
141 this.addWebUIListener( | 141 this.addWebUIListener( |
142 'create-profile-warning', this.handleMessage_.bind(this)); | 142 'create-profile-warning', this.handleMessage_.bind(this)); |
143 this.addWebUIListener( | 143 this.addWebUIListener( |
144 'create-profile-error', this.handleMessage_.bind(this)); | 144 'create-profile-error', this.handleMessage_.bind(this)); |
145 this.addWebUIListener( | 145 this.addWebUIListener('profile-icons-received', function(icons) { |
146 'profile-icons-received', this.handleProfileIcons_.bind(this)); | 146 this.availableIcons_ = icons; |
| 147 }.bind(this)); |
147 this.addWebUIListener( | 148 this.addWebUIListener( |
148 'profile-defaults-received', this.handleProfileDefaults_.bind(this)); | 149 'profile-defaults-received', this.handleProfileDefaults_.bind(this)); |
149 this.addWebUIListener( | 150 this.addWebUIListener( |
150 'signedin-users-received', this.handleSignedInUsers_.bind(this)); | 151 'signedin-users-received', this.handleSignedInUsers_.bind(this)); |
151 | 152 |
152 this.browserProxy_.getAvailableIcons(); | 153 this.browserProxy_.getAvailableIcons(); |
153 this.browserProxy_.getSignedInUsers(); | 154 this.browserProxy_.getSignedInUsers(); |
154 }, | 155 }, |
155 | 156 |
156 /** @override */ | 157 /** @override */ |
(...skipping 19 matching lines...) Expand all Loading... |
176 event.preventDefault(); | 177 event.preventDefault(); |
177 } else if (element.id == 'reauth') { | 178 } else if (element.id == 'reauth') { |
178 var elementData = /** @type {{userEmail: string}} */ (element.dataset); | 179 var elementData = /** @type {{userEmail: string}} */ (element.dataset); |
179 this.browserProxy_.authenticateCustodian(elementData.userEmail); | 180 this.browserProxy_.authenticateCustodian(elementData.userEmail); |
180 this.hideMessage_(); | 181 this.hideMessage_(); |
181 event.preventDefault(); | 182 event.preventDefault(); |
182 } | 183 } |
183 }, | 184 }, |
184 | 185 |
185 /** | 186 /** |
186 * Handler for when the profile icons are pushed from the browser. | |
187 * @param {!Array<!AvatarIcon>} icons | |
188 * @private | |
189 */ | |
190 handleProfileIcons_: function(icons) { | |
191 this.availableIcons_ = icons; | |
192 this.profileIconUrl_ = icons[0].url; | |
193 }, | |
194 | |
195 /** | |
196 * Handler for when the profile defaults are pushed from the browser. | 187 * Handler for when the profile defaults are pushed from the browser. |
197 * @param {!ProfileInfo} profileInfo Default Info for the new profile. | 188 * @param {!ProfileInfo} profileInfo Default Info for the new profile. |
198 * @private | 189 * @private |
199 */ | 190 */ |
200 handleProfileDefaults_: function(profileInfo) { | 191 handleProfileDefaults_: function(profileInfo) { |
201 this.profileName_ = profileInfo.name; | 192 this.profileName_ = profileInfo.name; |
202 }, | 193 }, |
203 | 194 |
204 /** | 195 /** |
205 * Handler for when signed-in users are pushed from the browser. | 196 * Handler for when signed-in users are pushed from the browser. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 createProfile_: function() { | 349 createProfile_: function() { |
359 var custodianProfilePath = ''; | 350 var custodianProfilePath = ''; |
360 if (this.signedInUserIndex_ != NO_USER_SELECTED) { | 351 if (this.signedInUserIndex_ != NO_USER_SELECTED) { |
361 custodianProfilePath = | 352 custodianProfilePath = |
362 this.signedInUser_(this.signedInUserIndex_).profilePath; | 353 this.signedInUser_(this.signedInUserIndex_).profilePath; |
363 } | 354 } |
364 this.hideMessage_(); | 355 this.hideMessage_(); |
365 this.createInProgress_ = true; | 356 this.createInProgress_ = true; |
366 var createShortcut = | 357 var createShortcut = |
367 this.isProfileShortcutsEnabled_ && this.createShortcut_; | 358 this.isProfileShortcutsEnabled_ && this.createShortcut_; |
| 359 // Select the 1st avatar if none selected. |
| 360 var selectedAvatar = this.selectedAvatar_ || this.availableIcons_[0]; |
368 this.browserProxy_.createProfile( | 361 this.browserProxy_.createProfile( |
369 this.profileName_, this.profileIconUrl_, createShortcut, | 362 this.profileName_, selectedAvatar.url, createShortcut, |
370 this.isSupervised_, '', custodianProfilePath); | 363 this.isSupervised_, '', custodianProfilePath); |
371 }, | 364 }, |
372 | 365 |
373 /** | 366 /** |
374 * Handler for a change in the supervised account dropdown. | 367 * Handler for a change in the supervised account dropdown. |
375 * @param {!{target: HTMLSelectElement}} event | 368 * @param {!{target: HTMLSelectElement}} event |
376 * @private | 369 * @private |
377 */ | 370 */ |
378 onAccountChanged_: function(event) { | 371 onAccountChanged_: function(event) { |
379 this.signedInUserIndex_ = parseInt(event.target.value, 10); | 372 this.signedInUserIndex_ = parseInt(event.target.value, 10); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 'id': function(node, value) { | 456 'id': function(node, value) { |
464 return node.tagName == 'A'; | 457 return node.tagName == 'A'; |
465 } | 458 } |
466 } | 459 } |
467 }; | 460 }; |
468 | 461 |
469 return this.i18nAdvanced(id, opts); | 462 return this.i18nAdvanced(id, opts); |
470 }, | 463 }, |
471 | 464 |
472 /** | 465 /** |
473 * Computed binding determining which profile icon button is toggled on. | |
474 * @param {string} iconUrl icon URL of a given icon button. | |
475 * @param {string} profileIconUrl Currently selected icon URL. | |
476 * @return {boolean} | |
477 * @private | |
478 */ | |
479 isActiveIcon_: function(iconUrl, profileIconUrl) { | |
480 return iconUrl == profileIconUrl; | |
481 }, | |
482 | |
483 /** | |
484 * Computed binding determining whether the paper-spinner is active. | 466 * Computed binding determining whether the paper-spinner is active. |
485 * @param {boolean} createInProgress Is create in progress? | 467 * @param {boolean} createInProgress Is create in progress? |
486 * @param {boolean} loadingSupervisedUsers Are supervised users being loaded? | 468 * @param {boolean} loadingSupervisedUsers Are supervised users being loaded? |
487 * @return {boolean} | 469 * @return {boolean} |
488 * @private | 470 * @private |
489 */ | 471 */ |
490 isSpinnerActive_: function(createInProgress, loadingSupervisedUsers) { | 472 isSpinnerActive_: function(createInProgress, loadingSupervisedUsers) { |
491 return createInProgress || loadingSupervisedUsers; | 473 return createInProgress || loadingSupervisedUsers; |
492 }, | 474 }, |
493 | 475 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 * Computed binding that returns True if there are any signed-in users. | 510 * Computed binding that returns True if there are any signed-in users. |
529 * @param {!Array<!SignedInUser>} signedInUsers signed-in users. | 511 * @param {!Array<!SignedInUser>} signedInUsers signed-in users. |
530 * @return {boolean} | 512 * @return {boolean} |
531 * @private | 513 * @private |
532 */ | 514 */ |
533 isSignedIn_: function(signedInUsers) { | 515 isSignedIn_: function(signedInUsers) { |
534 return signedInUsers.length > 0; | 516 return signedInUsers.length > 0; |
535 } | 517 } |
536 }); | 518 }); |
537 }()); | 519 }()); |
OLD | NEW |