Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview 'create-profile' is a page that contains controls for creating | |
| 7 * a (optionally supervised) profile, including choosing a name, and an avatar. | |
| 8 * | |
| 9 * @element create-profile | |
| 10 */ | |
| 11 Polymer({ | |
| 12 is: 'create-profile', | |
| 13 | |
| 14 properties: { | |
| 15 /** | |
| 16 * True if supervised user checkbox is disabled. | |
| 17 * @private {boolean} | |
| 18 */ | |
| 19 supervisedUserCheckboxDisabled_: { | |
| 20 type: Boolean, | |
| 21 computed: | |
| 22 'isSupervisedUserCheckboxDisabled_(createInProgress_, signedIn_)' | |
| 23 }, | |
| 24 | |
| 25 /** | |
| 26 * The current profile name. | |
| 27 * @private {string} | |
| 28 */ | |
| 29 profileName_: { | |
| 30 type: String, | |
| 31 value: '', | |
| 32 }, | |
| 33 | |
| 34 /** | |
| 35 * The list of available profile icon URLs. | |
| 36 * @private {!Array<string>} | |
| 37 */ | |
| 38 availableIconUrls_: { | |
| 39 type: Array, | |
| 40 value: function() { return []; } | |
| 41 }, | |
| 42 | |
| 43 /** | |
| 44 * The currently selected profile icon URL. May be a data URL. | |
| 45 * @private {string} | |
| 46 */ | |
| 47 profileIconUrl_: { | |
| 48 type: String, | |
| 49 value: '' | |
| 50 }, | |
| 51 | |
| 52 /** | |
| 53 * True if a profile is being created or imported. | |
| 54 * @private {boolean} | |
| 55 */ | |
| 56 createInProgress_: { | |
| 57 type: Boolean, | |
| 58 value: false | |
| 59 }, | |
| 60 | |
| 61 /** | |
| 62 * The current error/warning message. | |
| 63 * @private {string} | |
| 64 */ | |
| 65 message_: { | |
| 66 type: String, | |
| 67 value: '' | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * True if the new profile is a supervised profile. | |
| 72 * @private {boolean} | |
| 73 */ | |
| 74 isSupervised_: { | |
| 75 type: Boolean, | |
| 76 value: false | |
| 77 }, | |
| 78 | |
| 79 /** | |
| 80 * The list of usernames and profile paths for currently signed-in users. | |
| 81 * @private {!Array<SignedInUser>} | |
| 82 */ | |
| 83 signedInUsers_: { | |
| 84 type: Array, | |
| 85 value: function() { return []; } | |
| 86 }, | |
| 87 | |
| 88 /** | |
| 89 * Index of the selected signed-in user. | |
| 90 * @private {number} | |
| 91 */ | |
| 92 selectedEmail_: { | |
| 93 type: Number, | |
| 94 value: 0 | |
| 95 }, | |
| 96 }, | |
| 97 | |
| 98 /** @override */ | |
| 99 attached: function() { | |
| 100 signin.ProfileApi.setProfileCreateSuccessCallback( | |
| 101 this.handleSuccess_.bind(this)); | |
| 102 signin.ProfileApi.setProfileCreateWarningCallback( | |
| 103 this.handleMessage_.bind(this)); | |
| 104 signin.ProfileApi.setProfileCreateErrorCallback( | |
| 105 this.handleMessage_.bind(this)); | |
| 106 | |
| 107 this.parentNode.addEventListener('iron-select', | |
| 108 this.onPageSelect_.bind(this)); | |
| 109 }, | |
| 110 | |
| 111 /** @override */ | |
| 112 detached: function() { | |
|
Dan Beam
2016/03/04 02:45:49
do you expect detached to ever actually happen?
Moe
2016/03/08 00:57:04
It should now. I put create-profile under a dom-if
| |
| 113 signin.ProfileApi.setProfileCreateSuccessCallback(null); | |
| 114 signin.ProfileApi.setProfileCreateWarningCallback(null); | |
| 115 signin.ProfileApi.setProfileCreateErrorCallback(null); | |
| 116 }, | |
| 117 | |
| 118 /** | |
| 119 * Handler for 'iron-select' events. Resets the form and makes calls to | |
| 120 * ProfileApi every time the page becomes visible. | |
| 121 * @param {!Event} event | |
| 122 * @private | |
| 123 */ | |
| 124 onPageSelect_: function(event) { | |
| 125 if (event.target.selected == 'create-user-page') { | |
|
Dan Beam
2016/03/04 02:45:48
nit:
if (event.target.selected != 'create-user-pa
Moe
2016/03/08 00:57:04
Done.
| |
| 126 this.resetForm_(); | |
| 127 signin.ProfileApi.getAvailableIcons( | |
| 128 this.handleAvailableIcons_.bind(this)); | |
| 129 signin.ProfileApi.getSignedInUsers( | |
| 130 this.handleUpdateSignedInUsers_.bind(this)); | |
| 131 } | |
| 132 }, | |
| 133 | |
| 134 /** | |
| 135 * Resets the state of the page. | |
| 136 * @private | |
| 137 */ | |
| 138 resetForm_: function() { | |
| 139 this.profileName_ = ''; | |
| 140 this.availableIconUrls_ = []; | |
| 141 this.profileIconUrl_ = ''; | |
| 142 this.createInProgress_ = false; | |
| 143 this.message_ = ''; | |
| 144 this.isSupervised_ = false; | |
| 145 this.signedInUsers_ = []; | |
| 146 this.selectedEmail_ = 0; | |
| 147 }, | |
| 148 | |
| 149 /** | |
| 150 * Handler for when the available icons are pushed from ProfileApi. | |
| 151 * @param {!Array<string>} iconUrls | |
| 152 * @private | |
| 153 */ | |
| 154 handleAvailableIcons_: function(iconUrls) { | |
| 155 this.availableIconUrls_ = iconUrls; | |
| 156 this.profileIconUrl_ = iconUrls[0]; | |
| 157 }, | |
| 158 | |
| 159 /** | |
| 160 * Updates the signed-in users. | |
| 161 * @param {!Array<SignedInUser>} signedInUsers | |
| 162 * @private | |
| 163 */ | |
| 164 handleUpdateSignedInUsers_: function(signedInUsers) { | |
| 165 this.signedInUsers_ = signedInUsers; | |
| 166 this.signedIn_ = signedInUsers.length > 0; | |
| 167 }, | |
| 168 | |
| 169 /** | |
| 170 * Handler for the 'Learn More' button click event. | |
| 171 * @param {!Event} event | |
| 172 * @private | |
| 173 */ | |
| 174 onLearnMore_: function(event) { | |
| 175 // TODO(mahmadi): fire the event to show the 'learn-more-page' | |
| 176 }, | |
| 177 | |
| 178 /** | |
| 179 * Handler for the 'Ok' button click event. | |
| 180 * @param {!Event} event | |
| 181 * @private | |
| 182 */ | |
| 183 onOk_: function(event) { | |
| 184 this.createInProgress_ = true; | |
| 185 signin.ProfileApi.createProfile( | |
| 186 this.profileName_, this.profileIconUrl_, this.isSupervised_, | |
| 187 this.signedInUsers_[this.selectedEmail_].profilePath); | |
| 188 }, | |
| 189 | |
| 190 /** | |
| 191 * Handler for the 'Cancel' button click event. | |
| 192 * @param {!Event} event | |
| 193 * @private | |
| 194 */ | |
| 195 onCancel_: function(event) { | |
| 196 if (this.createInProgress_) { | |
| 197 this.createInProgress_ = false; | |
| 198 signin.ProfileApi.cancelCreateProfile(); | |
| 199 } else { | |
| 200 this.fire('change-page', {page: 'user-pods-page'}); | |
| 201 } | |
| 202 }, | |
| 203 | |
| 204 /** | |
| 205 * Handler for when the user clicks a new profile icon. | |
| 206 * @param {!Event} event | |
| 207 * @private | |
| 208 */ | |
| 209 onIconTap_: function(event) { | |
| 210 var element = Polymer.dom(event).rootTarget; | |
| 211 | |
| 212 if (element.nodeName == 'IMG') | |
| 213 this.profileIconUrl_ = element.src; | |
| 214 else if (element.dataset && element.dataset.iconUrl) | |
| 215 this.profileIconUrl_ = element.dataset.iconUrl; | |
| 216 | |
| 217 // Button toggle state is controlled by the selected icon URL. Prevent | |
| 218 // tap events from changing the toggle state. | |
| 219 event.preventDefault(); | |
| 220 }, | |
| 221 | |
| 222 /** | |
| 223 * Handles profile create/import success message pushed by ProfileApi. | |
| 224 * @param {!ProfileInfo} profileInfo Details of the created/imported profile. | |
| 225 * @private | |
| 226 */ | |
| 227 handleSuccess_: function(profileInfo) { | |
| 228 this.createInProgress_ = false; | |
| 229 this.fire('change-page', {page: 'user-pods-page'}); | |
| 230 }, | |
| 231 | |
| 232 /** | |
| 233 * Handles profile create/import warning/error message pushed by ProfileApi. | |
| 234 * @param {string} message An HTML warning/error message. | |
| 235 * @private | |
| 236 */ | |
| 237 handleMessage_: function(message) { | |
| 238 this.createInProgress_ = false; | |
| 239 this.message_ = message; | |
| 240 }, | |
| 241 | |
| 242 /** | |
| 243 * Computed binding determining which profile icon button is toggled on. | |
| 244 * @param {string} iconUrl icon URL of a given icon button | |
| 245 * @param {string} profileIconUrl Currently selected icon URL | |
| 246 * @return {boolean} | |
| 247 * @private | |
| 248 */ | |
| 249 isActiveIcon_: function(iconUrl, profileIconUrl) { | |
| 250 return iconUrl == profileIconUrl; | |
| 251 }, | |
| 252 | |
| 253 /** | |
| 254 * Computed binding determining whether 'Ok' button is disabled. | |
| 255 * @param {boolean} createInProgress Is create in progress? | |
| 256 * @param {string} profileName Profile Name | |
| 257 * @param {string} message Existing warning/error message | |
| 258 * @return {boolean} | |
| 259 * @private | |
| 260 */ | |
| 261 isOkDisabled_: function(createInProgress, profileName, message) { | |
| 262 /** @type {{validate:(function())}} */ | |
|
Dan Beam
2016/03/04 02:45:49
this should be a PaperInputElement
Moe
2016/03/08 00:57:04
Changing this to PaperInputElement and adding the
Dan Beam
2016/03/08 01:18:16
this is a problem with compiling Polymer. how abo
Dan Beam
2016/03/08 01:18:16
nit: /** @type {{validate: function():boolean}} */
Moe
2016/03/08 15:47:33
Done.
Moe
2016/03/08 15:47:34
Done.
| |
| 263 var nameInput = this.$.nameInput; | |
| 264 return createInProgress || !profileName || message != '' || | |
| 265 !nameInput.validate(); | |
| 266 }, | |
| 267 | |
| 268 /** | |
| 269 * Computed binding determining whether supervised user checkbox is disabled. | |
| 270 * @param {boolean} createInProgress Is create in progress? | |
| 271 * @param {boolean} signedIn Are there any signed-in users? | |
| 272 * @return {boolean} | |
| 273 * @private | |
| 274 */ | |
| 275 isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) { | |
| 276 return createInProgress || !signedIn; | |
| 277 } | |
| 278 }); | |
| OLD | NEW |