Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 login.createScreen('OAuthEnrollmentScreen', 'oauth-enrollment', function() { | 5 login.createScreen('OAuthEnrollmentScreen', 'oauth-enrollment', function() { |
| 6 /** @const */ var STEP_SIGNIN = 'signin'; | 6 /** @const */ var STEP_SIGNIN = 'signin'; |
| 7 /** @const */ var STEP_WORKING = 'working'; | 7 /** @const */ var STEP_WORKING = 'working'; |
| 8 /** @const */ var STEP_ATTRIBUTE_PROMPT = 'attribute-prompt'; | |
| 8 /** @const */ var STEP_ERROR = 'error'; | 9 /** @const */ var STEP_ERROR = 'error'; |
| 9 /** @const */ var STEP_SUCCESS = 'success'; | 10 /** @const */ var STEP_SUCCESS = 'success'; |
| 10 | 11 |
| 11 /** @const */ var HELP_TOPIC_ENROLLMENT = 4631259; | 12 /** @const */ var HELP_TOPIC_ENROLLMENT = 4631259; |
| 12 | 13 |
| 13 return { | 14 return { |
| 14 EXTERNAL_API: [ | 15 EXTERNAL_API: [ |
| 15 'showStep', | 16 'showStep', |
| 16 'showError', | 17 'showError', |
| 17 'doReload', | 18 'doReload', |
| 19 'showAttributePromptStep', | |
| 18 ], | 20 ], |
| 19 | 21 |
| 20 /** | 22 /** |
| 21 * Authenticator object that wraps GAIA webview. | 23 * Authenticator object that wraps GAIA webview. |
| 22 */ | 24 */ |
| 23 authenticator_: null, | 25 authenticator_: null, |
| 24 | 26 |
| 25 /** | 27 /** |
| 26 * The current step. This is the last value passed to showStep(). | 28 * The current step. This is the last value passed to showStep(). |
| 27 */ | 29 */ |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 } | 142 } |
| 141 | 143 |
| 142 makeButton( | 144 makeButton( |
| 143 'oauth-enroll-done-button', | 145 'oauth-enroll-done-button', |
| 144 ['oauth-enroll-focus-on-success'], | 146 ['oauth-enroll-focus-on-success'], |
| 145 loadTimeData.getString('oauthEnrollDone'), | 147 loadTimeData.getString('oauthEnrollDone'), |
| 146 function() { | 148 function() { |
| 147 chrome.send('oauthEnrollClose', ['done']); | 149 chrome.send('oauthEnrollClose', ['done']); |
| 148 }); | 150 }); |
| 149 | 151 |
| 152 makeButton( | |
| 153 'oauth-enroll-continue-button', | |
| 154 ['oauth-enroll-focus-on-attribute-prompt'], | |
| 155 loadTimeData.getString('oauthEnrollContinue'), | |
| 156 function() { | |
| 157 chrome.send('oauthEnrollAttributes', | |
| 158 [$('oauth-enroll-asset-id').value, | |
| 159 $('oauth-enroll-location').value]); | |
| 160 }); | |
| 161 | |
| 150 return buttons; | 162 return buttons; |
| 151 }, | 163 }, |
| 152 | 164 |
| 153 /** | 165 /** |
| 154 * Event handler that is invoked just before the frame is shown. | 166 * Event handler that is invoked just before the frame is shown. |
| 155 * @param {Object} data Screen init payload, contains the signin frame | 167 * @param {Object} data Screen init payload, contains the signin frame |
| 156 * URL. | 168 * URL. |
| 157 */ | 169 */ |
| 158 onBeforeShow: function(data) { | 170 onBeforeShow: function(data) { |
| 159 var gaiaParams = {}; | 171 var gaiaParams = {}; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 172 var modes = ['manual', 'forced', 'recovery']; | 184 var modes = ['manual', 'forced', 'recovery']; |
| 173 for (var i = 0; i < modes.length; ++i) { | 185 for (var i = 0; i < modes.length; ++i) { |
| 174 this.classList.toggle('mode-' + modes[i], | 186 this.classList.toggle('mode-' + modes[i], |
| 175 data.enrollment_mode == modes[i]); | 187 data.enrollment_mode == modes[i]); |
| 176 } | 188 } |
| 177 this.isCancelDisabled = true; | 189 this.isCancelDisabled = true; |
| 178 this.showStep(STEP_SIGNIN); | 190 this.showStep(STEP_SIGNIN); |
| 179 }, | 191 }, |
| 180 | 192 |
| 181 /** | 193 /** |
| 194 * Shows attribute-prompt step with pre-filled asset ID and | |
| 195 * location. | |
| 196 */ | |
| 197 showAttributePromptStep: function(annotated_asset_id, annotated_location) { | |
| 198 $('oauth-enroll-attribute-prompt-message').innerHTML = | |
| 199 loadTimeData.getString('oauthEnrollAttributes'); | |
| 200 | |
| 201 $('oauth-enroll-asset-id').value = annotated_asset_id; | |
| 202 $('oauth-enroll-location').value = annotated_location; | |
| 203 | |
| 204 this.showStep(STEP_ATTRIBUTE_PROMPT); | |
| 205 }, | |
| 206 | |
| 207 /** | |
| 182 * Cancels enrollment and drops the user back to the login screen. | 208 * Cancels enrollment and drops the user back to the login screen. |
| 183 */ | 209 */ |
| 184 cancel: function() { | 210 cancel: function() { |
| 185 if (this.isCancelDisabled) | 211 if (this.isCancelDisabled) |
| 186 return; | 212 return; |
| 187 this.isCancelDisabled = true; | 213 this.isCancelDisabled = true; |
| 188 chrome.send('oauthEnrollClose', ['cancel']); | 214 chrome.send('oauthEnrollClose', ['cancel']); |
| 189 }, | 215 }, |
| 190 | 216 |
| 191 /** | 217 /** |
| 218 * Returns whether |step| is the device attribute update error or | |
| 219 * not. | |
| 220 */ | |
| 221 isAttributeUpdateError: function(step) { | |
| 222 return this.currentStep_ == STEP_ATTRIBUTE_PROMPT && step == STEP_ERROR; | |
| 223 }, | |
| 224 | |
| 225 /** | |
| 226 * Shows cancel or done button. | |
| 227 */ | |
| 228 hideCancelShowDone: function(hide) { | |
| 229 $('oauth-enroll-cancel-button').hidden = hide; | |
| 230 $('oauth-enroll-cancel-button').disabled = hide; | |
| 231 | |
| 232 $('oauth-enroll-done-button').hidden = !hide; | |
| 233 $('oauth-enroll-done-button').disabled = !hide; | |
| 234 }, | |
| 235 | |
| 236 /** | |
| 192 * Switches between the different steps in the enrollment flow. | 237 * Switches between the different steps in the enrollment flow. |
| 193 * @param {string} step the steps to show, one of "signin", "working", | 238 * @param {string} step the steps to show, one of "signin", "working", |
| 194 * "error", "success". | 239 * "attribute-prompt", "error", "success". |
| 195 */ | 240 */ |
| 196 showStep: function(step) { | 241 showStep: function(step) { |
| 242 var focusSTep = step; | |
|
dzhioev (left Google)
2015/04/14 15:48:19
Misprint, should be 'focusStep'.
Anyway, is this v
Polina Bondarenko
2015/04/14 16:14:32
Thanks, it is also a bug. It should be used instea
| |
| 243 | |
| 197 this.classList.toggle('oauth-enroll-state-' + this.currentStep_, false); | 244 this.classList.toggle('oauth-enroll-state-' + this.currentStep_, false); |
| 198 this.classList.toggle('oauth-enroll-state-' + step, true); | 245 this.classList.toggle('oauth-enroll-state-' + step, true); |
| 246 | |
| 247 /** | |
| 248 * In case of device attribute update error done button should be shown | |
| 249 * instead of cancel button and focus on success, | |
| 250 * because enrollment has completed | |
| 251 */ | |
| 252 if (this.isAttributeUpdateError(step)) { | |
| 253 focusStep = STEP_SUCCESS; | |
| 254 this.hideCancelShowDone(true); | |
| 255 } else { | |
| 256 if (step == STEP_ERROR) | |
| 257 this.hideCancelShowDone(false); | |
| 258 } | |
| 259 | |
| 199 var focusElements = | 260 var focusElements = |
| 200 this.querySelectorAll('.oauth-enroll-focus-on-' + step); | 261 this.querySelectorAll('.oauth-enroll-focus-on-' + step); |
| 201 for (var i = 0; i < focusElements.length; ++i) { | 262 for (var i = 0; i < focusElements.length; ++i) { |
| 202 if (getComputedStyle(focusElements[i])['display'] != 'none') { | 263 if (getComputedStyle(focusElements[i])['display'] != 'none') { |
| 203 focusElements[i].focus(); | 264 focusElements[i].focus(); |
| 204 break; | 265 break; |
| 205 } | 266 } |
| 206 } | 267 } |
| 207 this.currentStep_ = step; | 268 this.currentStep_ = step; |
| 208 }, | 269 }, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 226 * Retries the enrollment process after an error occurred in a previous | 287 * Retries the enrollment process after an error occurred in a previous |
| 227 * attempt. This goes to the C++ side through |chrome| first to clean up the | 288 * attempt. This goes to the C++ side through |chrome| first to clean up the |
| 228 * profile, so that the next attempt is performed with a clean state. | 289 * profile, so that the next attempt is performed with a clean state. |
| 229 */ | 290 */ |
| 230 doRetry_: function() { | 291 doRetry_: function() { |
| 231 chrome.send('oauthEnrollRetry'); | 292 chrome.send('oauthEnrollRetry'); |
| 232 } | 293 } |
| 233 }; | 294 }; |
| 234 }); | 295 }); |
| 235 | 296 |
| OLD | NEW |