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 '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() { | 9 (function() { |
| 10 /** | 10 /** |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 */ | 91 */ |
| 92 signedInUserIndex_: { | 92 signedInUserIndex_: { |
| 93 type: Number, | 93 type: Number, |
| 94 value: NO_USER_SELECTED | 94 value: NO_USER_SELECTED |
| 95 }, | 95 }, |
| 96 | 96 |
| 97 /** @private {!signin.ProfileBrowserProxy} */ | 97 /** @private {!signin.ProfileBrowserProxy} */ |
| 98 browserProxy_: Object | 98 browserProxy_: Object |
| 99 }, | 99 }, |
| 100 | 100 |
| 101 listeners: { | |
| 102 'tap': 'onTap_' | |
|
tommycli
2016/04/18 23:27:18
This is leftover right?
Moe
2016/04/19 21:47:42
No it is not. Unfortunately, this is another i18n
Dan Beam
2016/04/19 23:41:57
bummer, you can't do supervised-user-import-existi
Moe
2016/04/20 15:28:56
totally!
| |
| 103 }, | |
| 104 | |
| 101 /** @override */ | 105 /** @override */ |
| 102 created: function() { | 106 created: function() { |
| 103 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance(); | 107 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance(); |
| 104 }, | 108 }, |
| 105 | 109 |
| 106 /** @override */ | 110 /** @override */ |
| 107 ready: function() { | 111 ready: function() { |
| 108 this.addWebUIListener( | 112 this.addWebUIListener( |
| 109 'create-profile-success', this.handleSuccess_.bind(this)); | 113 'create-profile-success', this.handleSuccess_.bind(this)); |
| 110 this.addWebUIListener( | 114 this.addWebUIListener( |
| 111 'create-profile-warning', this.handleMessage_.bind(this)); | 115 'create-profile-warning', this.handleMessage_.bind(this)); |
| 112 this.addWebUIListener( | 116 this.addWebUIListener( |
| 113 'create-profile-error', this.handleMessage_.bind(this)); | 117 'create-profile-error', this.handleMessage_.bind(this)); |
| 114 this.addWebUIListener( | 118 this.addWebUIListener( |
| 115 'profile-icons-received', this.handleProfileIcons_.bind(this)); | 119 'profile-icons-received', this.handleProfileIcons_.bind(this)); |
| 116 this.addWebUIListener( | 120 this.addWebUIListener( |
| 117 'profile-defaults-received', this.handleProfileDefaults_.bind(this)); | 121 'profile-defaults-received', this.handleProfileDefaults_.bind(this)); |
| 118 this.addWebUIListener( | 122 this.addWebUIListener( |
| 119 'signedin-users-received', this.handleSignedInUsers_.bind(this)); | 123 'signedin-users-received', this.handleSignedInUsers_.bind(this)); |
| 120 | 124 |
| 121 this.browserProxy_.getAvailableIcons(); | 125 this.browserProxy_.getAvailableIcons(); |
| 122 this.browserProxy_.getSignedInUsers(); | 126 this.browserProxy_.getSignedInUsers(); |
| 123 | 127 |
| 124 // Alias on 'this' to use in html. | 128 // Alias on 'this' to use in html. |
| 125 this.NO_USER_SELECTED = NO_USER_SELECTED; | 129 this.NO_USER_SELECTED = NO_USER_SELECTED; |
| 126 }, | 130 }, |
| 127 | 131 |
| 128 /** | 132 /** |
| 133 * General handler for tap event on the host, used to handle tap events for | |
| 134 * dynamically added '<a>' elements. | |
| 135 * @param {!Event} event | |
| 136 * @private | |
| 137 */ | |
| 138 onTap_: function(event) { | |
|
tommycli
2016/04/18 23:27:18
This is also a leftover right? I don't see any dyn
Moe
2016/04/19 21:47:42
Please see the previous response.
tommycli
2016/04/19 23:33:37
This is unfortunate but ... -- this is pretty dirt
Dan Beam
2016/04/19 23:41:57
this is not dirty, it's event delegation
Moe
2016/04/20 15:28:56
Done.
| |
| 139 var element = Polymer.dom(event).rootTarget; | |
| 140 | |
| 141 // Handle the tap event only if the target is a '<a>' element. | |
| 142 if (element.nodeName == 'A') { | |
|
Dan Beam
2016/04/19 23:41:57
you should never need to filter by nodeName if you
Moe
2016/04/20 15:28:56
Done.
| |
| 143 if (element.id == 'supervised-user-import-existing') { | |
|
Dan Beam
2016/04/19 23:41:57
no curlies
Moe
2016/04/20 15:28:56
Done.
| |
| 144 this.onImportUserTap_(event); | |
| 145 } | |
| 146 // TODO(mahmadi): handle tap event on '#reauth' to re-auth the custodian. | |
| 147 } | |
| 148 }, | |
| 149 | |
| 150 /** | |
| 129 * Handler for when the profile icons are pushed from the browser. | 151 * Handler for when the profile icons are pushed from the browser. |
| 130 * @param {!Array<string>} iconUrls | 152 * @param {!Array<string>} iconUrls |
| 131 * @private | 153 * @private |
| 132 */ | 154 */ |
| 133 handleProfileIcons_: function(iconUrls) { | 155 handleProfileIcons_: function(iconUrls) { |
| 134 this.availableIconUrls_ = iconUrls; | 156 this.availableIconUrls_ = iconUrls; |
| 135 this.profileIconUrl_ = iconUrls[0]; | 157 this.profileIconUrl_ = iconUrls[0]; |
| 136 }, | 158 }, |
| 137 | 159 |
| 138 /** | 160 /** |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 165 /** | 187 /** |
| 166 * Handler for the 'Learn More' link tap event. | 188 * Handler for the 'Learn More' link tap event. |
| 167 * @param {!Event} event | 189 * @param {!Event} event |
| 168 * @private | 190 * @private |
| 169 */ | 191 */ |
| 170 onLearnMoreTap_: function(event) { | 192 onLearnMoreTap_: function(event) { |
| 171 this.fire('change-page', {page: 'supervised-learn-more-page'}); | 193 this.fire('change-page', {page: 'supervised-learn-more-page'}); |
| 172 }, | 194 }, |
| 173 | 195 |
| 174 /** | 196 /** |
| 197 * Handler for the 'Import Supervised User' link tap event. | |
| 198 * @param {!Event} event | |
| 199 * @private | |
| 200 */ | |
| 201 onImportUserTap_: function(event) { | |
| 202 this.createInProgress_ = true; | |
| 203 | |
| 204 if (this.signedInUserIndex_ == NO_USER_SELECTED) { | |
| 205 // A custodian must be selected. | |
| 206 this.handleMessage_(this.i18n('custodianAccountNotSelectedError')); | |
| 207 this.createInProgress_ = false; | |
| 208 } else { | |
| 209 var signedInUser = this.signedInUser_(this.signedInUserIndex_); | |
| 210 this.browserProxy_.getExistingSupervisedUsers( | |
| 211 signedInUser.profilePath).then( | |
| 212 this.showImportSupervisedUserPopup_.bind(this), | |
| 213 /** @param {*} error */ | |
| 214 function(error) { this.handleMessage_(error); }.bind(this)); | |
| 215 } | |
| 216 }, | |
| 217 | |
| 218 /** | |
| 175 * Handler for the 'Save' button tap event. | 219 * Handler for the 'Save' button tap event. |
| 176 * @param {!Event} event | 220 * @param {!Event} event |
| 177 * @private | 221 * @private |
| 178 */ | 222 */ |
| 179 onSaveTap_: function(event) { | 223 onSaveTap_: function(event) { |
| 180 this.createInProgress_ = true; | 224 this.createInProgress_ = true; |
| 181 | 225 |
| 182 if (!this.isSupervised_) { | 226 if (!this.isSupervised_) { |
| 183 // The new profile is not supervised. Go ahead and create it. | 227 // The new profile is not supervised. Go ahead and create it. |
| 184 this.createProfile_(); | 228 this.createProfile_(); |
| 185 } else if (this.signedInUserIndex_ == NO_USER_SELECTED) { | 229 } else if (this.signedInUserIndex_ == NO_USER_SELECTED) { |
| 186 // If the new profile is supervised, a custodian must be selected. | 230 // If the new profile is supervised, a custodian must be selected. |
| 187 this.handleMessage_(this.i18n('custodianAccountNotSelectedError')); | 231 this.handleMessage_(this.i18n('custodianAccountNotSelectedError')); |
| 188 this.createInProgress_ = false; | 232 this.createInProgress_ = false; |
| 189 } else { | 233 } else { |
| 190 var signedInUser = this.signedInUser_(this.signedInUserIndex_); | 234 var signedInUser = this.signedInUser_(this.signedInUserIndex_); |
| 191 this.browserProxy_.getExistingSupervisedUsers( | 235 this.browserProxy_.getExistingSupervisedUsers( |
| 192 signedInUser.profilePath).then( | 236 signedInUser.profilePath).then( |
| 193 this.createProfileIfValidSupervisedUser_.bind(this), | 237 this.createProfileIfValidSupervisedUser_.bind(this), |
| 194 /** @param {*} error */ | 238 /** @param {*} error */ |
| 195 function(error) { this.handleMessage_(error); }.bind(this)); | 239 function(error) { this.handleMessage_(error); }.bind(this)); |
| 196 } | 240 } |
| 197 }, | 241 }, |
| 198 | 242 |
| 199 /** | 243 /** |
| 244 * Displays the import supervised user popup. | |
| 245 * @param {Array<SupervisedUser>} supervisedUsers The list of existing | |
| 246 * supervised users. | |
| 247 * @private | |
| 248 */ | |
| 249 showImportSupervisedUserPopup_: function(supervisedUsers) { | |
| 250 this.createInProgress_ = false; | |
| 251 this.$.importUserPopup.show(this.signedInUser_(this.signedInUserIndex_), | |
| 252 supervisedUsers); | |
| 253 }, | |
| 254 | |
| 255 /** | |
| 200 * Checks if the entered name matches name of an existing supervised user. | 256 * 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. | 257 * If yes, the user is prompted to import the existing supervised user. |
| 202 * If no, the new supervised profile gets created. | 258 * If no, the new supervised profile gets created. |
| 203 * @param {Array<SupervisedUser>} supervisedUsers The list of existing | 259 * @param {Array<SupervisedUser>} supervisedUsers The list of existing |
| 204 * supervised users. | 260 * supervised users. |
| 205 * @private | 261 * @private |
| 206 */ | 262 */ |
| 207 createProfileIfValidSupervisedUser_: function(supervisedUsers) { | 263 createProfileIfValidSupervisedUser_: function(supervisedUsers) { |
| 208 for (var i = 0; i < supervisedUsers.length; ++i) { | 264 for (var i = 0; i < supervisedUsers.length; ++i) { |
| 209 if (supervisedUsers[i].name != this.profileName_) | 265 if (supervisedUsers[i].name != this.profileName_) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 * @private | 298 * @private |
| 243 */ | 299 */ |
| 244 createProfile_: function() { | 300 createProfile_: function() { |
| 245 var custodianProfilePath = ''; | 301 var custodianProfilePath = ''; |
| 246 if (this.signedInUserIndex_ != NO_USER_SELECTED) { | 302 if (this.signedInUserIndex_ != NO_USER_SELECTED) { |
| 247 custodianProfilePath = | 303 custodianProfilePath = |
| 248 this.signedInUser_(this.signedInUserIndex_).profilePath; | 304 this.signedInUser_(this.signedInUserIndex_).profilePath; |
| 249 } | 305 } |
| 250 | 306 |
| 251 this.browserProxy_.createProfile( | 307 this.browserProxy_.createProfile( |
| 252 this.profileName_, this.profileIconUrl_, this.isSupervised_, | 308 this.profileName_, this.profileIconUrl_, this.isSupervised_, '', |
| 253 custodianProfilePath); | 309 custodianProfilePath); |
| 254 }, | 310 }, |
| 255 | 311 |
| 256 /** | 312 /** |
| 313 * Handler for the 'import-supervised-user' element's import event. | |
|
tommycli
2016/04/18 23:27:18
Maybe update the comment to elucidate more that th
Moe
2016/04/19 21:47:42
Done.
| |
| 314 * @param {!{detail: {supervisedUser: !SupervisedUser, | |
| 315 signedInUser: !SignedInUser}}} event | |
| 316 * @private | |
| 317 */ | |
| 318 onImportUserPopupImport_: function(event) { | |
| 319 this.createInProgress_ = true; | |
| 320 var supervisedUser = event.detail.supervisedUser; | |
| 321 var signedInUser = event.detail.signedInUser; | |
| 322 this.browserProxy_.createProfile( | |
| 323 supervisedUser.name, supervisedUser.iconURL, true, supervisedUser.id, | |
| 324 signedInUser.profilePath); | |
| 325 }, | |
| 326 | |
| 327 /** | |
| 257 * Handler for the 'Cancel' button tap event. | 328 * Handler for the 'Cancel' button tap event. |
| 258 * @param {!Event} event | 329 * @param {!Event} event |
| 259 * @private | 330 * @private |
| 260 */ | 331 */ |
| 261 onCancelTap_: function(event) { | 332 onCancelTap_: function(event) { |
| 262 if (this.createInProgress_) { | 333 if (this.createInProgress_) { |
| 263 this.createInProgress_ = false; | 334 this.createInProgress_ = false; |
| 264 this.browserProxy_.cancelCreateProfile(); | 335 this.browserProxy_.cancelCreateProfile(); |
| 265 } else { | 336 } else { |
| 266 this.fire('change-page', {page: 'user-pods-page'}); | 337 this.fire('change-page', {page: 'user-pods-page'}); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 }, | 372 }, |
| 302 | 373 |
| 303 /** | 374 /** |
| 304 * Handles profile create/import warning/error message pushed by the browser. | 375 * Handles profile create/import warning/error message pushed by the browser. |
| 305 * @param {string} message An HTML warning/error message. | 376 * @param {string} message An HTML warning/error message. |
| 306 * @private | 377 * @private |
| 307 */ | 378 */ |
| 308 handleMessage_: function(message) { | 379 handleMessage_: function(message) { |
| 309 this.createInProgress_ = false; | 380 this.createInProgress_ = false; |
| 310 this.message_ = message; | 381 this.message_ = message; |
| 311 | |
| 312 // TODO(mahmadi): attach handler to '#supervised-user-import-existing' | |
| 313 // in order to import supervised user with the given name. | |
| 314 | |
| 315 // TODO(mahmadi): attach handler to '#reauth' in order to re-authenticate | |
| 316 // custodian. | |
| 317 }, | 382 }, |
| 318 | 383 |
| 319 /** | 384 /** |
| 320 * Computed binding determining which profile icon button is toggled on. | 385 * Computed binding determining which profile icon button is toggled on. |
| 321 * @param {string} iconUrl icon URL of a given icon button. | 386 * @param {string} iconUrl icon URL of a given icon button. |
| 322 * @param {string} profileIconUrl Currently selected icon URL. | 387 * @param {string} profileIconUrl Currently selected icon URL. |
| 323 * @return {boolean} | 388 * @return {boolean} |
| 324 * @private | 389 * @private |
| 325 */ | 390 */ |
| 326 isActiveIcon_: function(iconUrl, profileIconUrl) { | 391 isActiveIcon_: function(iconUrl, profileIconUrl) { |
| 327 return iconUrl == profileIconUrl; | 392 return iconUrl == profileIconUrl; |
| 328 }, | 393 }, |
| 329 | 394 |
| 330 /** | 395 /** |
| 331 * Computed binding determining whether 'Save' button is disabled. | 396 * Computed binding determining whether 'Save' button is disabled. |
| 332 * @param {boolean} createInProgress Is create in progress? | 397 * @param {boolean} createInProgress Is create in progress? |
| 333 * @param {string} profileName Profile Name. | 398 * @param {string} profileName Profile Name. |
| 334 * @return {boolean} | 399 * @return {boolean} |
| 335 * @private | 400 * @private |
| 336 */ | 401 */ |
| 337 isSaveDisabled_: function(createInProgress, profileName) { | 402 isSaveDisabled_: function(createInProgress, profileName) { |
| 338 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a | 403 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a |
| 339 // dependency and cast to PaperInputElement instead. | 404 // dependency and cast to PaperInputElement instead. |
| 340 /** @type {{validate: function():boolean}} */ | 405 /** @type {{validate: function():boolean}} */ |
| 341 var nameInput = this.$.nameInput; | 406 var nameInput = this.$.nameInput; |
| 342 return createInProgress || !profileName || !nameInput.validate(); | 407 return createInProgress || !profileName || !nameInput.validate(); |
| 343 }, | 408 }, |
| 344 | 409 |
| 345 /** | 410 /** |
| 411 * Returns True if the import supervised user link should be hidden. | |
| 412 * @param {boolean} createInProgress True if create/import is in progress | |
| 413 * @param {number} signedInUserIndex Index of the selected signed-in user. | |
| 414 * @return {boolean} | |
| 415 * @private | |
| 416 */ | |
| 417 isImportUserLinkHidden_: function(createInProgress, signedInUserIndex) { | |
| 418 return createInProgress || !this.signedInUser_(signedInUserIndex); | |
|
tommycli
2016/04/18 23:27:18
Interesting... the link is really hidden as soon a
Moe
2016/04/19 21:47:42
I checked with UX. The same thing as the create sc
| |
| 419 }, | |
| 420 | |
| 421 /** | |
| 346 * Computed binding that returns True if there are any signed-in users. | 422 * Computed binding that returns True if there are any signed-in users. |
| 347 * @param {!Array<!SignedInUser>} signedInUsers signed-in users. | 423 * @param {!Array<!SignedInUser>} signedInUsers signed-in users. |
| 348 * @return {boolean} | 424 * @return {boolean} |
| 349 * @private | 425 * @private |
| 350 */ | 426 */ |
| 351 isSignedIn_: function(signedInUsers) { | 427 isSignedIn_: function(signedInUsers) { |
| 352 return signedInUsers.length > 0; | 428 return signedInUsers.length > 0; |
| 353 } | 429 } |
| 354 }); | 430 }); |
| 355 }()); | 431 }()); |
| OLD | NEW |