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