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 * @element create-profile | 9 * @element create-profile |
| 10 */ | 10 */ |
| 11 Polymer({ | 11 Polymer({ |
| 12 is: 'create-profile', | 12 is: 'create-profile', |
| 13 | 13 |
| 14 behaviors: [WebUIListenerBehavior], | 14 behaviors: [ |
| 15 I18nBehavior, | |
| 16 WebUIListenerBehavior | |
| 17 ], | |
| 15 | 18 |
| 16 properties: { | 19 properties: { |
| 17 /** | 20 /** |
| 18 * True if supervised user checkbox is disabled. | |
| 19 * @private {boolean} | |
| 20 */ | |
| 21 supervisedUserCheckboxDisabled_: { | |
| 22 type: Boolean, | |
| 23 computed: | |
| 24 'isSupervisedUserCheckboxDisabled_(createInProgress_, signedIn_)' | |
| 25 }, | |
| 26 | |
| 27 /** | |
| 28 * The current profile name. | 21 * The current profile name. |
| 29 * @private {string} | 22 * @private {string} |
| 30 */ | 23 */ |
| 31 profileName_: { | 24 profileName_: { |
| 32 type: String, | 25 type: String, |
| 33 value: '', | 26 value: '' |
| 34 }, | 27 }, |
| 35 | 28 |
| 36 /** | 29 /** |
| 37 * The list of available profile icon URLs. | 30 * The list of available profile icon URLs. |
| 38 * @private {!Array<string>} | 31 * @private {!Array<string>} |
| 39 */ | 32 */ |
| 40 availableIconUrls_: { | 33 availableIconUrls_: { |
| 41 type: Array, | 34 type: Array, |
| 42 value: function() { return []; } | 35 value: function() { return []; } |
| 43 }, | 36 }, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 */ | 77 */ |
| 85 signedInUsers_: { | 78 signedInUsers_: { |
| 86 type: Array, | 79 type: Array, |
| 87 value: function() { return []; } | 80 value: function() { return []; } |
| 88 }, | 81 }, |
| 89 | 82 |
| 90 /** | 83 /** |
| 91 * Index of the selected signed-in user. | 84 * Index of the selected signed-in user. |
| 92 * @private {number} | 85 * @private {number} |
| 93 */ | 86 */ |
| 94 selectedEmail_: { | 87 signedInUserIndex_: { |
|
tommycli
2016/03/24 19:28:51
Just add a comment here that -1 means no user is s
Moe
2016/03/24 22:07:56
Done.
tommycli
2016/03/24 22:18:54
Can we make this a constant? NO_USER_SELECTED or s
Moe
2016/03/29 20:51:16
Done.
| |
| 95 type: Number, | 88 type: Number, |
| 96 value: 0 | 89 value: -1 |
| 97 }, | 90 }, |
| 98 | 91 |
| 99 /** @private {!signin.ProfileBrowserProxy} */ | 92 /** @private {!signin.ProfileBrowserProxy} */ |
| 100 browserProxy_: Object | 93 browserProxy_: Object |
| 101 }, | 94 }, |
| 102 | 95 |
| 103 /** @override */ | 96 /** @override */ |
| 104 created: function() { | 97 created: function() { |
| 105 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance(); | 98 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance(); |
| 106 }, | 99 }, |
| 107 | 100 |
| 108 /** @override */ | 101 /** @override */ |
| 109 attached: function() { | 102 ready: function() { |
| 110 this.resetForm_(); | |
| 111 | |
| 112 this.addWebUIListener( | 103 this.addWebUIListener( |
| 113 'create-profile-success', this.handleSuccess_.bind(this)); | 104 'create-profile-success', this.handleSuccess_.bind(this)); |
| 114 this.addWebUIListener( | 105 this.addWebUIListener( |
| 115 'create-profile-warning', this.handleMessage_.bind(this)); | 106 'create-profile-warning', this.handleMessage_.bind(this)); |
| 116 this.addWebUIListener( | 107 this.addWebUIListener( |
| 117 'create-profile-error', this.handleMessage_.bind(this)); | 108 'create-profile-error', this.handleMessage_.bind(this)); |
| 118 this.addWebUIListener( | 109 this.addWebUIListener( |
| 119 'profile-icons-received', this.handleProfileIcons_.bind(this)); | 110 'profile-icons-received', this.handleProfileIcons_.bind(this)); |
| 120 this.addWebUIListener( | 111 this.addWebUIListener( |
| 112 'profile-defaults-received', this.handleProfileDefaults_.bind(this)); | |
| 113 this.addWebUIListener( | |
| 121 'signedin-users-received', this.handleSignedInUsers_.bind(this)); | 114 'signedin-users-received', this.handleSignedInUsers_.bind(this)); |
| 122 | 115 |
| 123 this.browserProxy_.getAvailableIcons(); | 116 this.browserProxy_.getAvailableIcons(); |
| 124 this.browserProxy_.getSignedInUsers(); | 117 this.browserProxy_.getSignedInUsers(); |
| 125 }, | 118 }, |
| 126 | 119 |
| 127 /** | 120 /** |
| 128 * Resets the state of the page. | |
| 129 * @private | |
| 130 */ | |
| 131 resetForm_: function() { | |
| 132 this.profileName_ = ''; | |
| 133 this.availableIconUrls_ = []; | |
| 134 this.profileIconUrl_ = ''; | |
| 135 this.createInProgress_ = false; | |
| 136 this.message_ = ''; | |
| 137 this.isSupervised_ = false; | |
| 138 this.signedInUsers_ = []; | |
| 139 this.selectedEmail_ = 0; | |
| 140 }, | |
| 141 | |
| 142 /** | |
| 143 * Handler for when the profile icons are pushed from the browser. | 121 * Handler for when the profile icons are pushed from the browser. |
| 144 * @param {!Array<string>} iconUrls | 122 * @param {!Array<string>} iconUrls |
| 145 * @private | 123 * @private |
| 146 */ | 124 */ |
| 147 handleProfileIcons_: function(iconUrls) { | 125 handleProfileIcons_: function(iconUrls) { |
| 148 this.availableIconUrls_ = iconUrls; | 126 this.availableIconUrls_ = iconUrls; |
| 149 this.profileIconUrl_ = iconUrls[0]; | 127 this.profileIconUrl_ = iconUrls[0]; |
| 150 }, | 128 }, |
| 151 | 129 |
| 152 /** | 130 /** |
| 153 * Updates the signed-in users. | 131 * Handler for when the profile defaults are pushed from the browser. |
| 132 * @param {ProfileInfo} profileInfo Default Info for the new profile. | |
| 133 * @private | |
| 134 */ | |
| 135 handleProfileDefaults_: function(profileInfo) { | |
| 136 this.profileName_ = profileInfo.name; | |
| 137 }, | |
| 138 | |
| 139 /** | |
| 140 * Handler for when signed-in users are pushed from the browser. | |
| 154 * @param {!Array<SignedInUser>} signedInUsers | 141 * @param {!Array<SignedInUser>} signedInUsers |
| 155 * @private | 142 * @private |
| 156 */ | 143 */ |
| 157 handleSignedInUsers_: function(signedInUsers) { | 144 handleSignedInUsers_: function(signedInUsers) { |
| 158 this.signedInUsers_ = signedInUsers; | 145 this.signedInUsers_ = signedInUsers; |
| 159 this.signedIn_ = signedInUsers.length > 0; | |
| 160 }, | 146 }, |
| 161 | 147 |
| 162 /** | 148 /** |
| 163 * Handler for the 'Learn More' button click event. | 149 * Handler for the 'Learn More' link tap event. |
| 164 * @param {!Event} event | 150 * @param {!Event} event |
| 165 * @private | 151 * @private |
| 166 */ | 152 */ |
| 167 onLearnMoreTap_: function(event) { | 153 onLearnMoreTap_: function(event) { |
| 168 // TODO(mahmadi): fire the event to show the 'learn-more-page' | 154 // TODO(mahmadi): fire the event to show the 'learn-more-page' |
| 169 }, | 155 }, |
| 170 | 156 |
| 171 /** | 157 /** |
| 172 * Handler for the 'Ok' button click event. | 158 * Handler for the 'Save' button tap event. |
| 173 * @param {!Event} event | 159 * @param {!Event} event |
| 174 * @private | 160 * @private |
| 175 */ | 161 */ |
| 176 onSaveTap_: function(event) { | 162 onSaveTap_: function(event) { |
| 177 this.createInProgress_ = true; | 163 this.createInProgress_ = true; |
| 178 this.browserProxy_.createProfile( | 164 |
| 179 this.profileName_, this.profileIconUrl_, this.isSupervised_, | 165 var signedInUser = this.signedInUsers_[this.signedInUserIndex_]; |
|
tommycli
2016/03/24 19:28:50
Is there anything to prevent Save from occuring if
Moe
2016/03/24 22:07:57
If the new profile is not marked to be supervised,
tommycli
2016/03/24 22:18:54
Relying on undefined was too subtle for me to unde
Moe
2016/03/29 20:51:16
Done.
| |
| 180 this.signedInUsers_[this.selectedEmail_].profilePath); | 166 |
| 167 if (!this.isSupervised_) { | |
| 168 this.createProfile_(); | |
| 169 } else if (!signedInUser) { | |
| 170 this.handleMessage_(this.i18n('supervisorAccountNotSelectedError')); | |
| 171 this.createInProgress_ = false; | |
| 172 } else { | |
| 173 this.browserProxy_.getExistingSupervisedUsers( | |
| 174 signedInUser.profilePath).then( | |
| 175 this.createProfileIfValidSupervisedUser_.bind(this), | |
| 176 /** @param {*} error */ | |
| 177 function(error) { this.handleMessage_(error); }.bind(this)); | |
| 178 } | |
| 181 }, | 179 }, |
| 182 | 180 |
| 183 /** | 181 /** |
| 184 * Handler for the 'Cancel' button click event. | 182 * Checks if the entered name matches name of an existing supervised user. |
| 183 * user. If yes, the user is prompted to import the existing supervised user. | |
|
Roger Tawa OOO till Jul 10th
2016/03/24 14:39:05
Remove "user."
Moe
2016/03/24 22:07:56
Done.
| |
| 184 * If no, the new supervised profile gets created. | |
| 185 * @param {Array<SupervisedUser>} supervisedUsers The list of existing | |
| 186 * supervised users. | |
| 187 * @private | |
| 188 */ | |
| 189 createProfileIfValidSupervisedUser_: function(supervisedUsers) { | |
| 190 for (var i = 0; i < supervisedUsers.length; ++i) { | |
| 191 if (supervisedUsers[i].name != this.profileName_) | |
| 192 continue; | |
| 193 // Check if another supervised user also exists with that name. | |
| 194 var nameIsUnique = true; | |
| 195 // Handling the case when multiple supervised users with the same | |
| 196 // name exist, but not all of them are on the device. | |
| 197 // If at least one is not imported, we want to offer that | |
| 198 // option to the user. This could happen due to a bug that allowed | |
| 199 // creating SUs with the same name (https://crbug.com/557445). | |
| 200 var allOnCurrentDevice = supervisedUsers[i].onCurrentDevice; | |
| 201 for (var j = i + 1; j < supervisedUsers.length; ++j) { | |
| 202 if (supervisedUsers[j].name == this.profileName_) { | |
| 203 nameIsUnique = false; | |
| 204 allOnCurrentDevice = allOnCurrentDevice && | |
| 205 supervisedUsers[j].onCurrentDevice; | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 this.handleMessage_(allOnCurrentDevice ? | |
| 210 this.i18n('managedProfilesExistingLocalSupervisedUser') : | |
| 211 this.i18n('manageProfilesExistingSupervisedUser', | |
| 212 HTMLEscape(elide(this.profileName_, /* maxLength */ 50)))); | |
| 213 | |
| 214 this.createInProgress_ = false; | |
| 215 return; | |
| 216 } | |
| 217 // No existing supervised user's name matches the entered profile name. | |
| 218 // Continue with creating the new supervised profile. | |
| 219 this.createProfile_(); | |
| 220 }, | |
| 221 | |
| 222 /** | |
| 223 * Creates the new profile. | |
| 224 * @private | |
| 225 */ | |
| 226 createProfile_: function() { | |
| 227 var signedInUser = this.signedInUsers_[this.signedInUserIndex_]; | |
|
tommycli
2016/03/24 19:28:50
Same here. How do we prevent a -1 signedInUserInde
Moe
2016/03/24 22:07:56
Same here. We don't need to prevent it when the ne
tommycli
2016/03/24 22:18:54
Same comment as above, explicitly checking vs. the
Moe
2016/03/29 20:51:16
Done.
| |
| 228 var supervisorProfilePath = signedInUser ? signedInUser.profilePath : ''; | |
| 229 | |
| 230 this.browserProxy_.createProfile( | |
| 231 this.profileName_, this.profileIconUrl_, this.isSupervised_, | |
| 232 supervisorProfilePath); | |
| 233 }, | |
| 234 | |
| 235 /** | |
| 236 * Handler for the 'Cancel' button tap event. | |
| 185 * @param {!Event} event | 237 * @param {!Event} event |
| 186 * @private | 238 * @private |
| 187 */ | 239 */ |
| 188 onCancelTap_: function(event) { | 240 onCancelTap_: function(event) { |
| 189 if (this.createInProgress_) { | 241 if (this.createInProgress_) { |
| 190 this.createInProgress_ = false; | 242 this.createInProgress_ = false; |
| 191 this.browserProxy_.cancelCreateProfile(); | 243 this.browserProxy_.cancelCreateProfile(); |
| 192 } else { | 244 } else { |
| 193 this.fire('change-page', {page: 'user-pods-page'}); | 245 this.fire('change-page', {page: 'user-pods-page'}); |
| 194 } | 246 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 223 }, | 275 }, |
| 224 | 276 |
| 225 /** | 277 /** |
| 226 * Handles profile create/import warning/error message pushed by the browser. | 278 * Handles profile create/import warning/error message pushed by the browser. |
| 227 * @param {string} message An HTML warning/error message. | 279 * @param {string} message An HTML warning/error message. |
| 228 * @private | 280 * @private |
| 229 */ | 281 */ |
| 230 handleMessage_: function(message) { | 282 handleMessage_: function(message) { |
| 231 this.createInProgress_ = false; | 283 this.createInProgress_ = false; |
| 232 this.message_ = message; | 284 this.message_ = message; |
| 285 | |
| 286 // TODO(mahmadi): attach handler to '#supervised-user-import-existing' | |
| 287 // in order to import supervised user with the given name. | |
| 288 | |
| 289 // TODO(mahmadi): attach handler to '#reauth' in order to re-authenticate | |
| 290 // supervisor. | |
| 233 }, | 291 }, |
| 234 | 292 |
| 235 /** | 293 /** |
| 236 * Computed binding determining which profile icon button is toggled on. | 294 * Computed binding determining which profile icon button is toggled on. |
| 237 * @param {string} iconUrl icon URL of a given icon button. | 295 * @param {string} iconUrl icon URL of a given icon button. |
| 238 * @param {string} profileIconUrl Currently selected icon URL. | 296 * @param {string} profileIconUrl Currently selected icon URL. |
| 239 * @return {boolean} | 297 * @return {boolean} |
| 240 * @private | 298 * @private |
| 241 */ | 299 */ |
| 242 isActiveIcon_: function(iconUrl, profileIconUrl) { | 300 isActiveIcon_: function(iconUrl, profileIconUrl) { |
| 243 return iconUrl == profileIconUrl; | 301 return iconUrl == profileIconUrl; |
| 244 }, | 302 }, |
| 245 | 303 |
| 246 /** | 304 /** |
| 247 * Computed binding determining whether 'Ok' button is disabled. | 305 * Computed binding determining whether 'Save' button is disabled. |
| 248 * @param {boolean} createInProgress Is create in progress? | 306 * @param {boolean} createInProgress Is create in progress? |
| 249 * @param {string} profileName Profile Name. | 307 * @param {string} profileName Profile Name. |
| 250 * @param {string} message Existing warning/error message. | |
| 251 * @return {boolean} | 308 * @return {boolean} |
| 252 * @private | 309 * @private |
| 253 */ | 310 */ |
| 254 isOkDisabled_: function(createInProgress, profileName, message) { | 311 isSaveDisabled_: function(createInProgress, profileName) { |
|
tommycli
2016/03/24 19:28:50
How is this disabled if the selectedUserIndex = -1
Moe
2016/03/24 22:07:57
The button is not disabled in that case by design.
| |
| 255 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a | 312 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a |
| 256 // dependency and cast to PaperInputElement instead. | 313 // dependency and cast to PaperInputElement instead. |
| 257 /** @type {{validate: function():boolean}} */ | 314 /** @type {{validate: function():boolean}} */ |
| 258 var nameInput = this.$.nameInput; | 315 var nameInput = this.$.nameInput; |
| 259 return createInProgress || !profileName || message != '' || | 316 return createInProgress || !profileName || !nameInput.validate(); |
| 260 !nameInput.validate(); | |
| 261 }, | 317 }, |
| 262 | 318 |
| 263 /** | 319 /** |
| 264 * Computed binding determining whether supervised user checkbox is disabled. | 320 * Computed binding that returns True if there are any signed-in users. |
| 265 * @param {boolean} createInProgress Is create in progress? | 321 * @param {!Array<SignedInUser>} signedInUsers signed-in users. |
| 266 * @param {boolean} signedIn Are there any signed-in users? | |
| 267 * @return {boolean} | 322 * @return {boolean} |
| 268 * @private | 323 * @private |
| 269 */ | 324 */ |
| 270 isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) { | 325 isSignedIn_: function(signedInUsers) { |
| 271 return createInProgress || !signedIn; | 326 return signedInUsers.length > 0; |
| 272 } | 327 } |
| 273 }); | 328 }); |
| OLD | NEW |