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 /** | |
| 7 * @fileoverview | |
| 8 * 'create-profile' is a page that contains controls for creating a (optionally | |
| 9 * supervised) profile, including choosing a name, and an avatar. | |
| 10 * | |
| 11 * @element create-profile | |
| 12 */ | |
| 13 Polymer({ | |
| 14 is: 'create-profile', | |
| 15 | |
| 16 properties: { | |
| 17 /** | |
| 18 * Indicates whether the supervised user checkbox should be disabled. | |
|
tommycli
2016/02/08 18:45:19
True if the supervised user checkbox is disabled.
Moe
2016/02/09 00:15:33
Done.
| |
| 19 * @private {boolean} | |
| 20 */ | |
| 21 supervisedUserCheckboxDisabled_: { | |
| 22 type: Boolean, | |
| 23 computed: | |
| 24 'isSupervisedUserCheckboxDisabled_(createInProgress_, signedIn_)' | |
| 25 }, | |
| 26 | |
| 27 /** | |
| 28 * The error/warning message related to creating/importing a profile. | |
| 29 * @private {string} | |
| 30 */ | |
| 31 errorMessage_: { | |
| 32 type: String, | |
| 33 value: '', | |
| 34 observer: 'errorMessageChanged_' | |
| 35 } | |
| 36 }, | |
| 37 | |
| 38 /** @override */ | |
| 39 attached: function() { | |
| 40 signin.ProfileApi.setProfileCreateSuccessCallback( | |
| 41 this.handleSuccess_.bind(this)); | |
| 42 signin.ProfileApi.setProfileCreateWarningCallback( | |
| 43 this.handleWarning_.bind(this)); | |
| 44 signin.ProfileApi.setProfileCreateErrorCallback( | |
| 45 this.handleError_.bind(this)); | |
| 46 | |
| 47 this.parentNode.addEventListener('iron-select', | |
| 48 this.onPageSelect_.bind(this)); | |
| 49 }, | |
| 50 | |
| 51 /** @override */ | |
| 52 detached: function() { | |
| 53 signin.ProfileApi.setProfileCreateSuccessCallback(null); | |
| 54 signin.ProfileApi.setProfileCreateWarningCallback(null); | |
| 55 signin.ProfileApi.setProfileCreateErrorCallback(null); | |
| 56 }, | |
| 57 | |
| 58 /** | |
| 59 * Handler for |iron-select| events. Resets the form and makes calls to | |
| 60 * ProfileApi every time the page becomes visible. | |
| 61 * @param {!Event} event | |
| 62 * @private | |
| 63 */ | |
| 64 onPageSelect_: function(event) { | |
| 65 if (event.target.selected == 'create-user-page') { | |
| 66 this.resetForm_(); | |
| 67 signin.ProfileApi.getAvailableIcons( | |
| 68 this.handleAvailableIcons_.bind(this)); | |
| 69 signin.ProfileApi.getSignedInUsers( | |
| 70 this.handleUpdateSignedInUsers_.bind(this)); | |
| 71 } | |
| 72 }, | |
| 73 | |
| 74 /** | |
| 75 * Resets the state of the page. | |
| 76 * @private | |
| 77 */ | |
| 78 resetForm_: function() { | |
| 79 /** | |
| 80 * The current profile name. | |
| 81 * @type {!string} | |
| 82 */ | |
| 83 this.profileName = ''; | |
| 84 /** | |
| 85 * The list of available profile icon URLs. | |
| 86 * @type {!Array<string>} | |
| 87 */ | |
| 88 this.availableIconUrls = []; | |
|
tommycli
2016/02/08 18:45:19
Hi, this needs to be a property if it's going to b
Moe
2016/02/09 00:15:33
Done.
| |
| 89 /** | |
| 90 * The currently selected profile icon URL. May be a data URL. | |
| 91 * @type {!string} | |
| 92 */ | |
| 93 this.profileIconUrl = ''; | |
| 94 /** | |
| 95 * Whether a profile is being created or imported. | |
| 96 * @type {boolean} | |
| 97 */ | |
| 98 this.createInProgress_ = false; | |
| 99 /** | |
| 100 * The current error/warning message. | |
| 101 * @type {!string} | |
| 102 */ | |
| 103 this.errorMessage_ = ''; | |
| 104 /** | |
| 105 * Whether the new profile is a supervised profile. | |
| 106 * @type {!boolean} | |
| 107 */ | |
| 108 this.isSupervised_ = false; | |
| 109 }, | |
| 110 | |
| 111 /** | |
| 112 * Handler for when the available icons are pushed from ProfileApi. | |
| 113 * @param {!Array<string>} iconUrls | |
| 114 * @private | |
| 115 */ | |
| 116 handleAvailableIcons_: function(iconUrls) { | |
| 117 this.availableIconUrls = iconUrls; | |
| 118 this.profileIconUrl = iconUrls[0]; | |
| 119 }, | |
| 120 | |
| 121 /** | |
| 122 * Updates the signed-in email addresses. | |
| 123 * @private | |
| 124 */ | |
| 125 handleUpdateSignedInUsers_: function(signedInUsers) { | |
| 126 this.signedInUsers_ = signedInUsers; | |
| 127 this.selectedEmail_ = 0; | |
| 128 this.signedIn_ = signedInUsers.length > 0; | |
| 129 }, | |
| 130 | |
| 131 /** | |
| 132 * Handler for the |Learn More| button click event. | |
| 133 * @param {!Event} event | |
| 134 * @private | |
| 135 */ | |
| 136 onLearnMore_: function(event) { | |
| 137 this.fire('change-page', {page: 'supervised-learn-more-page'}); | |
| 138 }, | |
| 139 | |
| 140 /** | |
| 141 * Handler for the |Ok| button click event. | |
| 142 * @param {!Event} event | |
| 143 * @private | |
| 144 */ | |
| 145 onOk_: function(event) { | |
| 146 this.createInProgress_ = true; | |
| 147 chrome.send('createProfile', | |
| 148 [this.profileName, this.profileIconUrl, false, | |
| 149 this.isSupervised_, '', | |
| 150 this.signedInUsers_[this.selectedEmail_].profilePath]); | |
| 151 }, | |
| 152 | |
| 153 /** | |
| 154 * Handler for the |Cancel| button click event. | |
| 155 * @param {!Event} event | |
| 156 * @private | |
| 157 */ | |
| 158 onCancel_: function(event) { | |
| 159 if (this.createInProgress_) { | |
| 160 this.createInProgress_ = false; | |
| 161 chrome.send('cancelCreateProfile'); | |
| 162 } else { | |
| 163 this.fire('change-page', {page: 'user-pods-page'}); | |
| 164 } | |
| 165 }, | |
| 166 | |
| 167 /** | |
| 168 * Handler for when the user clicks a new profile icon. | |
| 169 * @param {!Event} event | |
| 170 * @private | |
| 171 */ | |
| 172 onIconTap_: function(event) { | |
| 173 var element = Polymer.dom(event).rootTarget; | |
| 174 | |
| 175 if (element.nodeName == 'IMG') | |
| 176 this.profileIconUrl = element.src; | |
| 177 else if (element.dataset && element.dataset.iconUrl) | |
| 178 this.profileIconUrl = element.dataset.iconUrl; | |
| 179 | |
| 180 // Button toggle state is controlled by the selected icon URL. Prevent | |
| 181 // tap events from changing the toggle state. | |
| 182 event.preventDefault(); | |
| 183 }, | |
| 184 | |
| 185 /** | |
| 186 * Handles profile create/import success message pushed by ProfileApi. | |
| 187 * @param {!profileInfo} profileInfo Details of the created/imported profile. | |
| 188 * @private | |
| 189 */ | |
| 190 handleSuccess_: function(profileInfo) { | |
| 191 this.createInProgress_ = false; | |
| 192 this.fire('change-page', {page: 'user-pods-page'}); | |
| 193 }, | |
| 194 | |
| 195 /** | |
| 196 * Handles profile create/import warning message pushed by ProfileApi. | |
| 197 * @param {!string} warningHTML | |
| 198 * @private | |
| 199 */ | |
| 200 handleWarning_: function(warningHTML) { | |
|
tommycli
2016/02/08 18:45:19
Since this is the same as Error (just displays htm
Moe
2016/02/09 00:15:33
Done.
| |
| 201 this.createInProgress_ = false; | |
| 202 this.errorMessage_ = warningHTML; | |
| 203 }, | |
| 204 | |
| 205 /** | |
| 206 * Handles profile create/import error message pushed by ProfileApi. | |
| 207 * @param {!string} errorHTML | |
| 208 * @private | |
| 209 */ | |
| 210 handleError_: function(errorHTML) { | |
| 211 this.createInProgress_ = false; | |
| 212 this.errorMessage_ = errorHTML; | |
| 213 }, | |
| 214 | |
| 215 /** | |
| 216 * Observer for |errorMessage_|. Updates the content of |messageBubble|. | |
| 217 * @param {!string} newValue New value of the |errorMessage_| | |
|
tommycli
2016/02/08 18:45:19
string is primitive and thus implied to be non-nul
Moe
2016/02/09 00:15:33
Done.
| |
| 218 * @private | |
| 219 */ | |
| 220 errorMessageChanged_: function(newValue) { | |
|
tommycli
2016/02/08 18:45:19
Can we accomplish this goal without this observer?
Moe
2016/02/09 00:15:33
newValue can be HTML. I came across the above link
| |
| 221 this.$.messageBubble.innerHTML = newValue; | |
| 222 }, | |
| 223 | |
| 224 /** | |
| 225 * Computed binding determining which profile icon button is toggled on. | |
| 226 * @param {!string} iconUrl icon URL of a given icon button | |
| 227 * @param {!string} profileIconUrl Currently selected icon URL | |
| 228 * @private | |
| 229 * @return {boolean} | |
|
tommycli
2016/02/08 18:45:19
I think i've usually seen @return above @private.
Moe
2016/02/09 00:15:33
Done.
| |
| 230 */ | |
| 231 isActiveIcon_: function(iconUrl, profileIconUrl) { | |
| 232 return iconUrl == profileIconUrl; | |
| 233 }, | |
| 234 | |
| 235 /** | |
| 236 * Computed binding determining whether |Ok| button is disabled. | |
| 237 * @param {boolean} createInProgress Is create in progress? | |
| 238 * @param {!string} profileName Profile Name | |
| 239 * @param {!string} errorMessage Existing error message | |
| 240 * @private | |
| 241 * @return {boolean} | |
| 242 */ | |
| 243 isOkDisabled_: function(createInProgress, profileName, errorMessage) { | |
| 244 /** @type {{validate:(function())}} */ | |
| 245 var nameInput = this.$.nameInput; | |
| 246 return createInProgress || profileName == '' || nameInput.validate() || | |
| 247 errorMessage != ''; | |
| 248 }, | |
| 249 | |
| 250 /** | |
| 251 * Computed binding determining whether supervised user checkbox is disabled. | |
| 252 * @param {boolean} createInProgress Is create in progress? | |
| 253 * @param {boolean} signedIn Are there any signed in users? | |
| 254 * @private | |
| 255 * @return {boolean} | |
| 256 */ | |
| 257 isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) { | |
| 258 return createInProgress || !signedIn; | |
| 259 } | |
| 260 }); | |
| OLD | NEW |